forked from kubernetes-csi/external-snapshotter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link PVCs and PVs in VolumeGroupSnapshot and VolumeGroupSnapshotContent
This use the update API to set `persistentVolumeClaimRef` in `VolumeGroupSnapshot` and `persistentVolumeName` in `VolumeGroupSnapshotContent` to the corresponding objects. This makes restoring volumes from a VolumeGroupSnapshot easier. Related: kubernetes-csi#969
- Loading branch information
1 parent
51385b7
commit 71ea1e2
Showing
5 changed files
with
289 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// SnapshotInfo contains basic information about a volume being snapshotted | ||
type SnapshotInfo struct { | ||
VolumeHandle string `json:"volumeHandle"` | ||
PVName string `json:"pvName"` | ||
PVCName string `json:"pvcName"` | ||
} | ||
|
||
// SnapshotInfoList contains basic information about a set of volumes being snapshotted | ||
type SnapshotInfoList []SnapshotInfo | ||
|
||
// ToJSON serizalizes to JSON a set of SnapshotInfo | ||
func (data SnapshotInfoList) ToJSON() (string, error) { | ||
result, err := json.Marshal(data) | ||
if err != nil { | ||
err = fmt.Errorf("while serializing SnapshotInfoList: %w", err) | ||
} | ||
return string(result), err | ||
} | ||
|
||
// SnapshotInfoFromJSON deserializes from JSON a set of snapshot info | ||
func SnapshotInfoFromJSON(content string) (SnapshotInfoList, error) { | ||
var result SnapshotInfoList | ||
|
||
err := json.Unmarshal([]byte(content), &result) | ||
if err != nil { | ||
err = fmt.Errorf("while de-serializing SnapshotInfoList: %w", err) | ||
} | ||
|
||
return result, err | ||
} | ||
|
||
// GetFromVolumeHandle gets the entry from the list corresponding to a certain | ||
// volume handle. Returns an empty SnapshotInfo if there is no such entry | ||
func (data SnapshotInfoList) GetFromVolumeHandle(volumeHandle string) SnapshotInfo { | ||
for i := range data { | ||
if data[i].VolumeHandle == volumeHandle { | ||
return data[i] | ||
} | ||
} | ||
|
||
return SnapshotInfo{} | ||
} | ||
|
||
// GetFromPVName gets the entry from the list corresponding to a certain | ||
// PV name. Returns an empty SnapshotInfo if there is no such entry | ||
func (data SnapshotInfoList) GetFromPVName(pvName string) SnapshotInfo { | ||
for i := range data { | ||
if data[i].PVName == pvName { | ||
return data[i] | ||
} | ||
} | ||
|
||
return SnapshotInfo{} | ||
} |
Oops, something went wrong.