Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle webhook inability to connect error v35 #1631

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
}
}
}
Loading