Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.21.3

require (
github.com/blang/semver v3.5.1+incompatible
github.com/openshift/api v0.0.0-20240202140003-8b34b9854c7f
github.com/openshift/api v0.0.0-20240415215749-1ddd5804ab3a
github.com/openshift/build-machinery-go v0.0.0-20231128094528-1e9b1b0595c8
github.com/openshift/client-go v0.0.0-20240125160436-aa5df63097c4
github.com/openshift/library-go v0.0.0-20240130085015-2ad786549f07
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/openshift/api v0.0.0-20240202140003-8b34b9854c7f h1:yJ8mEpEW2aJo+97wguYL+ehCsJe/pbeKjFsbdMuuEJI=
github.com/openshift/api v0.0.0-20240202140003-8b34b9854c7f/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openshift/api v0.0.0-20240415215749-1ddd5804ab3a h1:MrdHtbj64cs4aqLEpZdbvR1OR2F0EFynHHB4XQZtQ/8=
github.com/openshift/api v0.0.0-20240415215749-1ddd5804ab3a/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
github.com/openshift/build-machinery-go v0.0.0-20231128094528-1e9b1b0595c8 h1:cu3YUMVGsKIyFyJGO3F6BZKGYQZpCKxAv9cBPgQAca8=
github.com/openshift/build-machinery-go v0.0.0-20231128094528-1e9b1b0595c8/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/client-go v0.0.0-20240125160436-aa5df63097c4 h1:Ct+/c9d5rjZudN+VBLxRJIQfPy1gJZier1P1KdpvCaM=
Expand Down
28 changes: 28 additions & 0 deletions pkg/operator/utils/config.go
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
}
75 changes: 75 additions & 0 deletions pkg/operator/utils/config_test.go
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\nExpected: %s", result, test.expectedResult)
}
})
}
}
7 changes: 7 additions & 0 deletions pkg/operator/vspherecontroller/vspherecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,13 @@ func (c *VSphereController) applyClusterCSIDriverChange(
csiConfig.Section("Labels").Key("topology-categories").SetValue(topologyCategoryString)
}

snapshotOptions := utils.GetSnapshotOptions(clusterCSIDriver)
if len(snapshotOptions) > 0 {
for k, v := range snapshotOptions {
csiConfig.Section("Snapshot").Key(k).SetValue(v)
}
}

// lets dump the ini file to a string
var finalConfigString strings.Builder
csiConfig.WriteTo(&finalConfigString)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading