Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#8174 from anshulahuja98/pvnullfix
Browse files Browse the repository at this point in the history
Add check for PV claimref nil
  • Loading branch information
blackpiglet authored Sep 4, 2024
2 parents 8ae667e + 2d3521a commit c78fea3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,10 @@ func hasCSIVolumeSnapshot(ctx *restoreContext, unstructuredPV *unstructured.Unst
ctx.log.WithError(err).Warnf("Unable to convert PV from unstructured to structured")
return false
}
// ignoring static PV cases where there is no claimRef
if pv.Spec.ClaimRef == nil {
return false
}

for _, vs := range ctx.csiVolumeSnapshots {
// In some error cases, the VSs' source PVC could be nil. Skip them.
Expand Down
22 changes: 22 additions & 0 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c78fea3

Please sign in to comment.