Skip to content

Commit e1f43d6

Browse files
authored
put all cert-controller constants in config struct (#69)
1 parent fceec10 commit e1f43d6

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

pkg/config/config.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ type FaultToleranceConfig struct {
3333
}
3434

3535
type CertManagementConfig struct {
36-
WebhookServiceName string `json:"webhookServiceName,omitempty"`
37-
WebhookSecretName string `json:"webhookSecretName,omitempty"`
38-
Namespace string `json:"namespace,omitempty"`
36+
Namespace string `json:"namespace,omitempty"`
37+
CertificateDir string `json:"certificateDir,omitempty"`
38+
CertificateName string `json:"certificateName,omitempty"`
39+
CertificateOrg string `json:"certificateOrg,omitempty"`
40+
MutatingWebhookConfigName string `json:"mutatingWebhookConfigName,omitempty"`
41+
ValidatingWebhookConfigName string `json:"validatingWebhookConfigName,omitempty"`
42+
WebhookServiceName string `json:"webhookServiceName,omitempty"`
43+
WebhookSecretName string `json:"webhookSecretName,omitempty"`
3944
}
4045

4146
// NewConfig constructs an AppWrapperConfig and fills in default values
@@ -50,9 +55,14 @@ func NewConfig(namespace string) *AppWrapperConfig {
5055
RetryLimit: 3,
5156
},
5257
CertManagement: CertManagementConfig{
53-
WebhookServiceName: "appwrapper-webhook-service",
54-
WebhookSecretName: "appwrapper-webhook-server-cert",
55-
Namespace: namespace,
58+
Namespace: namespace,
59+
CertificateDir: "/tmp/k8s-webhook-server/serving-certs",
60+
CertificateName: "appwrapper-ca",
61+
CertificateOrg: "appwrapper",
62+
MutatingWebhookConfigName: "appwrapper-mutating-webhook-configuration",
63+
ValidatingWebhookConfigName: "appwrapper-validating-webhook-configuration",
64+
WebhookServiceName: "appwrapper-webhook-service",
65+
WebhookSecretName: "appwrapper-webhook-server-cert",
5666
},
5767
}
5868
}

pkg/controller/setup.go

+5-13
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ import (
3838
"sigs.k8s.io/kueue/pkg/controller/jobframework"
3939
)
4040

41-
const (
42-
certDir = "/tmp/k8s-webhook-server/serving-certs"
43-
vwcName = "appwrapper-validating-webhook-configuration"
44-
mwcName = "appwrapper-mutating-webhook-configuration"
45-
caName = "appwrapper-ca"
46-
caOrganization = "appwrapper"
47-
)
48-
4941
// SetupControllers creates and configures all components of the AppWrapper controller
5042
func SetupControllers(ctx context.Context, mgr ctrl.Manager, awConfig *config.AppWrapperConfig,
5143
certsReady chan struct{}, log logr.Logger) {
@@ -129,14 +121,14 @@ func SetupCertManagement(mgr ctrl.Manager, config *config.CertManagementConfig,
129121

130122
return cert.AddRotator(mgr, &cert.CertRotator{
131123
SecretKey: types.NamespacedName{Namespace: config.Namespace, Name: config.WebhookSecretName},
132-
CertDir: certDir,
133-
CAName: caName,
134-
CAOrganization: caOrganization,
124+
CertDir: config.CertificateDir,
125+
CAName: config.CertificateName,
126+
CAOrganization: config.CertificateOrg,
135127
DNSName: dnsName,
136128
IsReady: certsReady,
137129
Webhooks: []cert.WebhookInfo{
138-
{Type: cert.Validating, Name: vwcName},
139-
{Type: cert.Mutating, Name: mwcName},
130+
{Type: cert.Validating, Name: config.ValidatingWebhookConfigName},
131+
{Type: cert.Mutating, Name: config.MutatingWebhookConfigName},
140132
},
141133
// When the controller is running in the leader election mode,
142134
// we expect webhook server will run in primary and secondary instance

0 commit comments

Comments
 (0)