From 34cc94900ad44b5cadb05d5d428e79353ab32db2 Mon Sep 17 00:00:00 2001 From: Dmitriy Kalinin Date: Tue, 12 Jan 2021 16:04:49 -0500 Subject: [PATCH] add --api-request-timeout flag for controller http timeout for k8s api requests commit 81bce8625d1d68062bf07b87381b5748262512b4 Merge: f8d8a03 cb3c46c Author: Dmitriy Kalinin Date: Tue Jan 12 16:00:22 2021 -0500 Merge branch 'http-timeout' of https://github.com/achimweigel/carvel-kapp-controller into achimweigel-http-timeout commit cb3c46cf72f9c5633f6724fbfb582fa0ffa1c47a Author: Achim Weigel Date: Fri Dec 18 13:54:21 2020 +0100 configurable timeout for http --- cmd/controller/run.go | 12 +++++++++--- cmd/main.go | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/controller/run.go b/cmd/controller/run.go index 03056dcea..f1c2d36d7 100644 --- a/cmd/controller/run.go +++ b/cmd/controller/run.go @@ -8,6 +8,7 @@ import ( "net/http" // Pprof related _ "net/http/pprof" // Pprof related "os" + "time" "github.com/go-logr/logr" kcv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1" @@ -27,9 +28,10 @@ const ( ) type Options struct { - Concurrency int - Namespace string - EnablePprof bool + Concurrency int + Namespace string + EnablePprof bool + APIRequestTimeout time.Duration } // Based on https://github.com/kubernetes-sigs/controller-runtime/blob/8f633b179e1c704a6e40440b528252f147a3362a/examples/builtins/main.go @@ -39,6 +41,10 @@ func Run(opts Options, runLog logr.Logger) { restConfig := config.GetConfigOrDie() + if opts.APIRequestTimeout != 0 { + restConfig.Timeout = opts.APIRequestTimeout + } + mgr, err := manager.New(restConfig, manager.Options{Namespace: opts.Namespace}) if err != nil { runLog.Error(err, "unable to set up overall controller manager") diff --git a/cmd/main.go b/cmd/main.go index 1c0ad25c5..cea6ae02d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,6 +6,7 @@ package main import ( "flag" "os" + "time" "github.com/vmware-tanzu/carvel-kapp-controller/cmd/controller" "github.com/vmware-tanzu/carvel-kapp-controller/cmd/controllerinit" @@ -25,6 +26,7 @@ func main() { flag.IntVar(&ctrlOpts.Concurrency, "concurrency", 10, "Max concurrent reconciles") flag.StringVar(&ctrlOpts.Namespace, "namespace", "", "Namespace to watch") flag.BoolVar(&ctrlOpts.EnablePprof, "dangerous-enable-pprof", false, "If set to true, enable pprof on "+controller.PprofListenAddr) + flag.DurationVar(&ctrlOpts.APIRequestTimeout, "api-request-timeout", time.Duration(0), "HTTP timeout for Kubernetes API requests") flag.BoolVar(&runController, controllerinit.InternalControllerFlag, false, "[Internal] run the controller code") flag.Parse()