From fba6a2d0c3755cb7be0be650c6cb47df73e2ed6e Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 30 Mar 2021 11:03:01 +0530 Subject: [PATCH] deploy: add csidriver object for cephfs and rbd csidriver object can be created on the kubernetes for below reason. If a CSI driver creates a CSIDriver object, Kubernetes users can easily discover the CSI Drivers installed on their cluster (simply by issuing kubectl get CSIDriver) Ref: https://kubernetes-csi.github.io/docs/csi-driver-object.html#what-is-the-csidriver-object attachRequired is always required to be set to true to avoid issue on RWO PVC. more details about it at https://github.com/rook/rook/pull/4332 Signed-off-by: Madhu Rajanna --- .../ceph-csi-cephfs/templates/csidriver-crd.yaml | 11 ++++++----- charts/ceph-csi-rbd/templates/csidriver-crd.yaml | 11 ++++++----- deploy/cephfs/kubernetes/csidriver.yaml | 10 ++++++++++ deploy/rbd/kubernetes/csidriver.yaml | 10 ++++++++++ e2e/cephfs.go | 15 +++++++++++++++ e2e/rbd.go | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 deploy/cephfs/kubernetes/csidriver.yaml create mode 100644 deploy/rbd/kubernetes/csidriver.yaml diff --git a/charts/ceph-csi-cephfs/templates/csidriver-crd.yaml b/charts/ceph-csi-cephfs/templates/csidriver-crd.yaml index aaef955df31..e085efd6f2f 100644 --- a/charts/ceph-csi-cephfs/templates/csidriver-crd.yaml +++ b/charts/ceph-csi-cephfs/templates/csidriver-crd.yaml @@ -1,10 +1,11 @@ -{{- if not .Values.provisioner.attacher.enabled -}} -apiVersion: storage.k8s.io/v1beta1 +{{ if semverCompare ">=1.18" .Capabilities.KubeVersion.GitVersion }} +apiVersion: storage.k8s.io/v1 +{{ else }} +apiVersion: storage.k8s.io/v1betav1 +{{ end }} kind: CSIDriver metadata: name: {{ .Values.driverName }} - namespace: {{ .Release.Namespace }} spec: - attachRequired: false + attachRequired: true podInfoOnMount: false -{{- end -}} diff --git a/charts/ceph-csi-rbd/templates/csidriver-crd.yaml b/charts/ceph-csi-rbd/templates/csidriver-crd.yaml index aaef955df31..4991bd4fc2f 100644 --- a/charts/ceph-csi-rbd/templates/csidriver-crd.yaml +++ b/charts/ceph-csi-rbd/templates/csidriver-crd.yaml @@ -1,10 +1,11 @@ -{{- if not .Values.provisioner.attacher.enabled -}} -apiVersion: storage.k8s.io/v1beta1 +{{ if semverCompare ">=1.18" .Capabilities.KubeVersion.GitVersion }} +apiVersion: storage.k8s.io/v1 +{{ else }} +apiVersion: storage.k8s.io/betav1 +{{ end }} kind: CSIDriver metadata: name: {{ .Values.driverName }} - namespace: {{ .Release.Namespace }} spec: - attachRequired: false + attachRequired: true podInfoOnMount: false -{{- end -}} diff --git a/deploy/cephfs/kubernetes/csidriver.yaml b/deploy/cephfs/kubernetes/csidriver.yaml new file mode 100644 index 00000000000..b3f93f000fa --- /dev/null +++ b/deploy/cephfs/kubernetes/csidriver.yaml @@ -0,0 +1,10 @@ +--- +# if Kubernetes version is less than 1.18 change +# apiVersion to storage.k8s.io/v1betav1 +apiVersion: storage.k8s.io/v1 +kind: CSIDriver +metadata: + name: cephfs.csi.ceph.com +spec: + attachRequired: true + podInfoOnMount: false diff --git a/deploy/rbd/kubernetes/csidriver.yaml b/deploy/rbd/kubernetes/csidriver.yaml new file mode 100644 index 00000000000..f371e9c938f --- /dev/null +++ b/deploy/rbd/kubernetes/csidriver.yaml @@ -0,0 +1,10 @@ +--- +# if Kubernetes version is less than 1.18 change +# apiVersion to storage.k8s.io/v1betav1 +apiVersion: storage.k8s.io/v1 +kind: CSIDriver +metadata: + name: rbd.csi.ceph.com +spec: + attachRequired: true + podInfoOnMount: false diff --git a/e2e/cephfs.go b/e2e/cephfs.go index 6abc9bfa44c..b60f0f05c05 100644 --- a/e2e/cephfs.go +++ b/e2e/cephfs.go @@ -3,6 +3,8 @@ package e2e import ( "context" "fmt" + "io/ioutil" + "os" "strings" "sync" @@ -61,6 +63,19 @@ func deleteCephfsPlugin() { } func createORDeleteCephfsResouces(action string) { + csiDriver, err := ioutil.ReadFile(cephfsDirPath + csiDriverObject) + if err != nil { + // createORDeleteRbdResouces is used for upgrade testing as csidriverObject is + // newly added, discarding file not found error. + if !os.IsNotExist(err) { + e2elog.Failf("failed to read content from %s with error %v", cephfsDirPath+csiDriverObject, err) + } + } else { + _, err = framework.RunKubectlInput(cephCSINamespace, string(csiDriver), action, "-f", "-") + if err != nil { + e2elog.Failf("failed to %s CSIDriver object with error %v", action, err) + } + } data, err := replaceNamespaceInTemplate(cephfsDirPath + cephfsProvisioner) if err != nil { e2elog.Failf("failed to read content from %s with error %v", cephfsDirPath+cephfsProvisioner, err) diff --git a/e2e/rbd.go b/e2e/rbd.go index d32606cadf5..aa41d3867c7 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -3,6 +3,8 @@ package e2e import ( "context" "fmt" + "io/ioutil" + "os" "strings" "sync" @@ -23,6 +25,7 @@ var ( rbdNodePluginRBAC = "csi-nodeplugin-rbac.yaml" rbdNodePluginPSP = "csi-nodeplugin-psp.yaml" configMap = "csi-config-map.yaml" + csiDriverObject = "csidriver.yaml" rbdDirPath = "../deploy/rbd/kubernetes/" rbdExamplePath = "../examples/rbd/" rbdDeploymentName = "csi-rbdplugin-provisioner" @@ -67,6 +70,19 @@ func deleteRBDPlugin() { } func createORDeleteRbdResouces(action string) { + csiDriver, err := ioutil.ReadFile(rbdDirPath + csiDriverObject) + if err != nil { + // createORDeleteRbdResouces is used for upgrade testing as csidriverObject is + // newly added, discarding file not found error. + if !os.IsNotExist(err) { + e2elog.Failf("failed to read content from %s with error %v", rbdDirPath+csiDriverObject, err) + } + } else { + _, err = framework.RunKubectlInput(cephCSINamespace, string(csiDriver), action, "-f", "-") + if err != nil { + e2elog.Failf("failed to %s CSIDriver object with error %v", action, err) + } + } data, err := replaceNamespaceInTemplate(rbdDirPath + rbdProvisioner) if err != nil { e2elog.Failf("failed to read content from %s with error %v", rbdDirPath+rbdProvisioner, err)