-
Notifications
You must be signed in to change notification settings - Fork 374
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
add groupsnapshot related webhooks #825
Conversation
|
Welcome @Rakshith-R! |
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 Once the patch is verified, the new status will be reflected by the 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. |
9c8d94c
to
7f39877
Compare
/ok-to-test |
name: "snapshot-validation-service" | ||
path: "/volumegroupsnapshot" | ||
caBundle: ${CA_BUNDLE} | ||
admissionReviewVersions: ["v1"] |
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 this be v1alpha1
?
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.
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 { |
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.
Is this VolumeGroupSnapshotClassLister
or VolumeGroupSnapshotLister
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.
its VolumeGroupSnapshotClassLister
Result: &metav1.Status{}, | ||
} | ||
|
||
// Only Validate when a new snapClass is being set as a default. |
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.
nit: Only validate when a new group snapshot class is being set as a default.
pkg/validation-webhook/snapshot.go
Outdated
return &admitter{ | ||
lister: lister, | ||
snapshotLister: lister, |
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.
does this also need to initialise the group snapshot lister?
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.
does this also need to initialise the group snapshot lister?
refactored a bit, This struct is not shared with group snapshot now.
pkg/validation-webhook/snapshot.go
Outdated
@@ -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: |
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.
do we need these? there's only v1alpha1
right now
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.
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.
pkg/validation-webhook/snapshot.go
Outdated
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, |
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.
Need to remove the &
here
7f39877
to
2f27cb0
Compare
2f27cb0
to
f6ee988
Compare
🤔 re-requesting for reviews seems to have removed review-request of other reviewers. /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 |
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.
GroupSnapshotContentV1Apha1GVR -> GroupSnapshotClassV1Apha1GVR
VolumeGroupSnapshotContents > VolumeGroupSnapshotClasses
} | ||
|
||
// Only Validate when a new group snapshot class is being set as a default. | ||
if snapClass.Annotations[utils.IsDefaultSnapshotClassAnnotation] != "true" { |
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 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 { |
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.
snapClass -> groupSnapClass
oldSnapClass -> oldGroupSnapClass
return reviewResponse | ||
} | ||
|
||
for _, snapshotClass := range ret { |
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.
snapshotClass -> groupSnapshotClass
} | ||
|
||
for _, snapshotClass := range ret { | ||
if snapshotClass.Annotations[utils.IsDefaultSnapshotClassAnnotation] != "true" { |
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.
utils.IsDefaultGroupSnapshotClassAnnotation
if snapshotClass.Annotations[utils.IsDefaultSnapshotClassAnnotation] != "true" { | ||
continue | ||
} | ||
if snapshotClass.Driver == snapClass.Driver { |
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.
snapshotClass -> groupSnapshotClass
snapClass -> groupSnapClass
Can you add a release note? |
) | ||
|
||
var ( | ||
// GroupSnapshotV1Alpha1GVR is GroupVersionResource for v1alpha1 VolumeSnapshots |
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.
VolumeSnapshots -> VolumeGroupSnapshots
} | ||
|
||
if isUpdate { | ||
// if it is an UPDATE and oldSnapshot is valid, check immutable fields |
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.
oldSnapshot -> oldGroupSnapshot
return reviewResponse | ||
} | ||
|
||
func decideGroupSnapshotContentV1Alpha1(groupSnapcontent, oldSnapcontent *volumegroupsnapshotv1alpha1.VolumeGroupSnapshotContent, isUpdate bool) *v1.AdmissionResponse { |
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.
oldSnapcontent -> oldGroupSnapcontent
} | ||
|
||
if isUpdate { | ||
// if it is an UPDATE and oldSnapcontent is valid, check immutable fields |
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.
oldSnapcontent -> oldGroupSnapcontent
return reviewResponse | ||
} | ||
|
||
// If Old group snapshot class has this, then we can assume that it was validated if driver is the same. |
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.
nit: If the old ...
}}, | ||
}, | ||
{ | ||
name: "new snapshot for class with existing default classes", |
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.
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", |
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.
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) { |
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.
Can these tests be moved to pkg/validation-webhook/groupsnapshot_test.go
pkg/validation-webhook/webhook.go
Outdated
@@ -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" |
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.
nit: groupsnapshotlisters
pkg/validation-webhook/webhook.go
Outdated
@@ -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" |
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.
snapshotlisters
f6ee988
to
43728d2
Compare
43728d2
to
a3cb5a9
Compare
/lgtm |
[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 |
@Rakshith-R Can you take a look and see if you can make the groupsnapshot related webhook optional? |
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?:
/cc @xing-yang @nixpanic @RaunakShah