Skip to content

Commit cae07b8

Browse files
OADP-823: Address oadp-1.0.z with ocp 4.11 csi compatibility issue (#848)
* address oadp-1.0.z with ocp 4.11 csi compatibility issue * remove version info logs * remove redundant plugin loop * update validation error message
1 parent 41d2459 commit cae07b8

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

controllers/validator.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package controllers
33
import (
44
"errors"
55
"fmt"
6+
"k8s.io/apimachinery/pkg/version"
7+
"k8s.io/client-go/kubernetes"
8+
"sigs.k8s.io/controller-runtime/pkg/client/config"
69

710
"github.com/go-logr/logr"
811
oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
@@ -85,6 +88,19 @@ func (r *DPAReconciler) ValidateVeleroPlugins(log logr.Logger) (bool, error) {
8588
var defaultPlugin oadpv1alpha1.DefaultPlugin
8689
for _, plugin := range dpa.Spec.Configuration.Velero.DefaultPlugins {
8790

91+
// check csi compatibility with cluster version
92+
// velero version <1.9 expects API group snapshot.storage.k8s.io/v1beta1, while OCP 4.11 (k8s 1.24) has only snapshot.storage.k8s.io/v1
93+
if plugin == oadpv1alpha1.DefaultPluginCSI {
94+
clusterVersion, err := getClusterVersion()
95+
if err != nil {
96+
return false, err
97+
}
98+
99+
if clusterVersion.Major == "1" && clusterVersion.Minor >= "24" {
100+
return false, errors.New("csi plugin on OADP 1.0 (velero <1.9) requires API snapshot.storage.k8s.io/v1beta1. On OCP 4.11+ (k8s 1.24+), to use CSI, upgrade to OADP 1.1+")
101+
}
102+
}
103+
88104
pluginSpecificMap, ok := credentials.PluginSpecificFields[plugin]
89105
pluginNeedsCheck, foundInBSLorVSL := providerNeedsDefaultCreds[string(plugin)]
90106

@@ -103,3 +119,12 @@ func (r *DPAReconciler) ValidateVeleroPlugins(log logr.Logger) (bool, error) {
103119
}
104120
return true, nil
105121
}
122+
123+
func getClusterVersion() (*version.Info, error) {
124+
kubeConf := config.GetConfigOrDie()
125+
clientset, err := kubernetes.NewForConfig(kubeConf)
126+
if err != nil {
127+
return nil, err
128+
}
129+
return clientset.Discovery().ServerVersion()
130+
}

0 commit comments

Comments
 (0)