From e983e12e8b53452f3dc7a0fd0f6f75540e196e06 Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Wed, 11 Dec 2024 16:23:33 +0100 Subject: [PATCH] feat: add option to disable health probes via env Added functionality to disable health probes in the controller, watcher, and webhook components by setting the environment variable PAC_DISABLE_HEALTH_PROBE to "true". This allows for more flexible configuration in environments where health probes are not needed (debugging on local machine, etc.). Signed-off-by: Chmouel Boudjnah --- cmd/pipelines-as-code-controller/main.go | 9 +++++++++ cmd/pipelines-as-code-watcher/main.go | 5 +++++ cmd/pipelines-as-code-webhook/main.go | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/cmd/pipelines-as-code-controller/main.go b/cmd/pipelines-as-code-controller/main.go index 9c9149731..0f9337a94 100644 --- a/cmd/pipelines-as-code-controller/main.go +++ b/cmd/pipelines-as-code-controller/main.go @@ -3,6 +3,8 @@ package main import ( "context" "log" + "os" + "strings" "github.com/openshift-pipelines/pipelines-as-code/pkg/adapter" "github.com/openshift-pipelines/pipelines-as-code/pkg/kubeinteraction" @@ -10,6 +12,7 @@ import ( "github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" evadapter "knative.dev/eventing/pkg/adapter/v2" "knative.dev/pkg/client/injection/kube/client" + "knative.dev/pkg/injection/sharedmain" "knative.dev/pkg/logging" "knative.dev/pkg/signals" "knative.dev/pkg/system" @@ -42,6 +45,12 @@ func main() { ctx = info.StoreNS(ctx, system.Namespace()) ctx = info.StoreCurrentControllerName(ctx, run.Info.Controller.Name) + if val, ok := os.LookupEnv("PAC_DISABLE_HEALTH_PROBE"); ok { + if strings.ToLower(val) == "true" { + ctx = sharedmain.WithHealthProbesDisabled(ctx) + } + } + ctx = context.WithValue(ctx, client.Key{}, run.Clients.Kube) ctx = evadapter.WithNamespace(ctx, system.Namespace()) ctx = evadapter.WithConfigWatcherEnabled(ctx) diff --git a/cmd/pipelines-as-code-watcher/main.go b/cmd/pipelines-as-code-watcher/main.go index 5bf10110b..ce5305c4a 100644 --- a/cmd/pipelines-as-code-watcher/main.go +++ b/cmd/pipelines-as-code-watcher/main.go @@ -65,6 +65,11 @@ func main() { if val, ok := os.LookupEnv("PAC_DISABLE_HA"); ok { if strings.ToLower(val) == "true" { ctx = sharedmain.WithHADisabled(ctx) + } + } + + if val, ok := os.LookupEnv("PAC_DISABLE_HEALTH_PROBE"); ok { + if strings.ToLower(val) == "true" { ctx = sharedmain.WithHealthProbesDisabled(ctx) } } diff --git a/cmd/pipelines-as-code-webhook/main.go b/cmd/pipelines-as-code-webhook/main.go index 6867f9798..dce5aef4b 100644 --- a/cmd/pipelines-as-code-webhook/main.go +++ b/cmd/pipelines-as-code-webhook/main.go @@ -3,6 +3,7 @@ package main import ( "context" "os" + "strings" validationWebhook "github.com/openshift-pipelines/pipelines-as-code/pkg/webhook" "knative.dev/pkg/configmap" @@ -32,6 +33,12 @@ func main() { SecretName: secretName, }) + if val, ok := os.LookupEnv("PAC_DISABLE_HEALTH_PROBE"); ok { + if strings.ToLower(val) == "true" { + ctx = sharedmain.WithHealthProbesDisabled(ctx) + } + } + sharedmain.WebhookMainWithConfig(ctx, "pipelines-as-code-webhook", injection.ParseAndGetRESTConfigOrDie(), certificates.NewController,