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

feat: implement validation webhook for Queue #264

Merged

Conversation

knight42
Copy link
Member

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:

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 15, 2022
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 15, 2022
@knight42
Copy link
Member Author

/cc @alculquicondor

apis/kueue/v1alpha1/queue_webhook_test.go Outdated Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook_test.go Outdated Show resolved Hide resolved
const queueName = "queue-test"

var _ = ginkgo.Describe("Queue validating webhook", func() {
ginkgo.Context("When updating a Queue", func() {
Copy link
Contributor

@kerthcet kerthcet May 23, 2022

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?

Copy link
Contributor

@ahg-g ahg-g Jul 26, 2022

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?

@alculquicondor
Copy link
Contributor

Sorry for the delay, I'm finally catching up with kueue's PRs. I'll get back to this tomorrow.

/cc

apis/kueue/v1alpha1/queue_webhook.go Outdated Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook.go Outdated Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook.go Outdated Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook.go Outdated Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook_test.go Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook_test.go Outdated Show resolved Hide resolved
apis/kueue/v1alpha1/queue_webhook_test.go Outdated Show resolved Hide resolved
@ahg-g
Copy link
Contributor

ahg-g commented Jul 18, 2022

@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.

}

func ValidateQueueCreate(q *Queue) field.ErrorList {
return apivalidation.ValidateObjectMetaAccessor(q.GetObjectMeta(), true, apivalidation.NameIsDNSLabel, field.NewPath("metadata"))
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 19, 2022
@knight42 knight42 force-pushed the feat/queue-validate-webhook branch from 939e44a to 4b47e8b Compare July 20, 2022 14:09
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 20, 2022
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 {
Copy link
Contributor

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(),
Copy link
Contributor

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": {
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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{}.

Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

@ahg-g ahg-g left a 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?

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))
Copy link
Contributor

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() {
Copy link
Contributor

@ahg-g ahg-g Jul 26, 2022

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?

@ahg-g
Copy link
Contributor

ahg-g commented Jul 27, 2022

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>
@knight42 knight42 force-pushed the feat/queue-validate-webhook branch 2 times, most recently from 44c5063 to 9f7d9b3 Compare July 28, 2022 14:07
@knight42
Copy link
Member Author

All comments should be addressed now, PTAL

Signed-off-by: Jian Zeng <anonymousknight96@gmail.com>
@knight42 knight42 force-pushed the feat/queue-validate-webhook branch from 9f7d9b3 to 242fc47 Compare July 28, 2022 17:13
@ahg-g
Copy link
Contributor

ahg-g commented Jul 28, 2022

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 28, 2022
@ahg-g
Copy link
Contributor

ahg-g commented Jul 28, 2022

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 28, 2022
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2022
@k8s-ci-robot k8s-ci-robot merged commit 4fca39d into kubernetes-sigs:main Jul 28, 2022
@knight42 knight42 deleted the feat/queue-validate-webhook branch July 29, 2022 00:46
ahg-g pushed a commit to ahg-g/kueue that referenced this pull request Aug 10, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants