Skip to content

Commit 110c93c

Browse files
KrishnaSindhurkrishna sindhurwozniakjan
authored
add: enable webhook patching with flag (#6396)
* add: enable webhook patching with flag Signed-off-by: krishna sindhur <[email protected]> * update: should enable/disable only the webhook Signed-off-by: krishna sindhur <[email protected]> * changelog: put webhook patching flag to 'New' section Signed-off-by: Jan Wozniak <[email protected]> --------- Signed-off-by: krishna sindhur <[email protected]> Signed-off-by: Jan Wozniak <[email protected]> Co-authored-by: krishna sindhur <[email protected]> Co-authored-by: Jan Wozniak <[email protected]>
1 parent 27c99dc commit 110c93c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
6060

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

6465
#### Experimental
6566

Diff for: cmd/operator/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func main() {
8585
var enableCertRotation bool
8686
var validatingWebhookName string
8787
var caDirs []string
88+
var enableWebhookPatching bool
8889
pflag.BoolVar(&enablePrometheusMetrics, "enable-prometheus-metrics", true, "Enable the prometheus metric of keda-operator.")
8990
pflag.BoolVar(&enableOpenTelemetryMetrics, "enable-opentelemetry-metrics", false, "Enable the opentelemetry metric of keda-operator.")
9091
pflag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the prometheus metric endpoint binds to.")
@@ -107,6 +108,7 @@ func main() {
107108
pflag.BoolVar(&enableCertRotation, "enable-cert-rotation", false, "enable automatic generation and rotation of TLS certificates/keys")
108109
pflag.StringVar(&validatingWebhookName, "validating-webhook-name", "keda-admission", "ValidatingWebhookConfiguration name. Defaults to keda-admission")
109110
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")
111+
pflag.BoolVar(&enableWebhookPatching, "enable-webhook-patching", true, "Enable patching of webhook resources. Defaults to true.")
110112
opts := zap.Options{}
111113
opts.BindFlags(flag.CommandLine)
112114
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
@@ -305,6 +307,7 @@ func main() {
305307
APIServiceName: "v1beta1.external.metrics.k8s.io",
306308
Logger: setupLog,
307309
Ready: certReady,
310+
EnableWebhookPatching: enableWebhookPatching,
308311
}
309312
if err := certManager.AddCertificateRotation(ctx, mgr); err != nil {
310313
setupLog.Error(err, "unable to set up cert rotation")

Diff for: pkg/certificates/certificate_manager.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,29 @@ type CertManager struct {
5050
APIServiceName string
5151
Logger logr.Logger
5252
Ready chan struct{}
53+
EnableWebhookPatching bool
5354
}
5455

5556
// AddCertificateRotation registers all needed services to generate the certificates and patches needed resources with the caBundle
5657
func (cm CertManager) AddCertificateRotation(ctx context.Context, mgr manager.Manager) error {
57-
var rotatorHooks = []rotator.WebhookInfo{
58-
{
59-
Name: cm.ValidatingWebhookName,
60-
Type: rotator.Validating,
61-
},
58+
rotatorHooks := []rotator.WebhookInfo{
6259
{
6360
Name: cm.APIServiceName,
6461
Type: rotator.APIService,
6562
},
6663
}
6764

65+
if cm.EnableWebhookPatching {
66+
rotatorHooks = append(rotatorHooks,
67+
rotator.WebhookInfo{
68+
Name: cm.ValidatingWebhookName,
69+
Type: rotator.Validating,
70+
},
71+
)
72+
} else {
73+
cm.Logger.V(1).Info("Webhook patching is disabled, skipping webhook certificates")
74+
}
75+
6876
err := cm.ensureSecret(ctx, mgr, cm.SecretName)
6977
if err != nil {
7078
return err

0 commit comments

Comments
 (0)