Skip to content

Commit

Permalink
add: enable webhook patching with flag (kedacore#6396)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Dec 16, 2024
1 parent 27c99dc commit 110c93c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
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

0 comments on commit 110c93c

Please sign in to comment.