Skip to content

Commit f126b1c

Browse files
authored
Added support for reusing the webhook TLS certificate across different deployments to prevent cases where operator takes too long to start up (#180)
1 parent d182a14 commit f126b1c

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

src/operator/config/rbac/role.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ rules:
2525
- patch
2626
- update
2727
- watch
28+
- apiGroups:
29+
- ""
30+
resourceNames:
31+
- credentials-operator-webhook-cert
32+
resources:
33+
- secrets
34+
verbs:
35+
- get
36+
- list
37+
- update
38+
- watch
2839
- apiGroups:
2940
- ""
3041
resources:

src/operator/go.mod

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/operator/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/operator/main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,25 @@ func main() {
231231
// setup webhook
232232
if viper.GetBool(operatorconfig.SelfSignedCertKey) {
233233
logrus.Infoln("Creating self signing certs")
234-
certBundle, err := operatorwebhooks.GenerateSelfSignedCertificate("credentials-operator-webhook-service", podNamespace)
234+
secretName := viper.GetString(operatorconfig.WebhookCertSecretNameKey)
235+
certBundle, ok, err := operatorwebhooks.ReadCertBundleFromSecret(signalHandlerCtx, directClient, secretName, podNamespace)
235236
if err != nil {
236-
logrus.WithError(err).Panic("unable to create self signed certs for webhook")
237+
logrus.WithError(err).Warn("unable to read existing certs from secret, generating new ones")
238+
}
239+
if !ok {
240+
logrus.Info("webhook certs uninitialized, generating new certs")
241+
}
242+
if !ok || err != nil {
243+
certBundleNew, err :=
244+
operatorwebhooks.GenerateSelfSignedCertificate("intents-operator-webhook-service", podNamespace)
245+
if err != nil {
246+
logrus.WithError(err).Panic("unable to create self signed certs for webhook")
247+
}
248+
err = operatorwebhooks.PersistCertBundleToSecret(signalHandlerCtx, directClient, secretName, podNamespace, certBundleNew)
249+
if err != nil {
250+
logrus.WithError(err).Panic("unable to persist certs to secret")
251+
}
252+
certBundle = certBundleNew
237253
}
238254
err = operatorwebhooks.WriteCertToFiles(certBundle)
239255
if err != nil {

src/operator/operatorconfig/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const (
5757
EnableSecretRotationDefault = false
5858
DatabasePasswordRotationIntervalKey = "database-password-rotation-interval"
5959
DatabasePasswordRotationIntervalDefault = time.Hour * 8
60+
WebhookCertSecretNameKey = "webhook-cert-secret-name"
61+
WebhookCertSecretNameDefault = "credentials-operator-webhook-cert"
6062
)
6163

6264
const (
@@ -86,6 +88,7 @@ func init() {
8688
viper.SetDefault(AWSUseSoftDeleteStrategyKey, AWSUseSoftDeleteStrategyDefault)
8789
viper.SetDefault(EnableSecretRotationKey, EnableSecretRotationDefault)
8890
viper.SetDefault(DebugKey, DebugDefault)
91+
viper.SetDefault(WebhookCertSecretNameKey, WebhookCertSecretNameDefault)
8992
viper.SetEnvPrefix(EnvPrefix)
9093
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
9194
viper.AutomaticEnv()

0 commit comments

Comments
 (0)