diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 538ccdc107..56a082260c 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -237,6 +237,11 @@ func (o *Operator) Start(ctx context.Context, cp cloudprovider.CloudProvider) { ctx = injection.WithClient(ctx, o.GetClient()) webhooks.Start(ctx, o.GetConfig(), o.webhooks...) }() + wg.Add(1) + go func() { + defer wg.Done() + webhooks.ValidateConversionEnabled(ctx, o.GetClient()) + }() } wg.Wait() } diff --git a/pkg/webhooks/webhooks.go b/pkg/webhooks/webhooks.go index e689617abf..85b7350191 100644 --- a/pkg/webhooks/webhooks.go +++ b/pkg/webhooks/webhooks.go @@ -23,6 +23,7 @@ import ( "io" "net/http" "strings" + "time" "github.com/samber/lo" "go.uber.org/zap" @@ -41,6 +42,7 @@ import ( "knative.dev/pkg/webhook/resourcesemantics" "knative.dev/pkg/webhook/resourcesemantics/conversion" "knative.dev/pkg/webhook/resourcesemantics/validation" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/healthz" v1 "sigs.k8s.io/karpenter/pkg/apis/v1" @@ -206,3 +208,22 @@ func HealthProbe(ctx context.Context) healthz.Checker { return nil } } + +func ValidateConversionEnabled(ctx context.Context, kubeclient client.Client) { + // allow context to exist longer than cache sync timeout which has a default of 120 seconds + listCtx, cancel := context.WithTimeout(ctx, 130*time.Second) + defer cancel() + var err error + v1np := &v1.NodePoolList{} + for { + err = kubeclient.List(listCtx, v1np, &client.ListOptions{Limit: 1}) + if err == nil { + return + } + select { + case <-listCtx.Done(): + panic("Conversion webhook enabled but unable to complete call: " + err.Error()) + case <-time.After(10 * time.Second): + } + } +}