Skip to content

Commit 4e03bd3

Browse files
authored
Merge pull request #995 from nixpanic/VolumeGroupSnapshot/optional-selector
Selector in VolumeGroupSnapshotSource API should be optional
2 parents fc49f32 + 9e58d4c commit 4e03bd3

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

client/apis/volumegroupsnapshot/v1alpha1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ type VolumeGroupSnapshotSource struct {
5252
// is created, the existing group snapshots won't be modified.
5353
// Once a VolumeGroupSnapshotContent is created and the sidecar starts to process
5454
// it, the volume list will not change with retries.
55-
// Required.
56-
Selector metav1.LabelSelector `json:"selector" protobuf:"bytes,1,opt,name=selector"`
55+
// +optional
56+
Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,1,opt,name=selector"`
5757

5858
// VolumeGroupSnapshotContentName specifies the name of a pre-existing VolumeGroupSnapshotContent
5959
// object representing an existing volume group snapshot.

client/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/config/crd/groupsnapshot.storage.k8s.io_volumegroupsnapshots.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/814"
6+
api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/995"
77
controller-gen.kubebuilder.io/version: v0.12.0
88
creationTimestamp: null
99
name: volumegroupsnapshots.groupsnapshot.storage.k8s.io
@@ -78,7 +78,6 @@ spec:
7878
is created, the existing group snapshots won't be modified.
7979
Once a VolumeGroupSnapshotContent is created and the sidecar
8080
starts to process it, the volume list will not change with retries.
81-
Required.
8281
properties:
8382
matchExpressions:
8483
description: matchExpressions is a list of label selector
@@ -129,8 +128,6 @@ spec:
129128
if the volume group snapshot already exists and only needs a
130129
representation in Kubernetes. This field is immutable.
131130
type: string
132-
required:
133-
- selector
134131
type: object
135132
volumeGroupSnapshotClassName:
136133
description: VolumeGroupSnapshotClassName is the name of the VolumeGroupSnapshotClass

pkg/common-controller/groupsnapshot_controller_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
295295
}
296296
// Keep this check in the controller since the validation webhook may not have been deployed.
297297
klog.V(5).Infof("syncGroupSnapshot[%s]: validate group snapshot to make sure source has been correctly specified", utils.GroupSnapshotKey(groupSnapshot))
298-
if (&groupSnapshot.Spec.Source.Selector == nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName == nil) ||
299-
(&groupSnapshot.Spec.Source.Selector != nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName != nil) {
298+
if (groupSnapshot.Spec.Source.Selector == nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName == nil) ||
299+
(groupSnapshot.Spec.Source.Selector != nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName != nil) {
300300
err := fmt.Errorf("Exactly one of Selector and VolumeGroupSnapshotContentName should be specified")
301301
klog.Errorf("syncGroupSnapshot[%s]: validation error, %s", utils.GroupSnapshotKey(groupSnapshot), err.Error())
302302
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotValidationError", err.Error())

pkg/validation-webhook/groupsnapshot_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
9090
volumeGroupSnapshot: &volumegroupsnapshotv1alpha1.VolumeGroupSnapshot{
9191
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
9292
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
93-
Selector: selector,
93+
Selector: &selector,
9494
},
9595
},
9696
},
@@ -172,13 +172,13 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
172172
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
173173
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
174174
VolumeGroupSnapshotContentName: &contentname,
175-
Selector: selector,
175+
Selector: &selector,
176176
},
177177
},
178178
},
179179
shouldAdmit: false,
180180
operation: v1.Update,
181-
msg: fmt.Sprintf("Spec.Source.Selector is immutable but was changed from %v to %v", selector, metav1.LabelSelector{}),
181+
msg: fmt.Sprintf("Spec.Source.Selector is immutable but was changed from %v to %v", &selector, "nil"),
182182
},
183183
{
184184
// will be handled by schema validation
@@ -187,15 +187,15 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
187187
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
188188
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
189189
VolumeGroupSnapshotContentName: &contentname,
190-
Selector: selector,
190+
Selector: &selector,
191191
},
192192
},
193193
},
194194
oldVolumeGroupSnapshot: &volumegroupsnapshotv1alpha1.VolumeGroupSnapshot{
195195
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
196196
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
197197
VolumeGroupSnapshotContentName: &contentname,
198-
Selector: selector,
198+
Selector: &selector,
199199
},
200200
},
201201
},

vendor/github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumegroupsnapshot/v1alpha1/types.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumegroupsnapshot/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)