Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigAPI: Implement validations for the internalCertManagement #2169

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions pkg/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
apimachineryvalidation "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

configapi "sigs.k8s.io/kueue/apis/config/v1beta1"
Expand All @@ -54,20 +55,35 @@ var (
requeuingStrategyPath = waitForPodsReadyPath.Child("requeuingStrategy")
multiKueuePath = field.NewPath("multiKueue")
fsPreemptionStrategiesPath = field.NewPath("fairSharing", "preemptionStrategies")
internalCertManagementPath = field.NewPath("internalCertManagement")
)

func validate(c *configapi.Configuration, scheme *runtime.Scheme) field.ErrorList {
var allErrs field.ErrorList

allErrs = append(allErrs, validateWaitForPodsReady(c)...)

allErrs = append(allErrs, validateQueueVisibility(c)...)

// Validate PodNamespaceSelector for the pod framework
allErrs = append(allErrs, validateIntegrations(c, scheme)...)

allErrs = append(allErrs, validateMultiKueue(c)...)
allErrs = append(allErrs, validateFairSharing(c)...)
allErrs = append(allErrs, validateInternalCertManagement(c)...)
return allErrs
}

func validateInternalCertManagement(c *configapi.Configuration) field.ErrorList {
var allErrs field.ErrorList
if c.InternalCertManagement == nil || !ptr.Deref(c.InternalCertManagement.Enable, false) {
return allErrs
}
if svcName := c.InternalCertManagement.WebhookServiceName; svcName != nil {
if errs := apimachineryvalidation.IsDNS1035Label(*svcName); len(errs) != 0 {
allErrs = append(allErrs, field.Invalid(internalCertManagementPath.Child("webhookServiceName"), svcName, strings.Join(errs, ",")))
}
}
if secName := c.InternalCertManagement.WebhookSecretName; secName != nil {
if errs := apimachineryvalidation.IsDNS1123Subdomain(*secName); len(errs) != 0 {
allErrs = append(allErrs, field.Invalid(internalCertManagementPath.Child("webhookSecretName"), secName, strings.Join(errs, ",")))
}
}
return allErrs
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/config/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,55 @@ func TestValidate(t *testing.T) {
},
},
},
"invalid .internalCertManagement.webhookSecretName": {
cfg: &configapi.Configuration{
Integrations: defaultIntegrations,
InternalCertManagement: &configapi.InternalCertManagement{
Enable: ptr.To(true),
WebhookSecretName: ptr.To(":)"),
},
},
wantErr: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "internalCertManagement.webhookSecretName",
},
},
},
"invalid .internalCertManagement.webhookServiceName": {
cfg: &configapi.Configuration{
Integrations: defaultIntegrations,
InternalCertManagement: &configapi.InternalCertManagement{
Enable: ptr.To(true),
WebhookServiceName: ptr.To("0-invalid"),
},
},
wantErr: field.ErrorList{
&field.Error{
Type: field.ErrorTypeInvalid,
Field: "internalCertManagement.webhookServiceName",
},
},
},
"disabled .internalCertManagement with invalid .internalCertManagement.webhookServiceName": {
cfg: &configapi.Configuration{
Integrations: defaultIntegrations,
InternalCertManagement: &configapi.InternalCertManagement{
Enable: ptr.To(false),
WebhookServiceName: ptr.To("0-invalid"),
},
},
},
"valid .internalCertManagement": {
cfg: &configapi.Configuration{
Integrations: defaultIntegrations,
InternalCertManagement: &configapi.InternalCertManagement{
Enable: ptr.To(true),
WebhookServiceName: ptr.To("webhook-svc"),
WebhookSecretName: ptr.To("webhook-sec"),
},
},
},
}

for name, tc := range testCases {
Expand Down