Skip to content

Commit

Permalink
add --api-request-timeout flag for controller http timeout for k8s ap…
Browse files Browse the repository at this point in the history
…i requests

commit 81bce8625d1d68062bf07b87381b5748262512b4
Merge: f8d8a03 cb3c46c
Author: Dmitriy Kalinin <[email protected]>
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 cb3c46c
Author: Achim Weigel <[email protected]>
Date:   Fri Dec 18 13:54:21 2020 +0100

    configurable timeout for http
  • Loading branch information
Dmitriy Kalinin committed Jan 12, 2021
1 parent f8d8a03 commit 34cc949
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/controller/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand Down

0 comments on commit 34cc949

Please sign in to comment.