Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 75fcae7

Browse files
committed
Use cert-rotator for API extension service
Add cert-rotator to the setup for the new resource list extension to remove the dependency on cert-manager.
1 parent fcebcbe commit 75fcae7

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

internal/setup/webhooks.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,26 @@ import (
1919
)
2020

2121
const (
22-
serviceName = "hnc-webhook-service"
23-
vwhName = "hnc-validating-webhook-configuration"
24-
mwhName = "hnc-mutating-webhook-configuration"
25-
caName = "hnc-ca"
26-
caOrganization = "hnc"
27-
secretName = "hnc-webhook-server-cert"
28-
certDir = "/tmp/k8s-webhook-server/serving-certs"
22+
serviceName = "hnc-webhook-service"
23+
vwhName = "hnc-validating-webhook-configuration"
24+
mwhName = "hnc-mutating-webhook-configuration"
25+
caName = "hnc-ca"
26+
caOrganization = "hnc"
27+
secretName = "hnc-webhook-server-cert"
28+
certDir = "/tmp/k8s-webhook-server/serving-certs"
29+
apiExtCertDir = "/certs"
30+
apiExtServiceName = "hnc-resourcelist"
31+
apiExtSecretName = "hnc-resourcelist"
32+
apiExtName = "v1alpha2.resources.hnc.x-k8s.io"
2933
)
3034

31-
// ManageCerts creates all certs for webhooks. This function is called from main.go.
35+
// ManageCerts creates all certs for webhooks and apiservices. This function is called from main.go.
3236
func ManageCerts(mgr ctrl.Manager, setupFinished chan struct{}, restartOnSecretRefresh bool) error {
3337
hncNamespace := config.GetHNCNamespace()
3438
// DNSName is <service name>.<hncNamespace>.svc
3539
dnsName := fmt.Sprintf("%s.%s.svc", serviceName, hncNamespace)
3640

37-
return cert.AddRotator(mgr, &cert.CertRotator{
41+
err := cert.AddRotator(mgr, &cert.CertRotator{
3842
SecretKey: types.NamespacedName{
3943
Namespace: hncNamespace,
4044
Name: secretName,
@@ -53,6 +57,26 @@ func ManageCerts(mgr ctrl.Manager, setupFinished chan struct{}, restartOnSecretR
5357
}},
5458
RestartOnSecretRefresh: restartOnSecretRefresh,
5559
})
60+
if err != nil {
61+
return err
62+
}
63+
apiExtDNSName := fmt.Sprintf("%s.%s.svc", apiExtServiceName, hncNamespace)
64+
return cert.AddRotator(mgr, &cert.CertRotator{
65+
SecretKey: types.NamespacedName{
66+
Namespace: hncNamespace,
67+
Name: apiExtSecretName,
68+
},
69+
CertDir: apiExtCertDir,
70+
CAName: caName,
71+
CAOrganization: caOrganization,
72+
DNSName: apiExtDNSName,
73+
IsReady: setupFinished,
74+
Webhooks: []cert.WebhookInfo{{
75+
Type: cert.APIService,
76+
Name: apiExtName,
77+
}},
78+
RestartOnSecretRefresh: restartOnSecretRefresh,
79+
})
5680
}
5781

5882
// createWebhooks creates all mutators and validators.

0 commit comments

Comments
 (0)