Don't generate empty structure.

VolumeInfo contains several sub-structures. They are filled for
different scenarios. Do not generate empty structure for the
not filled sub-structures.

Signed-off-by: Xun Jiang <jxun@vmware.com>
This commit is contained in:
Xun Jiang
2023-12-19 17:12:34 +08:00
parent 89cbdac0a3
commit 9be8eb0c6d
7 changed files with 132 additions and 75 deletions

View File

@@ -513,7 +513,7 @@ func retrieveNativeSnapshotLegacy(ctx context.Context, kbClient kbclient.Client,
for _, snap := range snapshots {
volumeInfo := volume.VolumeInfo{
PVName: snap.Spec.PersistentVolumeName,
NativeSnapshotInfo: volume.NativeSnapshotInfo{
NativeSnapshotInfo: &volume.NativeSnapshotInfo{
SnapshotHandle: snap.Status.ProviderSnapshotID,
VolumeType: snap.Spec.VolumeType,
VolumeAZ: snap.Spec.VolumeAZ,
@@ -567,7 +567,7 @@ func retrieveCSISnapshotLegacy(ctx context.Context, kbClient kbclient.Client, ba
for _, vsc := range vscList {
volInfo := volume.VolumeInfo{
PreserveLocalSnapshot: true,
CSISnapshotInfo: volume.CSISnapshotInfo{
CSISnapshotInfo: &volume.CSISnapshotInfo{
VSCName: vsc.Name,
Driver: vsc.Spec.Driver,
},
@@ -663,8 +663,8 @@ func describeLocalSnapshot(d *Describer, details bool, info *volume.VolumeInfo)
if details {
d.Printf("\t\t\tSnapshot:\n")
if !info.SnapshotDataMoved && info.OperationID != "" {
d.Printf("\t\t\t\tOperation ID: %s\n", info.OperationID)
if !info.SnapshotDataMoved && info.CSISnapshotInfo.OperationID != "" {
d.Printf("\t\t\t\tOperation ID: %s\n", info.CSISnapshotInfo.OperationID)
}
d.Printf("\t\t\t\tSnapshot Content Name: %s\n", info.CSISnapshotInfo.VSCName)
@@ -683,7 +683,7 @@ func describeDataMovement(d *Describer, details bool, info *volume.VolumeInfo) {
if details {
d.Printf("\t\t\tData Movement:\n")
d.Printf("\t\t\t\tOperation ID: %s\n", info.OperationID)
d.Printf("\t\t\t\tOperation ID: %s\n", info.SnapshotDataMovementInfo.OperationID)
dataMover := "velero"
if info.SnapshotDataMovementInfo.DataMover != "" {

View File

@@ -1,3 +1,19 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package output
import (
@@ -320,7 +336,7 @@ func TestDescribeNativeSnapshots(t *testing.T) {
{
BackupMethod: volume.NativeSnapshot,
PVName: "pv-1",
NativeSnapshotInfo: volume.NativeSnapshotInfo{
NativeSnapshotInfo: &volume.NativeSnapshotInfo{
SnapshotHandle: "snapshot-1",
VolumeType: "ebs",
VolumeAZ: "us-east-2",
@@ -338,7 +354,7 @@ func TestDescribeNativeSnapshots(t *testing.T) {
{
BackupMethod: volume.NativeSnapshot,
PVName: "pv-1",
NativeSnapshotInfo: volume.NativeSnapshotInfo{
NativeSnapshotInfo: &volume.NativeSnapshotInfo{
SnapshotHandle: "snapshot-1",
VolumeType: "ebs",
VolumeAZ: "us-east-2",
@@ -405,12 +421,12 @@ func TestCSISnapshots(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-1",
PreserveLocalSnapshot: true,
OperationID: "fake-operation-1",
CSISnapshotInfo: volume.CSISnapshotInfo{
CSISnapshotInfo: &volume.CSISnapshotInfo{
SnapshotHandle: "snapshot-1",
Size: 1024,
Driver: "fake-driver",
VSCName: "vsc-1",
OperationID: "fake-operation-1",
},
},
},
@@ -426,12 +442,12 @@ func TestCSISnapshots(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-2",
PreserveLocalSnapshot: true,
OperationID: "fake-operation-2",
CSISnapshotInfo: volume.CSISnapshotInfo{
CSISnapshotInfo: &volume.CSISnapshotInfo{
SnapshotHandle: "snapshot-2",
Size: 1024,
Driver: "fake-driver",
VSCName: "vsc-2",
OperationID: "fake-operation-2",
},
},
},
@@ -453,11 +469,11 @@ func TestCSISnapshots(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-3",
SnapshotDataMoved: true,
OperationID: "fake-operation-3",
SnapshotDataMovementInfo: volume.SnapshotDataMovementInfo{
SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{
DataMover: "velero",
UploaderType: "fake-uploader",
SnapshotHandle: "fake-repo-id-3",
OperationID: "fake-operation-3",
},
},
},
@@ -473,11 +489,11 @@ func TestCSISnapshots(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-4",
SnapshotDataMoved: true,
OperationID: "fake-operation-4",
SnapshotDataMovementInfo: volume.SnapshotDataMovementInfo{
SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{
DataMover: "velero",
UploaderType: "fake-uploader",
SnapshotHandle: "fake-repo-id-4",
OperationID: "fake-operation-4",
},
},
},
@@ -497,10 +513,10 @@ func TestCSISnapshots(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-5",
SnapshotDataMoved: true,
OperationID: "fake-operation-5",
SnapshotDataMovementInfo: volume.SnapshotDataMovementInfo{
SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{
UploaderType: "fake-uploader",
SnapshotHandle: "fake-repo-id-5",
OperationID: "fake-operation-5",
},
},
},

View File

@@ -425,7 +425,7 @@ func describeLocalSnapshotInSF(details bool, info *volume.VolumeInfo, snapshotDe
localSnapshot := make(map[string]interface{})
if !info.SnapshotDataMoved {
localSnapshot["operationID"] = info.OperationID
localSnapshot["operationID"] = info.CSISnapshotInfo.OperationID
}
localSnapshot["snapshotContentName"] = info.CSISnapshotInfo.VSCName
@@ -446,7 +446,7 @@ func describeDataMovementInSF(details bool, info *volume.VolumeInfo, snapshotDet
if details {
dataMovement := make(map[string]interface{})
dataMovement["operationID"] = info.OperationID
dataMovement["operationID"] = info.SnapshotDataMovementInfo.OperationID
dataMover := "velero"
if info.SnapshotDataMovementInfo.DataMover != "" {

View File

@@ -1,3 +1,19 @@
/*
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package output
import (
@@ -279,7 +295,7 @@ func TestDescribeNativeSnapshotsInSF(t *testing.T) {
{
BackupMethod: volume.NativeSnapshot,
PVName: "pv-1",
NativeSnapshotInfo: volume.NativeSnapshotInfo{
NativeSnapshotInfo: &volume.NativeSnapshotInfo{
SnapshotHandle: "snapshot-1",
VolumeType: "ebs",
VolumeAZ: "us-east-2",
@@ -299,7 +315,7 @@ func TestDescribeNativeSnapshotsInSF(t *testing.T) {
{
BackupMethod: volume.NativeSnapshot,
PVName: "pv-1",
NativeSnapshotInfo: volume.NativeSnapshotInfo{
NativeSnapshotInfo: &volume.NativeSnapshotInfo{
SnapshotHandle: "snapshot-1",
VolumeType: "ebs",
VolumeAZ: "us-east-2",
@@ -365,12 +381,12 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-1",
PreserveLocalSnapshot: true,
OperationID: "fake-operation-1",
CSISnapshotInfo: volume.CSISnapshotInfo{
CSISnapshotInfo: &volume.CSISnapshotInfo{
SnapshotHandle: "snapshot-1",
Size: 1024,
Driver: "fake-driver",
VSCName: "vsc-1",
OperationID: "fake-operation-1",
},
},
},
@@ -389,12 +405,12 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-2",
PreserveLocalSnapshot: true,
OperationID: "fake-operation-2",
CSISnapshotInfo: volume.CSISnapshotInfo{
CSISnapshotInfo: &volume.CSISnapshotInfo{
SnapshotHandle: "snapshot-2",
Size: 1024,
Driver: "fake-driver",
VSCName: "vsc-2",
OperationID: "fake-operation-2",
},
},
},
@@ -420,11 +436,11 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-3",
SnapshotDataMoved: true,
OperationID: "fake-operation-3",
SnapshotDataMovementInfo: volume.SnapshotDataMovementInfo{
SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{
DataMover: "velero",
UploaderType: "fake-uploader",
SnapshotHandle: "fake-repo-id-3",
OperationID: "fake-operation-3",
},
},
},
@@ -443,11 +459,11 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-4",
SnapshotDataMoved: true,
OperationID: "fake-operation-4",
SnapshotDataMovementInfo: volume.SnapshotDataMovementInfo{
SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{
DataMover: "velero",
UploaderType: "fake-uploader",
SnapshotHandle: "fake-repo-id-4",
OperationID: "fake-operation-4",
},
},
},
@@ -471,10 +487,10 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) {
BackupMethod: volume.CSISnapshot,
PVCName: "pvc-4",
SnapshotDataMoved: true,
OperationID: "fake-operation-4",
SnapshotDataMovementInfo: volume.SnapshotDataMovementInfo{
SnapshotDataMovementInfo: &volume.SnapshotDataMovementInfo{
UploaderType: "fake-uploader",
SnapshotHandle: "fake-repo-id-4",
OperationID: "fake-operation-4",
},
},
},