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

replication: add webhook for volumereplicationclass #257

Merged
merged 10 commits into from
Nov 15, 2022

Conversation

Madhu-1
Copy link
Member

@Madhu-1 Madhu-1 commented Oct 20, 2022

Add webhook for VolumeReplicationClass to validate update CR.

Signed-off-by: Madhu Rajanna [email protected]

# kubebuilder latest release has a label with name kuberentes
# TODO: remove this in next kubebuilder update as this is fixed
# in kubebuilder master
ignore_words_list: kuberentes
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a link to the kubebuilder issue in this comment, that makes it easier to verify what next release contains the fix

Copy link
Member Author

Choose a reason for hiding this comment

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

there was no issue created for it, it was fixed in a PR kubernetes-sigs/kubebuilder#2964 here

kind: Issuer
metadata:
labels:
app.kuberentes.io/name: issuer
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add a comment here that it is spelled correctly, and point to the codespell config

Copy link
Member Author

Choose a reason for hiding this comment

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

this is auto generated file adding commit might get overriden when its rebuild

@@ -0,0 +1,20 @@

apiVersion: v1
Copy link
Collaborator

Choose a reason for hiding this comment

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

starting with an empty line? Maybe include the yaml-start-of-document --- instead (and in other yaml files)

Copy link
Member Author

Choose a reason for hiding this comment

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

again this is auto generated file

@@ -57,4 +57,7 @@ resources:
kind: VolumeReplicationClass
Copy link
Collaborator

Choose a reason for hiding this comment

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

did you use a kubebuilder command to generate the initial files? Please include the command(s) in the commit message so that others can reproduce it, or follow the steps to add other webhooks.

)

// log is for logging in this package.
var volumereplicationclasslog = logf.Log.WithName("volumereplicationclass-resource")
Copy link
Collaborator

Choose a reason for hiding this comment

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

vrcLog would do too. But it isn't used much, so the long name might not be too inconvenient.

// log is for logging in this package.
var volumereplicationclasslog = logf.Log.WithName("volumereplicationclass-resource")

func (r *VolumeReplicationClass) SetupWebhookWithManager(mgr ctrl.Manager) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why r for VolumeReplicationClass? I guess it's used elsewhere and can not easily be modified without changing other files. r is not a self-explaining name when using it inside functions.

Copy link
Member Author

Choose a reason for hiding this comment

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

this is also auto generated not manually added, i think it need changes in many places

}

// ValidateUpdate implements webhook.Validator. Validates the updated
// VolumeReplicationClass and does not allow changes to existing spec object.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it does not allow any changes to the .Spec part, why not use reflect.DeepEqual for that? No need to compare .Provisioner and .Parameters separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

not comparing spec because for now we have only two fields in spec but later we might add new fields which are suppose to be editable also that the reason to compare it explicitly

}).Should(Succeed())

}, 60)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Where are the tests? I expected to find a By() or similar. At least one positive and one negative test would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Again this is an auto-generated file, current we dont have any functional suite tests. We have already 2 suite files in the repo. https://github.com/csi-addons/kubernetes-csi-addons/blob/main/controllers/csiaddons/suite_test.go https://github.com/csi-addons/kubernetes-csi-addons/blob/main/controllers/replication.storage/suite_test.go. i need to see how to have a single suite to run with the mock controller. I will take it up in the next PR to see how to make it possible.

Adding scalefolding for webhooks for
volumereplicationclass. below is the command
to generate it.

```
$operator-sdk create webhook --group
replication.storage --version v1alpha1
--kind VolumeReplicationClass
--programmatic-validation
```

Signed-off-by: Madhu Rajanna <[email protected]>
Added go logic to block updating the
provisioner name or the parameters in
the existing VolumeReplicationClass

Signed-off-by: Madhu Rajanna <[email protected]>
This commit contains the yaml changes to
enable the webhook in csv

Signed-off-by: Madhu Rajanna <[email protected]>
exclude kuberentes from codespell as there
is a typo in label name in latest kubebuilder
release and it is fixed in latest master and
should be available in next release.

Signed-off-by: Madhu Rajanna <[email protected]>
Provided an option to make webhook
configurable in the manager deployment
. The webhook will be enabled by default
when operator is deployed as OLM bundle
as OLM takes care of ceritifcates and
its disabled in standalone deployment for
now as we have dependency with certificates
and cert manager as it needs to be setup
separately.

Signed-off-by: Madhu Rajanna <[email protected]>
`$` is not required if we dont have
any output from the command in the
markdown.

Signed-off-by: Madhu Rajanna <[email protected]>
add namePrefix and namespace for webhook
and the certificates to match with other
resources.

Signed-off-by: Madhu Rajanna <[email protected]>
A new all-in-one yaml files will be generated
and it will include all the required RBAC, CRD's
, Webhooks, Certificates in a single file.

Signed-off-by: Madhu Rajanna <[email protected]>
@Madhu-1 Madhu-1 removed the DNM Do Not Merge label Nov 10, 2022
added a new section for deployment of
cert-manager and the controller with webhook
enabled.

Signed-off-by: Madhu Rajanna <[email protected]>
@Madhu-1
Copy link
Member Author

Madhu-1 commented Nov 10, 2022

I have tested both yaml-based and bundle-based deployments both work as expected.

@Madhu-1 Madhu-1 force-pushed the webhook branch 8 times, most recently from 24d9b0e to 7d30db3 Compare November 10, 2022 17:58
use local built image from CI testing.

Signed-off-by: Madhu Rajanna <[email protected]>
Copy link
Member

@Rakshith-R Rakshith-R left a comment

Choose a reason for hiding this comment

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

LGTM,
Thanks!

Comment on lines +46 to +48
func (v *VolumeReplicationClass) ValidateCreate() error {
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.

The pr description mentions webhooks for create too
but here it is empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

update the PR description, Create is not required as it should/can be handled as part of CRD schema validation.

Copy link
Member

Choose a reason for hiding this comment

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

ok thanks !

Copy link
Collaborator

@nixpanic nixpanic left a comment

Choose a reason for hiding this comment

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

I don't know much about WebHooks, but this looks reasonable to me.

@mergify mergify bot merged commit e819549 into csi-addons:main Nov 15, 2022
Nikhil-Ladha pushed a commit to Nikhil-Ladha/kubernetes-csi-addons that referenced this pull request Feb 19, 2025
Syncing latest changes from upstream main for kubernetes-csi-addons
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.

3 participants