-
Notifications
You must be signed in to change notification settings - Fork 235
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
feat: implement validation webhook for Queue #264
feat: implement validation webhook for Queue #264
Conversation
/cc @alculquicondor |
756d510
to
fd983f1
Compare
const queueName = "queue-test" | ||
|
||
var _ = ginkgo.Describe("Queue validating webhook", func() { | ||
ginkgo.Context("When updating a Queue", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a normal path as you did in workload validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't we settle on using when
instead of context?
Sorry for the delay, I'm finally catching up with kueue's PRs. I'll get back to this tomorrow. /cc |
fd983f1
to
4c2ba7d
Compare
@knight42 better to comment on the reviewer's comments so that they get notified that you addressed their review. I don't think @alculquicondor got notified that you uploaded a new patch addressing his comments. |
apis/kueue/v1alpha1/queue_webhook.go
Outdated
} | ||
|
||
func ValidateQueueCreate(q *Queue) field.ErrorList { | ||
return apivalidation.ValidateObjectMetaAccessor(q.GetObjectMeta(), true, apivalidation.NameIsDNSLabel, field.NewPath("metadata")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to validate spec.ClusterQueue as a valid name, not metadata.Name (this one is validated by the api-server)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the method to use to validate is NameIsDNSSubdomain
https://github.com/kubernetes/kubernetes/blob/8c8a4cf3e4a18e97359ce750530a4fa27bbd3b88/staging/src/k8s.io/apiextensions-apiserver/pkg/registry/customresource/validator.go#L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahg-g @alculquicondor Thanks for the suggestion, it should be fixed now. Please take another look
939e44a
to
4b47e8b
Compare
main.go
Outdated
@@ -161,7 +161,11 @@ func setupControllers(mgr ctrl.Manager, cCache *cache.Cache, queues *queue.Manag | |||
setupLog.Error(err, "Unable to create webhook", "webhook", failedWebhook) | |||
os.Exit(1) | |||
} | |||
//+kubebuilder:scaffold:builder | |||
if err := (&kueuev1alpha1.Queue{}).SetupWebhookWithManager(mgr); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have settled this in SetupWebhooks
. Plz remove it.
wantErr field.ErrorList | ||
}{ | ||
"should reject invalid clusterQueue": { | ||
queue: testingutil.MakeQueue(testQueueName, testQueueNamespace).ClusterQueue("invalid_queue").Obj(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"invalid_clusterQueue" ?
queue *Queue | ||
wantErr field.ErrorList | ||
}{ | ||
"should reject invalid clusterQueue": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should reject queue creation with an invalid clusterQueue name?
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
errList := ValidateQueueCreate(tc.queue) | ||
if len(errList) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? Diff the results seems enough.
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
errList := ValidateQueueUpdate(tc.before, tc.after) | ||
if len(tc.wantErr) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, if no errors expected, you can set the wantErr: field.ErrorList{}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@knight42 can you address this please as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have overlooked.. should be fixed this time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few nits, can you please address Kante's comments so we merge this?
apis/kueue/v1alpha1/queue_webhook.go
Outdated
func ValidateQueueCreate(q *Queue) field.ErrorList { | ||
var allErrs field.ErrorList | ||
for _, msg := range apivalidation.NameIsDNSSubdomain(string(q.Spec.ClusterQueue), false) { | ||
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "clusterQueue"), q.Spec.ClusterQueue, msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create the path once before the for loop
const queueName = "queue-test" | ||
|
||
var _ = ginkgo.Describe("Queue validating webhook", func() { | ||
ginkgo.Context("When updating a Queue", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't we settle on using when
instead of context?
Hi @knight42 are you still on this one? |
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
44c5063
to
9f7d9b3
Compare
All comments should be addressed now, PTAL |
Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
9f7d9b3
to
242fc47
Compare
/label tide/merge-method-squash |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahg-g, knight42 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* feat: implement validation webhook for Queue Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * address comments Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * fix: fix build error Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * feat: validate clusterQueue in Queue Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * fix: setup webhook for Queue Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * test: update test Signed-off-by: Jian Zeng <anonymousknight96@gmail.com> * address comments Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
Signed-off-by: Jian Zeng anonymousknight96@gmail.com
What type of PR is this?
/kind feature
What this PR does / why we need it:
Which issue(s) this PR fixes:
Ref #171
Special notes for your reviewer: