Selector in VolumeGroupSnapshotSource API should be optional
This commit is contained in:
@@ -295,8 +295,8 @@ func (ctrl *csiSnapshotCommonController) syncGroupSnapshot(groupSnapshot *crdv1a
|
||||
}
|
||||
// Keep this check in the controller since the validation webhook may not have been deployed.
|
||||
klog.V(5).Infof("syncGroupSnapshot[%s]: validate group snapshot to make sure source has been correctly specified", utils.GroupSnapshotKey(groupSnapshot))
|
||||
if (&groupSnapshot.Spec.Source.Selector == nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName == nil) ||
|
||||
(&groupSnapshot.Spec.Source.Selector != nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName != nil) {
|
||||
if (groupSnapshot.Spec.Source.Selector == nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName == nil) ||
|
||||
(groupSnapshot.Spec.Source.Selector != nil && groupSnapshot.Spec.Source.VolumeGroupSnapshotContentName != nil) {
|
||||
err := fmt.Errorf("Exactly one of Selector and VolumeGroupSnapshotContentName should be specified")
|
||||
klog.Errorf("syncGroupSnapshot[%s]: validation error, %s", utils.GroupSnapshotKey(groupSnapshot), err.Error())
|
||||
ctrl.updateGroupSnapshotErrorStatusWithEvent(groupSnapshot, true, v1.EventTypeWarning, "GroupSnapshotValidationError", err.Error())
|
||||
|
@@ -90,7 +90,7 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
|
||||
volumeGroupSnapshot: &volumegroupsnapshotv1alpha1.VolumeGroupSnapshot{
|
||||
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
|
||||
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
|
||||
Selector: selector,
|
||||
Selector: &selector,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -172,13 +172,13 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
|
||||
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
|
||||
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
|
||||
VolumeGroupSnapshotContentName: &contentname,
|
||||
Selector: selector,
|
||||
Selector: &selector,
|
||||
},
|
||||
},
|
||||
},
|
||||
shouldAdmit: false,
|
||||
operation: v1.Update,
|
||||
msg: fmt.Sprintf("Spec.Source.Selector is immutable but was changed from %v to %v", selector, metav1.LabelSelector{}),
|
||||
msg: fmt.Sprintf("Spec.Source.Selector is immutable but was changed from %v to %v", &selector, "nil"),
|
||||
},
|
||||
{
|
||||
// will be handled by schema validation
|
||||
@@ -187,7 +187,7 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
|
||||
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
|
||||
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
|
||||
VolumeGroupSnapshotContentName: &contentname,
|
||||
Selector: selector,
|
||||
Selector: &selector,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -195,7 +195,7 @@ func TestAdmitVolumeGroupSnapshotV1Alpha1(t *testing.T) {
|
||||
Spec: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSpec{
|
||||
Source: volumegroupsnapshotv1alpha1.VolumeGroupSnapshotSource{
|
||||
VolumeGroupSnapshotContentName: &contentname,
|
||||
Selector: selector,
|
||||
Selector: &selector,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user