Skip to content

Commit

Permalink
refactoring webhookCertDir
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkrkr committed May 30, 2023
1 parent 4cb4f5c commit e562b22
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ func startOperator(ctx context.Context) error {
// Create a new Cmd to provide shared dependencies and start components
opts := ctrl.Options{
Scheme: clientgoscheme.Scheme,
CertDir: viper.GetString(operator.WebhookCertDirFlag),
LeaderElection: viper.GetBool(operator.EnableLeaderElection),
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionID: LeaderElectionLeaseName,
Expand Down Expand Up @@ -578,8 +577,10 @@ func startOperator(ctx context.Context) error {
opts.MetricsBindAddress = fmt.Sprintf(":%d", metricsPort) // 0 to disable

webhookPort := viper.GetInt(operator.WebhookPortFlag)
webhookCertDir := viper.GetString(operator.WebhookCertDirFlag)
opts.WebhookServer = crwebhook.NewServer(crwebhook.Options{
Port: webhookPort,
Port: webhookPort,
CertDir: webhookCertDir,
})

mgr, err := ctrl.NewManager(cfg, opts)
Expand Down Expand Up @@ -681,7 +682,7 @@ func startOperator(ctx context.Context) error {
}

if viper.GetBool(operator.EnableWebhookFlag) {
setupWebhook(ctx, mgr, params, clientset, exposedNodeLabels, managedNamespaces, tracer)
setupWebhook(ctx, mgr, params, webhookCertDir, clientset, exposedNodeLabels, managedNamespaces, tracer)
}

enforceRbacOnRefs := viper.GetBool(operator.EnforceRBACOnRefsFlag)
Expand Down Expand Up @@ -973,6 +974,7 @@ func setupWebhook(
ctx context.Context,
mgr manager.Manager,
params operator.Parameters,
webhookCertDir string,
clientset kubernetes.Interface,
exposedNodeLabels esvalidation.NodeLabels,
managedNamespaces []string,
Expand Down Expand Up @@ -1025,7 +1027,7 @@ func setupWebhook(
interval := time.Second * 1
timeout := time.Second * 30

keyPath := filepath.Join(mgr.GetWebhookServer().CertDir, certificates.CertFileName)
keyPath := filepath.Join(webhookCertDir, certificates.CertFileName)
log.Info("Polling for the webhook certificate to be available", "path", keyPath)
//nolint:staticcheck
err := wait.PollImmediateWithContext(ctx, interval, timeout, func(_ context.Context) (bool, error) {
Expand Down

0 comments on commit e562b22

Please sign in to comment.