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

add: enable webhook patching with flag #6396

Merged
merged 3 commits into from
Dec 16, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio

- **General**: Enable OpenSSF Scorecard to enhance security practices across the project ([#5913](https://github.com/kedacore/keda/issues/5913))
- **General**: Introduce new NSQ scaler ([#3281](https://github.com/kedacore/keda/issues/3281))
- **General**: Operator flag to control patching of webhook resources certificates ([#6184](https://github.com/kedacore/keda/issues/6184))

#### Experimental

Expand Down
3 changes: 3 additions & 0 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func main() {
var enableCertRotation bool
var validatingWebhookName string
var caDirs []string
var enableWebhookPatching bool
pflag.BoolVar(&enablePrometheusMetrics, "enable-prometheus-metrics", true, "Enable the prometheus metric of keda-operator.")
pflag.BoolVar(&enableOpenTelemetryMetrics, "enable-opentelemetry-metrics", false, "Enable the opentelemetry metric of keda-operator.")
pflag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the prometheus metric endpoint binds to.")
Expand All @@ -107,6 +108,7 @@ func main() {
pflag.BoolVar(&enableCertRotation, "enable-cert-rotation", false, "enable automatic generation and rotation of TLS certificates/keys")
pflag.StringVar(&validatingWebhookName, "validating-webhook-name", "keda-admission", "ValidatingWebhookConfiguration name. Defaults to keda-admission")
pflag.StringArrayVar(&caDirs, "ca-dir", []string{"/custom/ca"}, "Directory with CA certificates for scalers to authenticate TLS connections. Can be specified multiple times. Defaults to /custom/ca")
pflag.BoolVar(&enableWebhookPatching, "enable-webhook-patching", true, "Enable patching of webhook resources. Defaults to true.")
opts := zap.Options{}
opts.BindFlags(flag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
Expand Down Expand Up @@ -305,6 +307,7 @@ func main() {
APIServiceName: "v1beta1.external.metrics.k8s.io",
Logger: setupLog,
Ready: certReady,
EnableWebhookPatching: enableWebhookPatching,
}
if err := certManager.AddCertificateRotation(ctx, mgr); err != nil {
setupLog.Error(err, "unable to set up cert rotation")
Expand Down
18 changes: 13 additions & 5 deletions pkg/certificates/certificate_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,29 @@ type CertManager struct {
APIServiceName string
Logger logr.Logger
Ready chan struct{}
EnableWebhookPatching bool
}

// AddCertificateRotation registers all needed services to generate the certificates and patches needed resources with the caBundle
func (cm CertManager) AddCertificateRotation(ctx context.Context, mgr manager.Manager) error {
var rotatorHooks = []rotator.WebhookInfo{
{
Name: cm.ValidatingWebhookName,
Type: rotator.Validating,
},
rotatorHooks := []rotator.WebhookInfo{
{
Name: cm.APIServiceName,
Type: rotator.APIService,
},
}

if cm.EnableWebhookPatching {
rotatorHooks = append(rotatorHooks,
rotator.WebhookInfo{
Name: cm.ValidatingWebhookName,
Type: rotator.Validating,
},
)
} else {
cm.Logger.V(1).Info("Webhook patching is disabled, skipping webhook certificates")
}

err := cm.ensureSecret(ctx, mgr, cm.SecretName)
if err != nil {
return err
Expand Down
Loading