Skip to content

Commit 304392a

Browse files
authored
configure webhook names (NVIDIA#564)
* Add webhook configuration name customization - Added optional fields in Admission, PodGroupController, and QueueController to specify webhook configuration names.
1 parent 5938926 commit 304392a

File tree

11 files changed

+90
-22
lines changed

11 files changed

+90
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
88

99
### Added
1010
- Added parent reference to SubGroup struct in PodGroup CRD to create a hierarchical SubGroup structure
11+
- Added the option to configure the names of the webhook configuration resources.
1112

1213
### Fixed
1314
- Fixed a bug where the scheduler would not re-try updating podgroup status after failure

deployments/kai-scheduler/crds/kai.scheduler_configs.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ spec:
4848
description: GPUSharing enables GPU sharing functionality for
4949
the admission service
5050
type: boolean
51+
mutatingWebhookConfigurationName:
52+
description: MutatingWebhookConfigurationName is the name of the
53+
MutatingWebhookConfiguration for the admission service
54+
type: string
5155
queueLabelSelector:
5256
description: QueueLabelSelector enables the queue label MatchExpression
5357
in webhooks
@@ -153,6 +157,10 @@ spec:
153157
type: object
154158
type: object
155159
type: object
160+
validatingWebhookConfigurationName:
161+
description: ValidatingWebhookConfigurationName is the name of
162+
the ValidatingWebhookConfiguration for the admission service
163+
type: string
156164
webhook:
157165
description: Webhook defines configuration for the admission service
158166
properties:
@@ -1846,7 +1854,13 @@ spec:
18461854
controller webhooks
18471855
properties:
18481856
enableValidation:
1857+
description: EnableValidation enables the validation webhook
1858+
for the pod group controller
18491859
type: boolean
1860+
webhookConfigurationNamePrefix:
1861+
description: WebhookConfigurationNamePrefix is the prefix
1862+
used for webhook configuration names
1863+
type: string
18501864
type: object
18511865
type: object
18521866
podGrouper:
@@ -2162,7 +2176,13 @@ spec:
21622176
controller webhooks
21632177
properties:
21642178
enableValidation:
2179+
description: EnableValidation enables the validation webhook
2180+
for the queue controller
21652181
type: boolean
2182+
webhookConfigurationNamePrefix:
2183+
description: WebhookConfigurationNamePrefix is the prefix
2184+
used for webhook configuration names
2185+
type: string
21662186
type: object
21672187
type: object
21682188
scheduler:

pkg/apis/kai/v1/admission/admission.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
)
1212

1313
const (
14-
imageName = "admission"
14+
imageName = "admission"
15+
defaultValidatingWebhookName = "validating-kai-admission"
16+
defaultMutatingWebhookName = "mutating-kai-admission"
1517
)
1618

1719
type Admission struct {
@@ -32,6 +34,14 @@ type Admission struct {
3234
// QueueLabelSelector enables the queue label MatchExpression in webhooks
3335
// +kubebuilder:validation:Optional
3436
QueueLabelSelector *bool `json:"queueLabelSelector,omitempty"`
37+
38+
// ValidatingWebhookConfigurationName is the name of the ValidatingWebhookConfiguration for the admission service
39+
// +kubebuilder:validation:Optional
40+
ValidatingWebhookConfigurationName *string `json:"validatingWebhookConfigurationName,omitempty"`
41+
42+
// MutatingWebhookConfigurationName is the name of the MutatingWebhookConfiguration for the admission service
43+
// +kubebuilder:validation:Optional
44+
MutatingWebhookConfigurationName *string `json:"mutatingWebhookConfigurationName,omitempty"`
3545
}
3646

3747
func (b *Admission) SetDefaultsWhereNeeded(replicaCount *int32) {
@@ -47,6 +57,9 @@ func (b *Admission) SetDefaultsWhereNeeded(replicaCount *int32) {
4757
b.Replicas = common.SetDefault(b.Replicas, ptr.To(ptr.Deref(replicaCount, 1)))
4858
b.GPUSharing = common.SetDefault(b.GPUSharing, ptr.To(false))
4959
b.QueueLabelSelector = common.SetDefault(b.QueueLabelSelector, ptr.To(false))
60+
61+
b.ValidatingWebhookConfigurationName = common.SetDefault(b.ValidatingWebhookConfigurationName, ptr.To(defaultValidatingWebhookName))
62+
b.MutatingWebhookConfigurationName = common.SetDefault(b.MutatingWebhookConfigurationName, ptr.To(defaultMutatingWebhookName))
5063
}
5164

5265
// Webhook defines configuration for the admission webhook

pkg/apis/kai/v1/admission/zz_generated.deepcopy.go

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

pkg/apis/kai/v1/pod_group_controller/pod_group_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
)
1414

1515
const (
16-
imageName = "podgroupcontroller"
16+
imageName = "podgroupcontroller"
17+
defaultValidatingWebhookPrefix = "kai-podgroup-validation-"
1718
)
1819

1920
type PodGroupController struct {
@@ -96,9 +97,16 @@ func (p *PortMapping) SetDefaultsWhereNeeded() {
9697
}
9798

9899
type PodGroupControllerWebhooks struct {
100+
// EnableValidation enables the validation webhook for the pod group controller
101+
// +kubebuilder:validation:Optional
99102
EnableValidation *bool `json:"enableValidation,omitempty"`
103+
104+
// WebhookConfigurationNamePrefix is the prefix used for webhook configuration names
105+
// +kubebuilder:validation:Optional
106+
WebhookConfigurationNamePrefix *string `json:"webhookConfigurationNamePrefix,omitempty"`
100107
}
101108

102109
func (q *PodGroupControllerWebhooks) SetDefaultsWhereNeeded() {
103110
q.EnableValidation = common.SetDefault(q.EnableValidation, ptr.To(true))
111+
q.WebhookConfigurationNamePrefix = common.SetDefault(q.WebhookConfigurationNamePrefix, ptr.To(defaultValidatingWebhookPrefix))
104112
}

pkg/apis/kai/v1/pod_group_controller/zz_generated.deepcopy.go

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

pkg/apis/kai/v1/queue_controller/queue_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
)
1313

1414
const (
15-
imageName = "queuecontroller"
15+
imageName = "queuecontroller"
16+
defaultValidatingWebhookPrefix = "kai-queue-validation-"
1617
)
1718

1819
type QueueController struct {
@@ -110,9 +111,16 @@ func (p *PortMapping) SetDefaultsWhereNeeded() {
110111
}
111112

112113
type QueueControllerWebhooks struct {
114+
// EnableValidation enables the validation webhook for the queue controller
115+
// +kubebuilder:validation:Optional
113116
EnableValidation *bool `json:"enableValidation,omitempty"`
117+
118+
// WebhookConfigurationNamePrefix is the prefix used for webhook configuration names
119+
// +kubebuilder:validation:Optional
120+
WebhookConfigurationNamePrefix *string `json:"webhookConfigurationNamePrefix,omitempty"`
114121
}
115122

116123
func (q *QueueControllerWebhooks) SetDefaultsWhereNeeded() {
117124
q.EnableValidation = common.SetDefault(q.EnableValidation, ptr.To(true))
125+
q.WebhookConfigurationNamePrefix = common.SetDefault(q.WebhookConfigurationNamePrefix, ptr.To(defaultValidatingWebhookPrefix))
118126
}

pkg/apis/kai/v1/queue_controller/zz_generated.deepcopy.go

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

pkg/operator/operands/admission/resources.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ import (
2525
)
2626

2727
const (
28-
mainResourceName = "admission"
29-
mutatorWebhookKAIAdmissionResourceName = "mutating-kai-admission"
30-
validatorWebhookKAIAdmissionResourceName = "validating-kai-admission"
31-
kaiAdmissionWebhookSecretName = "kai-admission-webhook-tls-secret"
32-
certKey = "tls.crt"
33-
keyKey = "tls.key"
28+
mainResourceName = "admission"
29+
kaiAdmissionWebhookSecretName = "kai-admission-webhook-tls-secret"
30+
certKey = "tls.crt"
31+
keyKey = "tls.key"
3432
)
3533

3634
func deploymentForKAIConfig(
@@ -198,11 +196,12 @@ func mutatingWCForKAIConfig(
198196
secret *v1.Secret, webhookName string,
199197
) ([]client.Object, error) {
200198
mutatingWebhookConfiguration := &admissionv1.MutatingWebhookConfiguration{}
201-
err := runtimeClient.Get(ctx, types.NamespacedName{Name: mutatorWebhookKAIAdmissionResourceName}, mutatingWebhookConfiguration)
199+
webhookConfigurationName := *kaiConfig.Spec.Admission.MutatingWebhookConfigurationName
200+
err := runtimeClient.Get(ctx, types.NamespacedName{Name: webhookConfigurationName}, mutatingWebhookConfiguration)
202201
if client.IgnoreNotFound(err) != nil {
203202
return nil, err
204203
}
205-
mutatingWebhookConfiguration.Name = mutatorWebhookKAIAdmissionResourceName
204+
mutatingWebhookConfiguration.Name = webhookConfigurationName
206205

207206
if mutatingWebhookConfiguration.Labels == nil {
208207
mutatingWebhookConfiguration.Labels = map[string]string{}
@@ -244,12 +243,13 @@ func validatingWCForKAIConfig(
244243
secret *v1.Secret, webhookName string,
245244
) ([]client.Object, error) {
246245
validatingWebhookConfiguration := &admissionv1.ValidatingWebhookConfiguration{}
247-
err := runtimeClient.Get(ctx, types.NamespacedName{Name: validatorWebhookKAIAdmissionResourceName},
246+
webhookConfigurationName := *kaiConfig.Spec.Admission.ValidatingWebhookConfigurationName
247+
err := runtimeClient.Get(ctx, types.NamespacedName{Name: webhookConfigurationName},
248248
validatingWebhookConfiguration)
249249
if client.IgnoreNotFound(err) != nil {
250250
return nil, err
251251
}
252-
validatingWebhookConfiguration.Name = validatorWebhookKAIAdmissionResourceName
252+
validatingWebhookConfiguration.Name = webhookConfigurationName
253253

254254
if validatingWebhookConfiguration.Labels == nil {
255255
validatingWebhookConfiguration.Labels = map[string]string{}

pkg/operator/operands/pod_group_controller/resources.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const (
2828
appName = deploymentName
2929
serviceName = deploymentName
3030

31-
validatingWebhookPrefix = "kai-podgroup-validation-"
32-
podGroupWebhookName = "podgroup-validation.kai.scheduler"
31+
podGroupWebhookName = "podgroup-validation.kai.scheduler"
3332

3433
secretName = "podgroup-webhook-tls-secret"
3534
certKey = "tls.crt"
@@ -163,7 +162,7 @@ func validatingWCForKAIConfig(
163162
for _, version := range constants.PodGroupValidatedVersions() {
164163
validatingWebhookConfiguration := &admissionv1.ValidatingWebhookConfiguration{}
165164

166-
webhookName := fmt.Sprintf("%s%s", validatingWebhookPrefix, version)
165+
webhookName := fmt.Sprintf("%s%s", *kaiConfig.Spec.PodGroupController.Webhooks.WebhookConfigurationNamePrefix, version)
167166
err = runtimeClient.Get(ctx, types.NamespacedName{Name: webhookName}, validatingWebhookConfiguration)
168167
if client.IgnoreNotFound(err) != nil {
169168
return nil, err

0 commit comments

Comments
 (0)