From e559d36d9f8374136916d45b72d7a3d0913ea840 Mon Sep 17 00:00:00 2001 From: Luiz Carvalho Date: Tue, 19 Mar 2024 12:14:34 -0400 Subject: [PATCH] Expose performance options This allow admins to specify a few parameters to better suit their use of Chains. `--threads-per-controller` controls the number of concurrent threads the Chains controller processes. The default value is 2. `--kube-api-burst` controle the maximum burst for throttle. `--kube-api-qps` controles the maximum QPS to the server from the client. The approach taken here is the same one used by the Tekton Pipeline controller for the sake of consistency in the ecosystem. Signed-off-by: Luiz Carvalho --- cmd/controller/main.go | 21 ++++++++++++++++++--- docs/performance.md | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 docs/performance.md diff --git a/cmd/controller/main.go b/cmd/controller/main.go index d8541a617f..8d99aa482b 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -18,6 +18,10 @@ import ( "github.com/tektoncd/chains/pkg/reconciler/pipelinerun" "github.com/tektoncd/chains/pkg/reconciler/taskrun" + + "k8s.io/client-go/rest" + + "knative.dev/pkg/controller" "knative.dev/pkg/injection" "knative.dev/pkg/injection/sharedmain" "knative.dev/pkg/signals" @@ -35,11 +39,22 @@ import ( _ "github.com/sigstore/sigstore/pkg/signature/kms/hashivault" ) -var namespace = flag.String("namespace", "", "Namespace to restrict informer to. Optional, defaults to all namespaces.") - func main() { + flag.IntVar(&controller.DefaultThreadsPerController, "threads-per-controller", controller.DefaultThreadsPerController, "Threads (goroutines) to create per controller") + namespace := flag.String("namespace", "", "Namespace to restrict informer to. Optional, defaults to all namespaces.") + + // This also calls flag.Parse(). + cfg := injection.ParseAndGetRESTConfigOrDie() + + if cfg.QPS == 0 { + cfg.QPS = 2 * rest.DefaultQPS + } + if cfg.Burst == 0 { + cfg.Burst = rest.DefaultBurst + } + flag.Parse() ctx := injection.WithNamespaceScope(signals.NewContext(), *namespace) - sharedmain.MainWithContext(ctx, "watcher", taskrun.NewController, pipelinerun.NewController) + sharedmain.MainWithConfig(ctx, "watcher", cfg, taskrun.NewController, pipelinerun.NewController) } diff --git a/docs/performance.md b/docs/performance.md new file mode 100644 index 0000000000..0043a96520 --- /dev/null +++ b/docs/performance.md @@ -0,0 +1,27 @@ +# Performance + +Tekton Chains exposes a few parameters that can be used to fine tune the controllers execution to +improve its performance as needed. + +The controller accepts the following parameters: + +`--threads-per-controller` controls the number of concurrent threads the Chains controller +processes. The default value is 2. + +`--kube-api-burst` controle the maximum burst for throttle. The default value is 10. + +`--kube-api-qps` controles the maximum QPS to the server from the client. The default value is 5. + +Modify the `Deployment` to use those parameters, for example: + +```yaml +spec: + template: + spec: + containers: + - image: gcr.io/tekton-releases/github.com/tektoncd/chains/cmd/controller:v0.20.0 + args: + - --threads-per-controller=32 + - --kube-api-burst=2 + - --kube-api-qps=3 +```