From ea5d9dfb5c4663ddc39c2c91007c8053370e7a33 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Thu, 14 Mar 2019 17:08:46 +0530 Subject: [PATCH] Fix driver name as per CSI spec Signed-off-by: Madhu Rajanna --- cephfs/main.go | 10 ++++- .../kubernetes/csi-cephfsplugin-attacher.yaml | 6 +-- .../csi-cephfsplugin-provisioner.yaml | 8 ++-- .../cephfs/kubernetes/csi-cephfsplugin.yaml | 20 ++++----- .../helm/templates/nodeplugin-daemonset.yaml | 2 +- .../templates/provisioner-statefulset.yaml | 2 +- deploy/rbd/helm/values.yaml | 2 +- .../kubernetes/csi-rbdplugin-attacher.yaml | 6 +-- .../kubernetes/csi-rbdplugin-provisioner.yaml | 8 ++-- deploy/rbd/kubernetes/csi-rbdplugin.yaml | 26 ++++++------ docs/deploy-cephfs.md | 2 +- docs/deploy-rbd.md | 2 +- examples/rbd/csi-snapshotter.yaml | 2 +- pkg/cephfs/driver.go | 9 ++-- pkg/cephfs/volume.go | 5 ++- pkg/rbd/rbd.go | 9 ++-- pkg/util/util.go | 41 +++++++++++++++++++ rbd/main.go | 10 ++++- 18 files changed, 118 insertions(+), 52 deletions(-) create mode 100644 pkg/util/util.go diff --git a/cephfs/main.go b/cephfs/main.go index e77089832..a50de2605 100644 --- a/cephfs/main.go +++ b/cephfs/main.go @@ -32,7 +32,7 @@ func init() { var ( endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint") - driverName = flag.String("drivername", "csi-cephfsplugin", "name of the driver") + driverName = flag.String("drivername", "cephfs.csi.ceph.com", "name of the driver") nodeId = flag.String("nodeid", "", "node id") volumeMounter = flag.String("volumemounter", "", "default volume mounter (possible options are 'kernel', 'fuse')") metadataStorage = flag.String("metadatastorage", "node", "metadata persistence method [node|k8s_configmap]") @@ -41,6 +41,14 @@ var ( func main() { flag.Parse() + err := util.ValidateDriverName(*driverName) + if err != nil { + glog.Errorf("failed to validate driver name: %v", err) + os.Exit(1) + } + //update plugin name + cephfs.PluginFolder = cephfs.PluginFolder + *driverName + if err := createPersistentStorage(path.Join(cephfs.PluginFolder, "controller")); err != nil { glog.Errorf("failed to create persistent storage for controller: %v", err) os.Exit(1) diff --git a/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml b/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml index af77e6058..b61130873 100644 --- a/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml +++ b/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml @@ -33,13 +33,13 @@ spec: - "--csi-address=$(ADDRESS)" env: - name: ADDRESS - value: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock + value: /var/lib/kubelet/plugins/cephfs.csi.ceph.com/csi.sock imagePullPolicy: "IfNotPresent" volumeMounts: - name: socket-dir - mountPath: /var/lib/kubelet/plugins/csi-cephfsplugin + mountPath: /var/lib/kubelet/plugins/cephfs.csi.ceph.com volumes: - name: socket-dir hostPath: - path: /var/lib/kubelet/plugins/csi-cephfsplugin + path: /var/lib/kubelet/plugins/cephfs.csi.ceph.com type: DirectoryOrCreate diff --git a/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml b/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml index 8d6addea8..1e67c6110 100644 --- a/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml +++ b/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml @@ -29,18 +29,18 @@ spec: - name: csi-provisioner image: quay.io/k8scsi/csi-provisioner:v0.3.0 args: - - "--provisioner=csi-cephfsplugin" + - "--provisioner=cephfs.csi.ceph.com" - "--csi-address=$(ADDRESS)" - "--v=5" env: - name: ADDRESS - value: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock + value: /var/lib/kubelet/plugins/cephfs.csi.ceph.com/csi.sock imagePullPolicy: "IfNotPresent" volumeMounts: - name: socket-dir - mountPath: /var/lib/kubelet/plugins/csi-cephfsplugin + mountPath: /var/lib/kubelet/plugins/cephfs.csi.ceph.com volumes: - name: socket-dir hostPath: - path: /var/lib/kubelet/plugins/csi-cephfsplugin + path: /var/lib/kubelet/plugins/cephfs.csi.ceph.com type: DirectoryOrCreate diff --git a/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml b/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml index 50d42d2fd..6a556ceb8 100644 --- a/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml +++ b/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml @@ -15,7 +15,7 @@ spec: hostNetwork: true # to use e.g. Rook orchestrated cluster, and mons' FQDN is # resolved through k8s service, set dns policy to cluster first - dnsPolicy: ClusterFirstWithHostNet + dnsPolicy: ClusterFirstWithHostNet containers: - name: driver-registrar image: quay.io/k8scsi/driver-registrar:v0.3.0 @@ -25,16 +25,16 @@ spec: - "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)" env: - name: ADDRESS - value: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock + value: /var/lib/kubelet/plugins/cephfs.csi.ceph.com/csi.sock - name: DRIVER_REG_SOCK_PATH - value: /var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock + value: /var/lib/kubelet/plugins/cephfs.csi.ceph.com/csi.sock - name: KUBE_NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName volumeMounts: - name: socket-dir - mountPath: /var/lib/kubelet/plugins/csi-cephfsplugin + mountPath: /var/lib/kubelet/plugins/cephfs.csi.ceph.com - name: registration-dir mountPath: /registration - name: csi-cephfsplugin @@ -44,11 +44,11 @@ spec: add: ["SYS_ADMIN"] allowPrivilegeEscalation: true image: quay.io/cephcsi/cephfsplugin:v0.3.0 - args : + args: - "--nodeid=$(NODE_ID)" - "--endpoint=$(CSI_ENDPOINT)" - "--v=5" - - "--drivername=csi-cephfsplugin" + - "--drivername=cephfs.csi.ceph.com" - "--metadatastorage=k8s_configmap" env: - name: NODE_ID @@ -60,11 +60,11 @@ spec: fieldRef: fieldPath: metadata.namespace - name: CSI_ENDPOINT - value: unix://var/lib/kubelet/plugins/csi-cephfsplugin/csi.sock + value: unix://var/lib/kubelet/plugins/cephfs.csi.ceph.com/csi.sock imagePullPolicy: "IfNotPresent" volumeMounts: - name: plugin-dir - mountPath: /var/lib/kubelet/plugins/csi-cephfsplugin + mountPath: /var/lib/kubelet/plugins/cephfs.csi.ceph.com - name: pods-mount-dir mountPath: /var/lib/kubelet/pods mountPropagation: "Bidirectional" @@ -78,7 +78,7 @@ spec: volumes: - name: plugin-dir hostPath: - path: /var/lib/kubelet/plugins/csi-cephfsplugin + path: /var/lib/kubelet/plugins/cephfs.csi.ceph.com type: DirectoryOrCreate - name: registration-dir hostPath: @@ -90,7 +90,7 @@ spec: type: Directory - name: socket-dir hostPath: - path: /var/lib/kubelet/plugins/csi-cephfsplugin + path: /var/lib/kubelet/plugins/cephfs.csi.ceph.com type: DirectoryOrCreate - name: host-sys hostPath: diff --git a/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml b/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml index 6cbc279da..12c7aded6 100644 --- a/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml +++ b/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml @@ -64,7 +64,7 @@ spec: - "--nodeid=$(NODE_ID)" - "--endpoint=$(CSI_ENDPOINT)" - "--v=5" - - "--drivername=csi-rbdplugin" + - "--drivername=rbd.csi.ceph.com" - "--containerized=true" env: - name: HOST_ROOTFS diff --git a/deploy/rbd/helm/templates/provisioner-statefulset.yaml b/deploy/rbd/helm/templates/provisioner-statefulset.yaml index f5809b760..be302fd7c 100644 --- a/deploy/rbd/helm/templates/provisioner-statefulset.yaml +++ b/deploy/rbd/helm/templates/provisioner-statefulset.yaml @@ -25,7 +25,7 @@ spec: - name: csi-provisioner image: "{{ .Values.provisioner.image.repository }}:{{ .Values.provisioner.image.tag }}" args: - - "--provisioner=csi-rbdplugin" + - "--provisioner=rbd.csi.ceph.com" - "--csi-address=$(ADDRESS)" - "--v=5" env: diff --git a/deploy/rbd/helm/values.yaml b/deploy/rbd/helm/values.yaml index 03e4a7b68..8cc9399a0 100644 --- a/deploy/rbd/helm/values.yaml +++ b/deploy/rbd/helm/values.yaml @@ -12,7 +12,7 @@ serviceAccounts: create: true name: -socketDir: /var/lib/kubelet/plugins/csi-rbdplugin +socketDir: /var/lib/kubelet/plugins/rbd.csi.ceph.com socketFile: csi.sock attacher: diff --git a/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml b/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml index 6bf9711a8..a71f68ce9 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml @@ -33,13 +33,13 @@ spec: - "--csi-address=$(ADDRESS)" env: - name: ADDRESS - value: /var/lib/kubelet/plugins/csi-rbdplugin/csi.sock + value: /var/lib/kubelet/plugins/rbd.csi.ceph.com/csi.sock imagePullPolicy: "IfNotPresent" volumeMounts: - name: socket-dir - mountPath: /var/lib/kubelet/plugins/csi-rbdplugin + mountPath: /var/lib/kubelet/plugins/rbd.csi.ceph.com volumes: - name: socket-dir hostPath: - path: /var/lib/kubelet/plugins/csi-rbdplugin + path: /var/lib/kubelet/plugins/rbd.csi.ceph.com type: DirectoryOrCreate diff --git a/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml b/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml index 515cc50e9..95914743d 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml @@ -29,18 +29,18 @@ spec: - name: csi-provisioner image: quay.io/k8scsi/csi-provisioner:v0.3.0 args: - - "--provisioner=csi-rbdplugin" + - "--provisioner=rbd.csi.ceph.com" - "--csi-address=$(ADDRESS)" - "--v=5" env: - name: ADDRESS - value: /var/lib/kubelet/plugins/csi-rbdplugin/csi.sock + value: /var/lib/kubelet/plugins/rbd.csi.ceph.com/csi.sock imagePullPolicy: "IfNotPresent" volumeMounts: - name: socket-dir - mountPath: /var/lib/kubelet/plugins/csi-rbdplugin + mountPath: /var/lib/kubelet/plugins/rbd.csi.ceph.com volumes: - name: socket-dir hostPath: - path: /var/lib/kubelet/plugins/csi-rbdplugin + path: /var/lib/kubelet/plugins/rbd.csi.ceph.com type: DirectoryOrCreate diff --git a/deploy/rbd/kubernetes/csi-rbdplugin.yaml b/deploy/rbd/kubernetes/csi-rbdplugin.yaml index 478856e19..9665ae155 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin.yaml @@ -13,10 +13,10 @@ spec: spec: serviceAccount: csi-nodeplugin hostNetwork: true - hostPID: true + hostPID: true # to use e.g. Rook orchestrated cluster, and mons' FQDN is # resolved through k8s service, set dns policy to cluster first - dnsPolicy: ClusterFirstWithHostNet + dnsPolicy: ClusterFirstWithHostNet containers: - name: driver-registrar image: quay.io/k8scsi/driver-registrar:v0.3.0 @@ -26,16 +26,16 @@ spec: - "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)" env: - name: ADDRESS - value: /var/lib/kubelet/plugins/csi-rbdplugin/csi.sock + value: /var/lib/kubelet/plugins/rbd.csi.ceph.com/csi.sock - name: DRIVER_REG_SOCK_PATH - value: /var/lib/kubelet/plugins/csi-rbdplugin/csi.sock + value: /var/lib/kubelet/plugins/rbd.csi.ceph.com/csi.sock - name: KUBE_NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName volumeMounts: - name: socket-dir - mountPath: /var/lib/kubelet/plugins/csi-rbdplugin + mountPath: /var/lib/kubelet/plugins/rbd.csi.ceph.com - name: registration-dir mountPath: /registration - name: csi-rbdplugin @@ -45,11 +45,11 @@ spec: add: ["SYS_ADMIN"] allowPrivilegeEscalation: true image: quay.io/cephcsi/rbdplugin:v0.3.0 - args : + args: - "--nodeid=$(NODE_ID)" - "--endpoint=$(CSI_ENDPOINT)" - "--v=5" - - "--drivername=csi-rbdplugin" + - "--drivername=rbd.csi.ceph.com" - "--containerized=true" - "--metadatastorage=k8s_configmap" env: @@ -64,18 +64,18 @@ spec: fieldRef: fieldPath: metadata.namespace - name: CSI_ENDPOINT - value: unix://var/lib/kubelet/plugins/csi-rbdplugin/csi.sock + value: unix://var/lib/kubelet/plugins/rbd.csi.ceph.com/csi.sock imagePullPolicy: "IfNotPresent" volumeMounts: - name: plugin-dir - mountPath: /var/lib/kubelet/plugins/csi-rbdplugin + mountPath: /var/lib/kubelet/plugins/rbd.csi.ceph.com - name: pods-mount-dir mountPath: /var/lib/kubelet/pods mountPropagation: "Bidirectional" - mountPath: /dev name: host-dev - mountPath: /rootfs - name: host-rootfs + name: host-rootfs - mountPath: /sys name: host-sys - mountPath: /lib/modules @@ -84,7 +84,7 @@ spec: volumes: - name: plugin-dir hostPath: - path: /var/lib/kubelet/plugins/csi-rbdplugin + path: /var/lib/kubelet/plugins/rbd.csi.ceph.com type: DirectoryOrCreate - name: registration-dir hostPath: @@ -96,14 +96,14 @@ spec: type: Directory - name: socket-dir hostPath: - path: /var/lib/kubelet/plugins/csi-rbdplugin + path: /var/lib/kubelet/plugins/rbd.csi.ceph.com type: DirectoryOrCreate - name: host-dev hostPath: path: /dev - name: host-rootfs hostPath: - path: / + path: / - name: host-sys hostPath: path: /sys diff --git a/docs/deploy-cephfs.md b/docs/deploy-cephfs.md index f364b0c9f..e00429d9e 100644 --- a/docs/deploy-cephfs.md +++ b/docs/deploy-cephfs.md @@ -25,7 +25,7 @@ make image-cephfsplugin Option | Default value | Description --------------------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- `--endpoint` | `unix://tmp/csi.sock` | CSI endpoint, must be a UNIX socket -`--drivername` | `csi-cephfsplugin` | name of the driver (Kubernetes: `provisioner` field in StorageClass must correspond to this value) +`--drivername` | `cephfs.csi.ceph.com` | name of the driver (Kubernetes: `provisioner` field in StorageClass must correspond to this value) `--nodeid` | _empty_ | This node's ID `--volumemounter` | _empty_ | default volume mounter. Available options are `kernel` and `fuse`. This is the mount method used if volume parameters don't specify otherwise. If left unspecified, the driver will first probe for `ceph-fuse` in system's path and will choose Ceph kernel client if probing failed. `--metadatastorage` | _empty_ | Whether metadata should be kept on node as file or in a k8s configmap (`node` or `k8s_configmap`) diff --git a/docs/deploy-rbd.md b/docs/deploy-rbd.md index 17036decd..cfa730776 100644 --- a/docs/deploy-rbd.md +++ b/docs/deploy-rbd.md @@ -25,7 +25,7 @@ make image-rbdplugin Option | Default value | Description --------------------|-----------------------|--------------------------------------------------------------------------------------------------- `--endpoint` | `unix://tmp/csi.sock` | CSI endpoint, must be a UNIX socket -`--drivername` | `csi-cephfsplugin` | name of the driver (Kubernetes: `provisioner` field in StorageClass must correspond to this value) +`--drivername` | `rbd.csi.ceph.com` | name of the driver (Kubernetes: `provisioner` field in StorageClass must correspond to this value) `--nodeid` | _empty_ | This node's ID `--containerized` | true | Whether running in containerized mode `--metadatastorage` | _empty_ | Whether should metadata be kept on node as file or in a k8s configmap (`node` or `k8s_configmap`) diff --git a/examples/rbd/csi-snapshotter.yaml b/examples/rbd/csi-snapshotter.yaml index 377da9bc8..d63efcaef 100644 --- a/examples/rbd/csi-snapshotter.yaml +++ b/examples/rbd/csi-snapshotter.yaml @@ -51,6 +51,6 @@ spec: imagePullPolicy: Always volumes: - hostPath: - path: /var/lib/kubelet/plugins/csi-rbdplugin + path: /var/lib/kubelet/plugins/rbd.csi.ceph.com type: DirectoryOrCreate name: socket-dir diff --git a/pkg/cephfs/driver.go b/pkg/cephfs/driver.go index d28b282dc..5b1c91d26 100644 --- a/pkg/cephfs/driver.go +++ b/pkg/cephfs/driver.go @@ -20,18 +20,21 @@ import ( "github.com/golang/glog" "github.com/container-storage-interface/spec/lib/go/csi/v0" - "github.com/kubernetes-csi/drivers/pkg/csi-common" + csicommon "github.com/kubernetes-csi/drivers/pkg/csi-common" "github.com/ceph/ceph-csi/pkg/util" ) const ( - // PluginFolder is the kubelet plugin directory for cephfs plugin - PluginFolder = "/var/lib/kubelet/plugins/csi-cephfsplugin" // Version of the cephfs csi driver Version = "0.3.0" ) +var ( + // PluginFolder is the kubelet plugin directory for cephfs plugin + PluginFolder = "/var/lib/kubelet/plugins/" +) + type cephfsDriver struct { driver *csicommon.CSIDriver diff --git a/pkg/cephfs/volume.go b/pkg/cephfs/volume.go index 42c5e081b..6f65595d9 100644 --- a/pkg/cephfs/volume.go +++ b/pkg/cephfs/volume.go @@ -23,12 +23,15 @@ import ( ) const ( - cephRootPrefix = PluginFolder + "/controller/volumes/root-" cephVolumesRoot = "csi-volumes" namespacePrefix = "ns-" ) +var ( + cephRootPrefix = PluginFolder + "/controller/volumes/root-" +) + func getCephRootPathLocal(volId volumeID) string { return cephRootPrefix + string(volId) } diff --git a/pkg/rbd/rbd.go b/pkg/rbd/rbd.go index 83803164c..0cda3b363 100644 --- a/pkg/rbd/rbd.go +++ b/pkg/rbd/rbd.go @@ -21,20 +21,23 @@ import ( "github.com/ceph/ceph-csi/pkg/util" "github.com/container-storage-interface/spec/lib/go/csi/v0" - "github.com/kubernetes-csi/drivers/pkg/csi-common" + csicommon "github.com/kubernetes-csi/drivers/pkg/csi-common" "k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/nsenter" "k8s.io/utils/exec" ) -// PluginFolder defines the location of rbdplugin const ( - PluginFolder = "/var/lib/kubelet/plugins/csi-rbdplugin" rbdDefaultAdminId = "admin" rbdDefaultUserId = rbdDefaultAdminId ) +var ( + // PluginFolder defines the location of rbdplugin + PluginFolder = "/var/lib/kubelet/plugins/" +) + type rbd struct { driver *csicommon.CSIDriver diff --git a/pkg/util/util.go b/pkg/util/util.go new file mode 100644 index 000000000..976ffddef --- /dev/null +++ b/pkg/util/util.go @@ -0,0 +1,41 @@ +/* +Copyright 2019 The Kubernetes Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "strings" + + "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/util/validation" +) + +// ValidateDriverName validates the driver name +func ValidateDriverName(driverName string) error { + if len(driverName) == 0 { + return errors.New("driver name is empty") + } + + if len(driverName) > 63 { + return errors.New("driver name length should be less than 63 chars") + } + var err error + for _, msg := range validation.IsDNS1123Subdomain(strings.ToLower(driverName)) { + if err == nil { + err = errors.New(msg) + continue + } + err = errors.Wrap(err, msg) + } + return err +} diff --git a/rbd/main.go b/rbd/main.go index b85e93b63..e28b0b2bf 100644 --- a/rbd/main.go +++ b/rbd/main.go @@ -32,7 +32,7 @@ func init() { var ( endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint") - driverName = flag.String("drivername", "csi-rbdplugin", "name of the driver") + driverName = flag.String("drivername", "rbd.csi.ceph.com", "name of the driver") nodeID = flag.String("nodeid", "", "node id") containerized = flag.Bool("containerized", true, "whether run as containerized") metadataStorage = flag.String("metadatastorage", "node", "metadata persistence method [node|k8s_configmap]") @@ -41,6 +41,14 @@ var ( func main() { flag.Parse() + err := util.ValidateDriverName(*driverName) + if err != nil { + glog.Errorf("failed to validate driver name: %v", err) + os.Exit(1) + } + //update plugin name + rbd.PluginFolder = rbd.PluginFolder + *driverName + if err := createPersistentStorage(path.Join(rbd.PluginFolder, "controller")); err != nil { glog.Errorf("failed to create persistent storage for controller %v", err) os.Exit(1)