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

add groupsnapshot related webhooks #825

Merged

Conversation

Rakshith-R
Copy link
Contributor

@Rakshith-R Rakshith-R commented Mar 29, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:

Adds support for webhooks for groupsnapshot CRs.

KEP - https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/3476-volume-group-snapshot

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Webhooks for VolumeGroupSnapshot, VolumeGroupSnapshotContent and VolumeGroupSnapshotClass.

/cc @xing-yang @nixpanic @RaunakShah

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 29, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 29, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Rakshith-R / name: Rakshith R (7f39877)

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 29, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @Rakshith-R!

It looks like this is your first PR to kubernetes-csi/external-snapshotter 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-csi/external-snapshotter has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Mar 29, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @Rakshith-R. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 29, 2023
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 29, 2023
@RaunakShah
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Mar 29, 2023
name: "snapshot-validation-service"
path: "/volumegroupsnapshot"
caBundle: ${CA_BUNDLE}
admissionReviewVersions: ["v1"]
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be v1alpha1?

Copy link
Contributor Author

@Rakshith-R Rakshith-R Mar 30, 2023

Choose a reason for hiding this comment

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

It is the AdmissionReview versions, not apiversions of CR.
We're using v1 version in webhook server.
I've tested it and it works fine.
admissionReviewVersions (string[]) AdmissionReviewVersions is an ordered list of preferred AdmissionReview versions the Webhook expects. API server will try to use first version in the list which it supports. If none of the versions specified in this list supported by API server, validation will fail for this object. If a persisted webhook configuration specifies allowed versions and does not include any versions known to the API Server, calls to the webhook will fail and be subject to the failure policy.

Admit(v1.AdmissionReview) *v1.AdmissionResponse
}

func NewGroupSnapshotAdmitter(lister groupSnapshotListers.VolumeGroupSnapshotClassLister) GroupSnapshotAdmitter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this VolumeGroupSnapshotClassLister or VolumeGroupSnapshotLister

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its VolumeGroupSnapshotClassLister

Result: &metav1.Status{},
}

// Only Validate when a new snapClass is being set as a default.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Only validate when a new group snapshot class is being set as a default.

return &admitter{
lister: lister,
snapshotLister: lister,
Copy link
Contributor

Choose a reason for hiding this comment

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

does this also need to initialise the group snapshot lister?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does this also need to initialise the group snapshot lister?

refactored a bit, This struct is not shared with group snapshot now.

@@ -107,9 +110,47 @@ func (a admitter) Admit(ar v1.AdmissionReview) *v1.AdmissionResponse {
klog.Error(err)
return toV1AdmissionResponse(err)
}
return decideSnapshotClassV1(snapClass, oldSnapClass, a.lister)
return decideSnapshotClassV1(snapClass, oldSnapClass, a.snapshotLister)
case GroupSnapshotV1Alpha1GVR:
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need these? there's only v1alpha1 right now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we need these? there's only v1alpha1 right now

I think its good to have it now, so we don't have to change it all over the place when
we have newer versions.

  • it is consistent with naming of snapshot v1 resources currently present.

default:
err := fmt.Errorf("expect resource to be %s, %s or %s", SnapshotV1GVR, SnapshotContentV1GVR, SnapshotClassV1GVR)
err := fmt.Errorf("expect resource to be %s, %s, %s, %s, %s, or %s, but found %v",
SnapshotV1GVR, SnapshotContentV1GVR, SnapshotClassV1GVR, &GroupSnapshotV1Alpha1GVR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to remove the & here

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 30, 2023
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 30, 2023
@Rakshith-R Rakshith-R requested review from RaunakShah and removed request for nixpanic and xing-yang March 30, 2023 06:02
@Rakshith-R
Copy link
Contributor Author

🤔 re-requesting for reviews seems to have removed review-request of other reviewers.
restoring it.

/cc @nixpanic @xing-yang

GroupSnapshotV1Alpha1GVR = metav1.GroupVersionResource{Group: volumegroupsnapshotv1alpha1.GroupName, Version: "v1alpha1", Resource: "volumegroupsnapshots"}
// GroupSnapshotContentV1Apha1GVR is GroupVersionResource for v1alpha1 VolumeGroupSnapshotContents
GroupSnapshotContentV1Apha1GVR = metav1.GroupVersionResource{Group: volumegroupsnapshotv1alpha1.GroupName, Version: "v1alpha1", Resource: "volumegroupsnapshotcontents"}
// GroupSnapshotContentV1Apha1GVR is GroupVersionResource for v1alpha1 VolumeGroupSnapshotContents
Copy link
Collaborator

Choose a reason for hiding this comment

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

GroupSnapshotContentV1Apha1GVR -> GroupSnapshotClassV1Apha1GVR
VolumeGroupSnapshotContents > VolumeGroupSnapshotClasses

}

// Only Validate when a new group snapshot class is being set as a default.
if snapClass.Annotations[utils.IsDefaultSnapshotClassAnnotation] != "true" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add a utils.IsDefaultGroupSnapshotClassAnnotation.
Add the following definition in utils.go:

IsDefaultGroupSnapshotClassAnnotation = "groupsnapshot.storage.kubernetes.io/is-default-class"

return reviewResponse
}

func decideGroupSnapshotClassV1Alpha1(snapClass, oldSnapClass *volumegroupsnapshotv1alpha1.VolumeGroupSnapshotClass, lister groupSnapshotListers.VolumeGroupSnapshotClassLister) *v1.AdmissionResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

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

snapClass -> groupSnapClass
oldSnapClass -> oldGroupSnapClass

return reviewResponse
}

for _, snapshotClass := range ret {
Copy link
Collaborator

Choose a reason for hiding this comment

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

snapshotClass -> groupSnapshotClass

}

for _, snapshotClass := range ret {
if snapshotClass.Annotations[utils.IsDefaultSnapshotClassAnnotation] != "true" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

utils.IsDefaultGroupSnapshotClassAnnotation

if snapshotClass.Annotations[utils.IsDefaultSnapshotClassAnnotation] != "true" {
continue
}
if snapshotClass.Driver == snapClass.Driver {
Copy link
Collaborator

Choose a reason for hiding this comment

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

snapshotClass -> groupSnapshotClass
snapClass -> groupSnapClass

@xing-yang
Copy link
Collaborator

Can you add a release note?

)

var (
// GroupSnapshotV1Alpha1GVR is GroupVersionResource for v1alpha1 VolumeSnapshots
Copy link
Contributor

Choose a reason for hiding this comment

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

VolumeSnapshots -> VolumeGroupSnapshots

}

if isUpdate {
// if it is an UPDATE and oldSnapshot is valid, check immutable fields
Copy link
Contributor

Choose a reason for hiding this comment

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

oldSnapshot -> oldGroupSnapshot

return reviewResponse
}

func decideGroupSnapshotContentV1Alpha1(groupSnapcontent, oldSnapcontent *volumegroupsnapshotv1alpha1.VolumeGroupSnapshotContent, isUpdate bool) *v1.AdmissionResponse {
Copy link
Contributor

Choose a reason for hiding this comment

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

oldSnapcontent -> oldGroupSnapcontent

}

if isUpdate {
// if it is an UPDATE and oldSnapcontent is valid, check immutable fields
Copy link
Contributor

Choose a reason for hiding this comment

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

oldSnapcontent -> oldGroupSnapcontent

return reviewResponse
}

// If Old group snapshot class has this, then we can assume that it was validated if driver is the same.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: If the old ...

}},
},
{
name: "new snapshot for class with existing default classes",
Copy link
Contributor

Choose a reason for hiding this comment

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

new snapshot for class with existing default classes -> new group snapshot for group snapshot class with existing default classes

}},
},
{
name: "update snapshot class to new driver with existing default classes",
Copy link
Contributor

Choose a reason for hiding this comment

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

update snapshot class to new driver with existing default classes -> update group snapshot class to new driver with existing default group snapshot classes

@@ -644,3 +663,614 @@ func TestAdmitVolumeSnapshotClassV1(t *testing.T) {
})
}
}

func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these tests be moved to pkg/validation-webhook/groupsnapshot_test.go

@@ -26,7 +26,8 @@ import (
"os"

clientset "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned"
storagelisters "github.com/kubernetes-csi/external-snapshotter/client/v6/listers/volumesnapshot/v1"
groupSnapshotListers "github.com/kubernetes-csi/external-snapshotter/client/v6/listers/volumegroupsnapshot/v1alpha1"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: groupsnapshotlisters

@@ -26,7 +26,8 @@ import (
"os"

clientset "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned"
storagelisters "github.com/kubernetes-csi/external-snapshotter/client/v6/listers/volumesnapshot/v1"
groupSnapshotListers "github.com/kubernetes-csi/external-snapshotter/client/v6/listers/volumegroupsnapshot/v1alpha1"
snapshotListers "github.com/kubernetes-csi/external-snapshotter/client/v6/listers/volumesnapshot/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

snapshotlisters

@Rakshith-R Rakshith-R force-pushed the add-group-snapshot-webhooks branch from f6ee988 to 43728d2 Compare May 8, 2023 10:17
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 8, 2023
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels May 8, 2023
@Rakshith-R Rakshith-R force-pushed the add-group-snapshot-webhooks branch from 43728d2 to a3cb5a9 Compare May 8, 2023 12:55
@xing-yang
Copy link
Collaborator

/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 May 8, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Rakshith-R, xing-yang

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 May 8, 2023
@k8s-ci-robot k8s-ci-robot merged commit a942b5b into kubernetes-csi:master May 8, 2023
@xing-yang
Copy link
Collaborator

@Rakshith-R Can you take a look and see if you can make the groupsnapshot related webhook optional?
#921

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants