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()