Add check for PV claimref nil
Signed-off-by: Anshul Ahuja <anshul.ahu@gmail.com>pull/8174/head
parent
2aecd45285
commit
8be8fc6671
|
@ -1952,8 +1952,8 @@ func hasCSIVolumeSnapshot(ctx *restoreContext, unstructuredPV *unstructured.Unst
|
|||
}
|
||||
|
||||
for _, vs := range ctx.csiVolumeSnapshots {
|
||||
// In some error cases, the VSs' source PVC could be nil. Skip them.
|
||||
if vs.Spec.Source.PersistentVolumeClaimName == nil {
|
||||
// In some error cases, the VSs' source PVC could be nil or PVs ClaimRef could be nil. Skip them.
|
||||
if vs.Spec.Source.PersistentVolumeClaimName == nil || pv.Spec.ClaimRef == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -3963,11 +3963,33 @@ func TestHasCSIVolumeSnapshot(t *testing.T) {
|
|||
"namespace": "default",
|
||||
"name": "test",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"claimRef": map[string]interface{}{
|
||||
"namespace": "velero",
|
||||
"name": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
vs: builder.ForVolumeSnapshot("velero", "test").Result(),
|
||||
expectedResult: false,
|
||||
},
|
||||
{
|
||||
name: "PVs claimref is nil, expect false.",
|
||||
obj: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": "PersistentVolume",
|
||||
"apiVersion": "v1",
|
||||
"metadata": map[string]interface{}{
|
||||
"namespace": "velero",
|
||||
"name": "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
vs: builder.ForVolumeSnapshot("velero", "test").SourcePVC("test").Result(),
|
||||
expectedResult: false,
|
||||
},
|
||||
|
||||
{
|
||||
name: "Find VS, expect true.",
|
||||
obj: &unstructured.Unstructured{
|
||||
|
|
Loading…
Reference in New Issue