-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use snapshot options from ClusterCSIDriver
- Loading branch information
1 parent
ccbd7a4
commit ebbfaf2
Showing
3 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package utils | ||
|
||
import ( | ||
opv1 "github.com/openshift/api/operator/v1" | ||
"strconv" | ||
) | ||
|
||
func addOption(options map[string]string, name string, intValue *uint32) { | ||
if intValue == nil { | ||
return | ||
} | ||
options[name] = strconv.FormatUint(uint64(*intValue), 10) | ||
} | ||
|
||
func GetSnapshotOptions(clusterCSIDriver *opv1.ClusterCSIDriver) map[string]string { | ||
snapshotOptions := map[string]string{} | ||
if clusterCSIDriver == nil || clusterCSIDriver.Spec.DriverConfig.VSphere == nil { | ||
return nil | ||
} | ||
|
||
vSphereConfig := clusterCSIDriver.Spec.DriverConfig.VSphere | ||
|
||
addOption(snapshotOptions, "global-max-snapshots-per-block-volume", vSphereConfig.GlobalMaxSnapshotsPerBlockVolume) | ||
addOption(snapshotOptions, "granular-max-snapshots-per-block-volume-vsan", vSphereConfig.GranularMaxSnapshotsPerBlockVolumeInVSAN) | ||
addOption(snapshotOptions, "granular-max-snapshots-per-block-volume-vvol", vSphereConfig.GranularMaxSnapshotsPerBlockVolumeInVVOL) | ||
|
||
return snapshotOptions | ||
} |
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,75 @@ | ||
package utils | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
opv1 "github.com/openshift/api/operator/v1" | ||
) | ||
|
||
func TestSnapshotConfiguration(t *testing.T) { | ||
globalMaxSnapshotsPerBlockVolume := uint32(5) | ||
granularMaxSnapshotsPerBlockVolumeInVSAN := uint32(10) | ||
granularMaxSnapshotsPerBlockVolumeInVVOL := uint32(15) | ||
|
||
emptyClusterCSIDriver := &opv1.ClusterCSIDriver{ | ||
Spec: opv1.ClusterCSIDriverSpec{ | ||
DriverConfig: opv1.CSIDriverConfigSpec{ | ||
VSphere: &opv1.VSphereCSIDriverConfigSpec{}, | ||
}, | ||
}} | ||
globalMaxSnapshotClusterCSIDriver := &opv1.ClusterCSIDriver{ | ||
Spec: opv1.ClusterCSIDriverSpec{ | ||
DriverConfig: opv1.CSIDriverConfigSpec{ | ||
VSphere: &opv1.VSphereCSIDriverConfigSpec{ | ||
GlobalMaxSnapshotsPerBlockVolume: &globalMaxSnapshotsPerBlockVolume, | ||
}, | ||
}, | ||
}} | ||
allSnapshotOptionsClusterCSIDriver := &opv1.ClusterCSIDriver{ | ||
Spec: opv1.ClusterCSIDriverSpec{ | ||
DriverConfig: opv1.CSIDriverConfigSpec{ | ||
VSphere: &opv1.VSphereCSIDriverConfigSpec{ | ||
GlobalMaxSnapshotsPerBlockVolume: &globalMaxSnapshotsPerBlockVolume, | ||
GranularMaxSnapshotsPerBlockVolumeInVSAN: &granularMaxSnapshotsPerBlockVolumeInVSAN, | ||
GranularMaxSnapshotsPerBlockVolumeInVVOL: &granularMaxSnapshotsPerBlockVolumeInVVOL, | ||
}, | ||
}, | ||
}} | ||
|
||
tests := []struct { | ||
name string | ||
clusterCSIDriver *opv1.ClusterCSIDriver | ||
expectedResult map[string]string | ||
}{ | ||
{ | ||
name: "no configuration", | ||
clusterCSIDriver: emptyClusterCSIDriver, | ||
expectedResult: map[string]string{}, | ||
}, | ||
{ | ||
name: "only global max snapshot limit configured", | ||
clusterCSIDriver: globalMaxSnapshotClusterCSIDriver, | ||
expectedResult: map[string]string{ | ||
"global-max-snapshots-per-block-volume": "5", | ||
}, | ||
}, | ||
{ | ||
name: "all snapshot options configured", | ||
clusterCSIDriver: allSnapshotOptionsClusterCSIDriver, | ||
expectedResult: map[string]string{ | ||
"global-max-snapshots-per-block-volume": "5", | ||
"granular-max-snapshots-per-block-volume-vsan": "10", | ||
"granular-max-snapshots-per-block-volume-vvol": "15", | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result := GetSnapshotOptions(test.clusterCSIDriver) | ||
if !reflect.DeepEqual(result, test.expectedResult) { | ||
t.Errorf("Unexpected result: %s\nExpectec: %s", result, test.expectedResult) | ||
} | ||
}) | ||
} | ||
} |
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