From fd12192dd48001114a0dfd162dd44ff043fc340c Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 9 Dec 2024 17:20:51 +0100 Subject: [PATCH] csi: use new flag to enable VGS feature In the Alpha Version of the VolumeGroupSnapshot Feature the flag to enable the feature was `--enable-volume-group-snapshots=true` and in the beta API the feature is diasbled by default to enable it we need to set `--feature-gate=CSIVolumeGroupSnapshot=true` There is a change in the flag between the API version This PR add a code where we choose the required flag based on the API version. Signed-off-by: Madhu Rajanna (cherry picked from commit 279e5f7cac0f3e1eb598ff2c5cb0df12eba0195e) --- pkg/operator/ceph/csi/csi.go | 28 ++++++++++++++++--- pkg/operator/ceph/csi/operator_driver.go | 2 +- pkg/operator/ceph/csi/spec.go | 2 +- .../csi-cephfsplugin-provisioner-dep.yaml | 2 +- .../rbd/csi-rbdplugin-provisioner-dep.yaml | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/pkg/operator/ceph/csi/csi.go b/pkg/operator/ceph/csi/csi.go index b1ab03618..1e64c2b09 100644 --- a/pkg/operator/ceph/csi/csi.go +++ b/pkg/operator/ceph/csi/csi.go @@ -303,15 +303,35 @@ func (r *ReconcileCSI) setParams() error { CSIParam.DriverNamePrefix = k8sutil.GetValue(r.opConfig.Parameters, "CSI_DRIVER_NAME_PREFIX", r.opConfig.OperatorNamespace) - _, err = r.context.ApiExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), "volumegroupsnapshotclasses.groupsnapshot.storage.k8s.io", metav1.GetOptions{}) + crd, err := r.context.ApiExtensionsClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), "volumegroupsnapshotclasses.groupsnapshot.storage.k8s.io", metav1.GetOptions{}) if err != nil && !kerrors.IsNotFound(err) { return errors.Wrapf(err, "failed to get volumegroupsnapshotclasses.groupsnapshot.storage.k8s.io CRD") } CSIParam.VolumeGroupSnapshotSupported = (err == nil) - CSIParam.EnableVolumeGroupSnapshot = true - if strings.EqualFold(k8sutil.GetValue(r.opConfig.Parameters, "CSI_ENABLE_VOLUME_GROUP_SNAPSHOT", "true"), "false") { - CSIParam.EnableVolumeGroupSnapshot = false + if err == nil && len(crd.Spec.Versions) > 0 { + ver := crd.Spec.Versions[0] + // Determine if VolumeGroupSnapshot feature should be disabled + disableVGS := strings.EqualFold(k8sutil.GetValue(r.opConfig.Parameters, "CSI_ENABLE_VOLUME_GROUP_SNAPSHOT", "true"), "false") + const ( + enableVolumeGroupSnapshotFlag = "--enable-volume-group-snapshots=" + featureGateFlag = "--feature-gate=CSIVolumeGroupSnapshot=" + ) + // Check for "v1alpha1" version to determine the appropriate CLI flag + // In the "v1alpha1" version, we use the '--enable-volume-group-snapshots' flag. + // In later versions (e.g., "v1beta1"), we use the '--feature-gate=CSIVolumeGroupSnapshot' flag. + if ver.Name == "v1alpha1" { + CSIParam.VolumeGroupSnapshotCLIFlag = enableVolumeGroupSnapshotFlag + "true" + } else { + CSIParam.VolumeGroupSnapshotCLIFlag = featureGateFlag + "true" + } + if disableVGS { + if ver.Name == "v1alpha1" { + CSIParam.VolumeGroupSnapshotCLIFlag = enableVolumeGroupSnapshotFlag + "false" + } else { + CSIParam.VolumeGroupSnapshotCLIFlag = featureGateFlag + "false" + } + } } kubeApiBurst := k8sutil.GetValue(r.opConfig.Parameters, "CSI_KUBE_API_BURST", "") diff --git a/pkg/operator/ceph/csi/operator_driver.go b/pkg/operator/ceph/csi/operator_driver.go index 165107da3..0a3fa8107 100644 --- a/pkg/operator/ceph/csi/operator_driver.go +++ b/pkg/operator/ceph/csi/operator_driver.go @@ -139,7 +139,7 @@ func (r *ReconcileCSI) createOrUpdateCephFSDriverResource(cluster cephv1.CephClu } cephFsDriver.Spec.SnapshotPolicy = csiopv1a1.NoneSnapshotPolicy - if CSIParam.EnableVolumeGroupSnapshot { + if CSIParam.VolumeGroupSnapshotCLIFlag != "" { cephFsDriver.Spec.SnapshotPolicy = csiopv1a1.VolumeGroupSnapshotPolicy } diff --git a/pkg/operator/ceph/csi/spec.go b/pkg/operator/ceph/csi/spec.go index 761494b90..1e645ba13 100644 --- a/pkg/operator/ceph/csi/spec.go +++ b/pkg/operator/ceph/csi/spec.go @@ -77,8 +77,8 @@ type Param struct { CephFSAttachRequired bool RBDAttachRequired bool NFSAttachRequired bool + VolumeGroupSnapshotCLIFlag string VolumeGroupSnapshotSupported bool - EnableVolumeGroupSnapshot bool LogLevel uint8 SidecarLogLevel uint8 CephFSLivenessMetricsPort uint16 diff --git a/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml b/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml index 35fa8d0c1..5ed29f704 100644 --- a/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml +++ b/pkg/operator/ceph/csi/template/cephfs/csi-cephfsplugin-provisioner-dep.yaml @@ -63,7 +63,7 @@ spec: - "--leader-election-retry-period={{ .LeaderElectionRetryPeriod }}" - "--extra-create-metadata=true" {{ if .VolumeGroupSnapshotSupported }} - - "--enable-volume-group-snapshots={{ .EnableVolumeGroupSnapshot }}" + - "{{ .VolumeGroupSnapshotCLIFlag }}" {{ end }} {{ if .KubeApiBurst }} - "--kube-api-burst={{ .KubeApiBurst }}" diff --git a/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml index 23a019bc0..135338322 100644 --- a/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml +++ b/pkg/operator/ceph/csi/template/rbd/csi-rbdplugin-provisioner-dep.yaml @@ -120,7 +120,7 @@ spec: - "--leader-election-retry-period={{ .LeaderElectionRetryPeriod }}" - "--extra-create-metadata=true" {{ if .VolumeGroupSnapshotSupported }} - - "--enable-volume-group-snapshots={{ .EnableVolumeGroupSnapshot }}" + - "{{ .VolumeGroupSnapshotCLIFlag }}" {{ end }} {{ if .KubeApiBurst }} - "--kube-api-burst={{ .KubeApiBurst }}"