Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Kubernetes client timeout configurable #188

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## main / unreleased

* [ENHANCEMENT] Make timeout for requests to Pods and to the Kubernetes control plane configurable. #188

## v0.22.0

* [ENHANCEMENT] New parameter log.format allows to set logging format to logfmt (default) or json (new). #184
Expand Down
11 changes: 5 additions & 6 deletions cmd/rollout-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type config struct {
kubeAPIURL string
kubeConfigFile string
kubeNamespace string
kubeClientTimeout time.Duration
reconcileInterval time.Duration

serverTLSEnabled bool
Expand All @@ -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.")

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}

Expand Down
Loading