Skip to content

Commit

Permalink
fix: handle webhook inability to connect error v34 (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschalo committed Sep 5, 2024
1 parent a371492 commit 92624b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
21 changes: 21 additions & 0 deletions pkg/webhooks/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"net/http"
"strings"
"time"

"github.com/samber/lo"
"go.uber.org/zap"
Expand All @@ -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"
Expand Down Expand Up @@ -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):
}
}
}

0 comments on commit 92624b9

Please sign in to comment.