From acad4285d92656b6eedad15bbc67de1757391823 Mon Sep 17 00:00:00 2001 From: Chuck Quinn IV Date: Mon, 26 Feb 2024 13:26:11 -0600 Subject: [PATCH] Add WEBHOOK_PORT environment variable Signed-off-by: Chuck Quinn IV --- cmd/webhook/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index e4c3a9a99..140f3ea04 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -3,6 +3,8 @@ package main import ( "context" "log" + "os" + "strconv" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" @@ -26,6 +28,8 @@ import ( "github.com/pivotal/kpack/pkg/apis/build/v1alpha2" ) +const defaultWebhookPort = 8443 + var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{ v1alpha2.SchemeGroupVersion.WithKind(v1alpha2.ImageKind): &v1alpha2.Image{}, v1alpha2.SchemeGroupVersion.WithKind(v1alpha2.BuildKind): &v1alpha2.Build{}, @@ -42,9 +46,14 @@ func init() { } func main() { + webhookPort := defaultWebhookPort + webhookPortEnv := os.Getenv("WEBHOOK_PORT") + if parsedWebhookPort, err := strconv.Atoi(webhookPortEnv); err == nil { + webhookPort = parsedWebhookPort + } ctx := webhook.WithOptions(signals.NewContext(), webhook.Options{ ServiceName: "kpack-webhook", - Port: 8443, + Port: webhookPort, SecretName: "webhook-certs", })