From d79a2784cac2d8700f0609a70ef71c6597104692 Mon Sep 17 00:00:00 2001 From: Nick Pillitteri Date: Fri, 13 Dec 2024 11:09:55 -0500 Subject: [PATCH 1/2] Make Kubernetes client timeout configurable Make the timeout added in #186 configurable and default to 5 minutes. Signed-off-by: Nick Pillitteri --- CHANGELOG.md | 2 ++ cmd/rollout-operator/main.go | 11 +++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7677353..a9d767c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## main / unreleased +* [ENHANCEMENT] Make timeout for requests to Pods and to the Kubernetes control plane configurable. #TBD + ## v0.22.0 * [ENHANCEMENT] New parameter log.format allows to set logging format to logfmt (default) or json (new). #184 diff --git a/cmd/rollout-operator/main.go b/cmd/rollout-operator/main.go index 8b3a8e39..255b05a4 100644 --- a/cmd/rollout-operator/main.go +++ b/cmd/rollout-operator/main.go @@ -46,6 +46,7 @@ type config struct { kubeAPIURL string kubeConfigFile string kubeNamespace string + kubeClientTimeout time.Duration reconcileInterval time.Duration serverTLSEnabled bool @@ -71,6 +72,7 @@ func (cfg *config) register(fs *flag.FlagSet) { fs.IntVar(&cfg.serverPort, "server.port", 8001, "Port to use for exposing instrumentation and readiness probe endpoints.") fs.StringVar(&cfg.kubeAPIURL, "kubernetes.api-url", "", "The Kubernetes server API URL. If not specified, it will be auto-detected when running within a Kubernetes cluster.") fs.StringVar(&cfg.kubeConfigFile, "kubernetes.config-file", "", "The Kubernetes config file path. If not specified, it will be auto-detected when running within a Kubernetes cluster.") + fs.DurationVar(&cfg.kubeClientTimeout, "kubernetes.client-timeout", 5*time.Minute, "Timeout for requests made to the Kubernetes API") fs.StringVar(&cfg.kubeNamespace, "kubernetes.namespace", "", "The Kubernetes namespace for which this operator is running.") fs.DurationVar(&cfg.reconcileInterval, "reconcile.interval", 5*time.Second, "The minimum interval of reconciliation.") @@ -142,7 +144,7 @@ func main() { check(srv.Start()) // Build the Kubernetes client config. - kubeConfig, err := buildKubeConfig(cfg.kubeAPIURL, cfg.kubeConfigFile) + kubeConfig, err := buildKubeConfig(cfg.kubeAPIURL, cfg.kubeConfigFile, cfg.kubeClientTimeout) check(errors.Wrap(err, "failed to build Kubernetes client config")) instrumentation.InstrumentKubernetesAPIClient(kubeConfig, reg) @@ -270,16 +272,13 @@ func checkAndWatchCertificate(cert tlscert.Certificate, logger log.Logger, resta } -func buildKubeConfig(apiURL, cfgFile string) (*rest.Config, error) { +func buildKubeConfig(apiURL, cfgFile string, timeout time.Duration) (*rest.Config, error) { if cfgFile != "" { config, err := clientcmd.BuildConfigFromFlags(apiURL, cfgFile) if err != nil { return nil, err } - // Set a generous timeout. - // We use this client for various HTTP operations against the k8s API and against the StatefulSets. - // We want to not be stuck waiting forever on a TCP timeout, but also not interrupt any process the StatefulSets might eb doing. - config.Timeout = 5 * time.Minute + config.Timeout = timeout return config, nil } From 66df9a66d98343ac5a3c3953bd659a70d20ea638 Mon Sep 17 00:00:00 2001 From: Nick Pillitteri Date: Fri, 13 Dec 2024 11:11:10 -0500 Subject: [PATCH 2/2] Changelog Signed-off-by: Nick Pillitteri --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9d767c8..a23b7400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## main / unreleased -* [ENHANCEMENT] Make timeout for requests to Pods and to the Kubernetes control plane configurable. #TBD +* [ENHANCEMENT] Make timeout for requests to Pods and to the Kubernetes control plane configurable. #188 ## v0.22.0