Skip to content

Commit

Permalink
feat: add option to disable health probes via env
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
chmouel committed Dec 12, 2024
1 parent 3e53ba2 commit f7c282b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/pipelines-as-code-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ 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"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
"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"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmd/pipelines-as-code-watcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/pipelines-as-code-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"os"
"strings"

validationWebhook "github.com/openshift-pipelines/pipelines-as-code/pkg/webhook"
"knative.dev/pkg/configmap"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f7c282b

Please sign in to comment.