Skip to content

Commit

Permalink
Don't use params field, if they are nil, while cloning volumesnapshot…
Browse files Browse the repository at this point in the history
…class (#1145)

* Don't use params field while cloning volumesnapshotclass

While cloning `VolumeSnapshotClass`, as part of #1128
we started passing params. But we should not pass params if the values
is `nil`, because in that case creation `VolumeSnapshotClass` fails with
`nil` not allowed.

* Refactor, address review comments

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
viveksinghggits and mergify[bot] authored Nov 19, 2021
1 parent f0d642c commit 5fab1bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
25 changes: 15 additions & 10 deletions pkg/kube/snapshot/snapshot_alpha.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,22 @@ func UnstructuredVolumeSnapshotContentAlpha(name, snapshotName, snapshotNs, dele
}

func UnstructuredVolumeSnapshotClassAlpha(name, driver, deletionPolicy string, params map[string]string) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": fmt.Sprintf("%s/%s", v1alpha1.GroupName, v1alpha1.Version),
"kind": VolSnapClassKind,
"metadata": map[string]interface{}{
"name": name,
},
VolSnapClassAlphaDriverKey: driver,
"deletionPolicy": deletionPolicy,
"parameters": Mss2msi(params),
obj := map[string]interface{}{
"apiVersion": fmt.Sprintf("%s/%s", v1alpha1.GroupName, v1alpha1.Version),
"kind": VolSnapClassKind,
"metadata": map[string]interface{}{
"name": name,
},
VolSnapClassAlphaDriverKey: driver,
"deletionPolicy": deletionPolicy,
}

if params != nil {
obj["parameters"] = Mss2msi(params)
}

return &unstructured.Unstructured{
Object: obj,
}
}

Expand Down
24 changes: 14 additions & 10 deletions pkg/kube/snapshot/snapshot_beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,21 @@ func UnstructuredVolumeSnapshotContent(gvr schema.GroupVersionResource, name, sn
}

func UnstructuredVolumeSnapshotClass(gvr schema.GroupVersionResource, name, driver, deletionPolicy string, params map[string]string) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": fmt.Sprintf("%s/%s", gvr.Group, gvr.Version),
"kind": VolSnapClassKind,
"metadata": map[string]interface{}{
"name": name,
},
VolSnapClassBetaDriverKey: driver,
"deletionPolicy": deletionPolicy,
"parameters": Mss2msi(params),
obj := map[string]interface{}{
"apiVersion": fmt.Sprintf("%s/%s", gvr.Group, gvr.Version),
"kind": VolSnapClassKind,
"metadata": map[string]interface{}{
"name": name,
},
VolSnapClassBetaDriverKey: driver,
"deletionPolicy": deletionPolicy,
}
if params != nil {
obj["parameters"] = Mss2msi(params)
}

return &unstructured.Unstructured{
Object: obj,
}
}

Expand Down

0 comments on commit 5fab1bb

Please sign in to comment.