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

added webhook validation for DRCluster #567

Merged
merged 1 commit into from Nov 4, 2022

Conversation

rakeshgm
Copy link
Member

@rakeshgm rakeshgm commented Oct 19, 2022

Implemented validation using webhook using cert-manager.
DRCluster CR objects Region and S3ProfileName are immutable.

Signed-off-by: rakeshgm rakeshgm@redhat.com

@rakeshgm rakeshgm marked this pull request as draft October 19, 2022 13:26
@rakeshgm
Copy link
Member Author

I believe most of the changes are complete. I need to complete one round of testing to check if the webhook is being called. so making the PR as draft for now.

@rakeshgm rakeshgm force-pushed the validate-using-webhooks branch 8 times, most recently from af33e9d to e0e5c7b Compare October 21, 2022 16:19
@rakeshgm rakeshgm force-pushed the validate-using-webhooks branch 5 times, most recently from 80be6dc to 25f5cdc Compare October 27, 2022 16:13
@rakeshgm rakeshgm marked this pull request as ready for review October 27, 2022 16:15
@rakeshgm rakeshgm force-pushed the validate-using-webhooks branch 2 times, most recently from 43f8b44 to 6de1506 Compare October 27, 2022 17:58
Copy link
Member

@iamniting iamniting left a comment

Choose a reason for hiding this comment

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

It looks good to me @rakeshgm

Copy link
Member

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

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

Can you please double-check that some yaml changes are missing, like a certificate.yaml and update in CSV, etc?

Comment on lines 59 to 52
if !reflect.DeepEqual(r.Spec.Region, oldDRCluster.Spec.Region) {
return fmt.Errorf("Region value cannot be changed")
}

if !reflect.DeepEqual(r.Spec.S3ProfileName, oldDRCluster.Spec.S3ProfileName) {
return fmt.Errorf("S3ProfileName cannot be changed")
}
Copy link
Member

Choose a reason for hiding this comment

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

These are just strings, right? Why do we need deepEqual just string comparison is enough.

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 will check and change

Comment on lines +70 to +62
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *DRCluster) ValidateDelete() error {
drclusterlog.Info("validate delete", "name", r.Name)

return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

No need for this one, as we dont have a Delete validator.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I could remove it. just kept it like that in case we decide in the future to have delete validation, this anyway is not getting called and returning nil. I am not against removing it. just putting my thought.

return fmt.Errorf("S3ProfileName cannot be changed")
}

return r.ValidateDRCluster()
Copy link
Member

Choose a reason for hiding this comment

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

When we will hit this case? Isn't it already covered in Create, and the above two checks will avoid setting empty values?

Copy link
Member Author

Choose a reason for hiding this comment

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

it won't hit as now. but we are planning to add other validations like CIDR format checking in validateDRCluster. so just added it for future-proofing.

Comment on lines +78 to +71
if r.Spec.Region == "" {
return fmt.Errorf("Region cannot be empty")
}

if r.Spec.S3ProfileName == "" {
return fmt.Errorf("S3ProfileName cannot be empty")
}
Copy link
Member

Choose a reason for hiding this comment

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

As empty Region and S3ProfileName are not allowed during creation itself. Can we do this validation at the CR itself

Copy link
Member Author

Choose a reason for hiding this comment

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

validate tags are not added in drcluster api file. i will add them in the next PR and refactor this code.

@rakeshgm
Copy link
Member Author

Can you please double-check that some yaml changes are missing, like a certificate.yaml and update in CSV, etc?

so CSV file is getting generated/updated during the build with bundle dir. we are not adding it to the repo. @ShyamsundarR and I checked this before. so the files needed to get webhook up and running are all added.

@rakeshgm rakeshgm force-pushed the validate-using-webhooks branch 2 times, most recently from 7a76639 to e7541fb Compare October 31, 2022 09:23
@nirs
Copy link
Member

nirs commented Oct 31, 2022

Implemented validation using webhook. DRCluster CR objects Region and S3ProfileName are immutable.

What is the purpose of the webhook? how will use it? Is it used both on the hub and
on the managed clusters?

main.go Outdated
if err = (&ramendrv1alpha1.DRCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "DRCluster")
os.Exit(1)
}
Copy link
Member

Choose a reason for hiding this comment

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

Blank line here will be more consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

code block moved to different a section.

@rakeshgm rakeshgm force-pushed the validate-using-webhooks branch 3 times, most recently from 046ae84 to b74f6fc Compare November 1, 2022 10:48
@rakeshgm
Copy link
Member Author

rakeshgm commented Nov 1, 2022

Implemented validation using webhook. DRCluster CR objects Region and S3ProfileName are immutable.

What is the purpose of the webhook? how will use it? Is it used both on the hub and on the managed clusters?

A more detailed explanation of webhooks is here.
In ramen we are implementing webhooks for validating CRs and as of now and this PR is about validating DRCluster CR.
webhooks are configured as part of ramen deployment. They are used/called when the CR is created/updated and in our case, it will be DRCluster CR. This webhooks is currently used only on the hub cluster.

Please check this issuse for further information as to why we are implementing webhooks

@rakeshgm rakeshgm changed the title added webhook validation for DRcluster added webhook validation for DRCluster Nov 1, 2022
Signed-off-by: rakeshgm <rakeshgm@redhat.com>
@ShyamsundarR ShyamsundarR merged commit cafb6ae into RamenDR:main Nov 4, 2022
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants