Skip to content

Commit

Permalink
args webhook initialize timeout, default is 60s
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg authored and furykerry committed Mar 4, 2025
1 parent 29258d3 commit 5e46d3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (
defaultRenewDeadline = 10 * time.Second
defaultRetryPeriod = 2 * time.Second
defaultControllerCacheSyncTimeout = 2 * time.Minute
defaultWebhookInitializeTimeout = 60 * time.Second
)

var (
Expand Down Expand Up @@ -102,6 +103,7 @@ func main() {
var leaderElectionId string
var retryPeriod time.Duration
var controllerCacheSyncTimeout time.Duration
var webhookInitializeTimeout time.Duration

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&healthProbeAddr, "health-probe-addr", ":8000", "The address the healthz/readyz endpoint binds to.")
Expand All @@ -126,6 +128,7 @@ func main() {
flag.DurationVar(&retryPeriod, "leader-election-retry-period", defaultRetryPeriod,
"leader-election-retry-period is the duration the LeaderElector clients should wait between tries of actions. Default is 2 seconds.")
flag.DurationVar(&controllerCacheSyncTimeout, "controller-cache-sync-timeout", defaultControllerCacheSyncTimeout, "CacheSyncTimeout refers to the time limit set to wait for syncing caches. Defaults to 2 minutes if not set.")
flag.DurationVar(&webhookInitializeTimeout, "webhook-initialize-timeout", defaultWebhookInitializeTimeout, "WebhookInitializeTimeout refers to the time limit set to wait for webhook initialization. Defaults to 60 seconds if not set.")

utilfeature.DefaultMutableFeatureGate.AddFlag(pflag.CommandLine)
logOptions := logs.NewOptions()
Expand Down Expand Up @@ -231,7 +234,7 @@ func main() {

// +kubebuilder:scaffold:builder
setupLog.Info("initialize webhook")
if err := webhook.Initialize(ctx, cfg); err != nil {
if err := webhook.Initialize(ctx, cfg, webhookInitializeTimeout); err != nil {
setupLog.Error(err, "unable to initialize webhook")
os.Exit(1)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func SetupWithManager(mgr manager.Manager) error {
// +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=validatingwebhookconfigurations,verbs=get;list;watch;update;patch
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch;update;patch

func Initialize(ctx context.Context, cfg *rest.Config) error {
func Initialize(ctx context.Context, cfg *rest.Config, webhookInitializeTime time.Duration) error {
c, err := webhookcontroller.New(cfg, HandlerMap)
if err != nil {
return err
Expand All @@ -113,13 +113,13 @@ func Initialize(ctx context.Context, cfg *rest.Config) error {
c.Start(ctx)
}()

timer := time.NewTimer(time.Second * 20)
timer := time.NewTimer(webhookInitializeTime)
defer timer.Stop()
select {
case <-webhookcontroller.Inited():
return nil
case <-timer.C:
return fmt.Errorf("failed to start webhook controller for waiting more than 20s")
return fmt.Errorf("failed to start webhook controller for waiting more than %fs", webhookInitializeTime.Seconds())
}
}

Expand Down

0 comments on commit 5e46d3a

Please sign in to comment.