From 8dcca3ebc568f2b8b09214a45728d22f5ddd67f5 Mon Sep 17 00:00:00 2001 From: Miao Zhou Date: Fri, 4 Jan 2019 11:43:28 +0800 Subject: [PATCH 01/12] bump image version csi-attacher and csi-provisioner change from v1.0.0 to v1.0.1, as i the v1.0.0 is a Pre-release driver-registrar:v1.0.0 change to csi-node-driver-registrar:v1.0.2, as in CSI Spec v1.0.0, image name has changed, see [https://github.com/kubernetes-csi/node-driver-registrar#compatibility](https://github.com/kubernetes-csi/node-driver-registrar#compatibility) --- deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml | 2 +- deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml | 2 +- deploy/cephfs/kubernetes/csi-cephfsplugin.yaml | 2 +- deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml | 2 +- deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml | 2 +- deploy/rbd/kubernetes/csi-rbdplugin.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml b/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml index b663067a8..066e14ad3 100644 --- a/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml +++ b/deploy/cephfs/kubernetes/csi-cephfsplugin-attacher.yaml @@ -27,7 +27,7 @@ spec: serviceAccount: csi-attacher containers: - name: csi-cephfsplugin-attacher - image: quay.io/k8scsi/csi-attacher:v1.0.0 + image: quay.io/k8scsi/csi-attacher:v1.0.1 args: - "--v=5" - "--csi-address=$(ADDRESS)" diff --git a/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml b/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml index 8206680b3..1b37c7165 100644 --- a/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml +++ b/deploy/cephfs/kubernetes/csi-cephfsplugin-provisioner.yaml @@ -27,7 +27,7 @@ spec: serviceAccount: csi-provisioner containers: - name: csi-provisioner - image: quay.io/k8scsi/csi-provisioner:v1.0.0 + image: quay.io/k8scsi/csi-provisioner:v1.0.1 args: - "--provisioner=csi-cephfsplugin" - "--csi-address=$(ADDRESS)" diff --git a/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml b/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml index e8f49f2af..36bdfecb3 100644 --- a/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml +++ b/deploy/cephfs/kubernetes/csi-cephfsplugin.yaml @@ -18,7 +18,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: driver-registrar - image: quay.io/k8scsi/driver-registrar:v1.0.0 + image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.2 args: - "--v=5" - "--csi-address=$(ADDRESS)" diff --git a/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml b/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml index f7a3d488a..39f9826ee 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin-attacher.yaml @@ -27,7 +27,7 @@ spec: serviceAccount: csi-attacher containers: - name: csi-rbdplugin-attacher - image: quay.io/k8scsi/csi-attacher:v1.0.0 + image: quay.io/k8scsi/csi-attacher:v1.0.1 args: - "--v=5" - "--csi-address=$(ADDRESS)" diff --git a/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml b/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml index 966b49260..abd2739c0 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin-provisioner.yaml @@ -27,7 +27,7 @@ spec: serviceAccount: csi-provisioner containers: - name: csi-provisioner - image: quay.io/k8scsi/csi-provisioner:v1.0.0 + image: quay.io/k8scsi/csi-provisioner:v1.0.1 args: - "--provisioner=csi-rbdplugin" - "--csi-address=$(ADDRESS)" diff --git a/deploy/rbd/kubernetes/csi-rbdplugin.yaml b/deploy/rbd/kubernetes/csi-rbdplugin.yaml index 12e1ffdfc..de91bf838 100644 --- a/deploy/rbd/kubernetes/csi-rbdplugin.yaml +++ b/deploy/rbd/kubernetes/csi-rbdplugin.yaml @@ -19,7 +19,7 @@ spec: dnsPolicy: ClusterFirstWithHostNet containers: - name: driver-registrar - image: quay.io/k8scsi/driver-registrar:v1.0.0 + image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.2 args: - "--v=5" - "--csi-address=$(ADDRESS)" From ffe2816cb5751b713729fd3e0d0aadc58458e1a2 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 20 Mar 2019 15:14:20 -0400 Subject: [PATCH 02/12] cmd: create a unified cephcsi binary Create a single binary that can start ceph-csi in either rbd or cephfs mode. Signed-off-by: John Mulligan --- cmd/cephcsi.go | 133 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 cmd/cephcsi.go diff --git a/cmd/cephcsi.go b/cmd/cephcsi.go new file mode 100644 index 000000000..315b4fa9c --- /dev/null +++ b/cmd/cephcsi.go @@ -0,0 +1,133 @@ +/* +Copyright 2019 The Ceph-CSI 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 main + +import ( + "flag" + "os" + "path" + "strings" + + "github.com/ceph/ceph-csi/pkg/cephfs" + "github.com/ceph/ceph-csi/pkg/rbd" + "github.com/ceph/ceph-csi/pkg/util" + "k8s.io/klog" +) + +const ( + rbdType = "rbd" + cephfsType = "cephfs" + + rbdDefaultName = "rbd.csi.ceph.com" + cephfsDefaultName = "cephfs.csi.ceph.com" +) + +var ( + // common flags + vtype = flag.String("type", "", "driver type [rbd|cephfs]") + endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint") + driverName = flag.String("drivername", "", "name of the driver") + nodeID = flag.String("nodeid", "", "node id") + metadataStorage = flag.String("metadatastorage", "", "metadata persistence method [node|k8s_configmap]") + + // rbd related flags + containerized = flag.Bool("containerized", true, "whether run as containerized") + configRoot = flag.String("configroot", "/etc/csi-config", "directory in which CSI specific Ceph"+ + " cluster configurations are present, OR the value \"k8s_objects\" if present as kubernetes secrets") + + // cephfs related flags + volumeMounter = flag.String("volumemounter", "", "default volume mounter (possible options are 'kernel', 'fuse')") + mountCacheDir = flag.String("mountcachedir", "", "mount info cache save dir") +) + +func init() { + klog.InitFlags(nil) + if err := flag.Set("logtostderr", "true"); err != nil { + klog.Exitf("failed to set logtostderr flag: %v", err) + } + flag.Parse() +} + +func getType() string { + if vtype == nil || len(*vtype) == 0 { + a0 := path.Base(os.Args[0]) + if strings.Contains(a0, rbdType) { + return rbdType + } + if strings.Contains(a0, cephfsType) { + return cephfsType + } + return "" + } + return *vtype +} + +func getDriverName() string { + // was explicitly passed a driver name + if driverName != nil && len(*driverName) != 0 { + return *driverName + } + // select driver name based on volume type + switch getType() { + case rbdType: + return rbdDefaultName + case cephfsType: + return cephfsDefaultName + default: + return "" + } +} + +func main() { + driverType := getType() + if len(driverType) == 0 { + klog.Fatalln("driver type not specified") + } + + dname := getDriverName() + err := util.ValidateDriverName(dname) + if err != nil { + klog.Fatalln(err) // calls exit + } + + switch driverType { + case rbdType: + rbd.PluginFolder = rbd.PluginFolder + dname + cp, err := util.CreatePersistanceStorage( + rbd.PluginFolder, *metadataStorage, dname) + if err != nil { + os.Exit(1) + } + driver := rbd.NewDriver() + driver.Run(dname, *nodeID, *endpoint, *configRoot, *containerized, cp) + + case cephfsType: + cephfs.PluginFolder = cephfs.PluginFolder + dname + cp, err := util.CreatePersistanceStorage( + cephfs.PluginFolder, *metadataStorage, dname) + if err != nil { + os.Exit(1) + } + driver := cephfs.NewDriver() + driver.Run(dname, *nodeID, *endpoint, *volumeMounter, *mountCacheDir, cp) + + default: + klog.Fatalln("invalid volume type", vtype) // calls exit + } + + os.Exit(0) +} From d969dada3ef9f563b4a5f7079c60fca5c94d548a Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 20 Mar 2019 15:15:51 -0400 Subject: [PATCH 03/12] deploy: create a new Dockerfile for unified cephcsi image Signed-off-by: John Mulligan --- deploy/cephcsi/image/Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 deploy/cephcsi/image/Dockerfile diff --git a/deploy/cephcsi/image/Dockerfile b/deploy/cephcsi/image/Dockerfile new file mode 100644 index 000000000..3a11c225d --- /dev/null +++ b/deploy/cephcsi/image/Dockerfile @@ -0,0 +1,14 @@ + +FROM ceph/ceph:v14.2 +LABEL maintainers="Ceph-CSI Authors" +LABEL description="Ceph-CSI Plugin" + +ENV CSIBIN=/usr/local/bin/cephcsi + +COPY cephcsi $CSIBIN + +RUN chmod +x $CSIBIN && \ + ln -sf $CSIBIN /usr/local/bin/cephcsi-rbd && \ + ln -sf $CSIBIN /usr/local/bin/cephcsi-cephfs + +ENTRYPOINT ["/usr/local/bin/cephcsi"] From de94cb62a99b899dc95bf9db79510a1c6ae9a867 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 20 Mar 2019 15:16:15 -0400 Subject: [PATCH 04/12] Makefile: add initial build rules for combined binary and image Add rules and variables to the Makefile so that the unified binary and container image can be built. Signed-off-by: John Mulligan --- Makefile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 11b1a67fc..8451b380a 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ RBD_IMAGE_VERSION=$(if $(ENV_RBD_IMAGE_VERSION),$(ENV_RBD_IMAGE_VERSION),v1.0.0) CEPHFS_IMAGE_NAME=$(if $(ENV_CEPHFS_IMAGE_NAME),$(ENV_CEPHFS_IMAGE_NAME),quay.io/cephcsi/cephfsplugin) CEPHFS_IMAGE_VERSION=$(if $(ENV_CEPHFS_IMAGE_VERSION),$(ENV_CEPHFS_IMAGE_VERSION),v1.0.0) +CSI_IMAGE_NAME?=quay.io/cephcsi/cephcsi +CSI_IMAGE_VERSION?=v1.0.0 + $(info rbd image settings: $(RBD_IMAGE_NAME) version $(RBD_IMAGE_VERSION)) $(info cephfs image settings: $(CEPHFS_IMAGE_NAME) version $(CEPHFS_IMAGE_VERSION)) @@ -36,20 +39,21 @@ static-check: ./scripts/lint-go.sh ./scripts/lint-text.sh -rbdplugin: +.PHONY: cephcsi +cephcsi: if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi - CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/rbdplugin ./cmd/rbd + CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/cephcsi ./cmd/ -image-rbdplugin: rbdplugin - cp _output/rbdplugin deploy/rbd/docker +image-cephcsi: cephcsi + cp deploy/cephcsi/image/Dockerfile _output + $(CONTAINER_CMD) build -t $(CSI_IMAGE_NAME):$(CSI_IMAGE_VERSION) _output + +image-rbdplugin: cephcsi + cp _output/cephcsi deploy/rbd/docker/rbdplugin $(CONTAINER_CMD) build -t $(RBD_IMAGE_NAME):$(RBD_IMAGE_VERSION) deploy/rbd/docker -cephfsplugin: - if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi - CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o _output/cephfsplugin ./cmd/cephfs - -image-cephfsplugin: cephfsplugin - cp _output/cephfsplugin deploy/cephfs/docker +image-cephfsplugin: cephcsi + cp _output/cephsci deploy/cephfs/docker/cephfsplugin $(CONTAINER_CMD) build -t $(CEPHFS_IMAGE_NAME):$(CEPHFS_IMAGE_VERSION) deploy/cephfs/docker push-image-rbdplugin: image-rbdplugin From a01c01b01b962e5a529e77c7612e7bac0d91c7e2 Mon Sep 17 00:00:00 2001 From: Zhou Miao Date: Thu, 25 Apr 2019 12:03:44 +0800 Subject: [PATCH 05/12] fix helm value pullPolicy mismatch bug --- deploy/cephfs/helm/templates/nodeplugin-daemonset.yaml | 4 ++-- deploy/cephfs/helm/templates/provisioner-statefulset.yaml | 2 +- deploy/rbd/helm/templates/nodeplugin-daemonset.yaml | 4 ++-- deploy/rbd/helm/templates/provisioner-statefulset.yaml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deploy/cephfs/helm/templates/nodeplugin-daemonset.yaml b/deploy/cephfs/helm/templates/nodeplugin-daemonset.yaml index c56e70bb4..24ffc8420 100644 --- a/deploy/cephfs/helm/templates/nodeplugin-daemonset.yaml +++ b/deploy/cephfs/helm/templates/nodeplugin-daemonset.yaml @@ -49,7 +49,7 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName - imagePullPolicy: {{ .Values.nodeplugin.registrar.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.registrar.image.pullPolicy }} volumeMounts: - name: plugin-dir mountPath: /csi @@ -82,7 +82,7 @@ spec: fieldPath: spec.nodeName - name: CSI_ENDPOINT value: "unix:/{{ .Values.socketDir }}/{{ .Values.socketFile }}" - imagePullPolicy: {{ .Values.nodeplugin.plugin.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.plugin.image.pullPolicy }} volumeMounts: - name: mount-cache-dir mountPath: /mount-cache-dir diff --git a/deploy/cephfs/helm/templates/provisioner-statefulset.yaml b/deploy/cephfs/helm/templates/provisioner-statefulset.yaml index fe4fc6428..84c698fbc 100644 --- a/deploy/cephfs/helm/templates/provisioner-statefulset.yaml +++ b/deploy/cephfs/helm/templates/provisioner-statefulset.yaml @@ -65,7 +65,7 @@ spec: fieldPath: spec.nodeName - name: CSI_ENDPOINT value: "unix:/{{ .Values.socketDir }}/{{ .Values.socketFile }}" - imagePullPolicy: {{ .Values.nodeplugin.plugin.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.plugin.image.pullPolicy }} volumeMounts: - name: socket-dir mountPath: {{ .Values.socketDir }} diff --git a/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml b/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml index 355983b49..6290dd978 100644 --- a/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml +++ b/deploy/rbd/helm/templates/nodeplugin-daemonset.yaml @@ -49,7 +49,7 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName - imagePullPolicy: {{ .Values.nodeplugin.registrar.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.registrar.image.pullPolicy }} volumeMounts: - name: plugin-dir mountPath: /csi @@ -82,7 +82,7 @@ spec: fieldPath: spec.nodeName - name: CSI_ENDPOINT value: "unix:/{{ .Values.socketDir }}/{{ .Values.socketFile }}" - imagePullPolicy: {{ .Values.nodeplugin.plugin.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.plugin.image.pullPolicy }} volumeMounts: - name: plugin-dir mountPath: {{ .Values.socketDir }} diff --git a/deploy/rbd/helm/templates/provisioner-statefulset.yaml b/deploy/rbd/helm/templates/provisioner-statefulset.yaml index 269cb0a44..23265d116 100644 --- a/deploy/rbd/helm/templates/provisioner-statefulset.yaml +++ b/deploy/rbd/helm/templates/provisioner-statefulset.yaml @@ -43,7 +43,7 @@ spec: {{ toYaml .Values.provisioner.resources | indent 12 }} - name: csi-snapshotter image: {{ .Values.snapshotter.image.repository }}:{{ .Values.snapshotter.image.tag }} - imagePullPolicy: {{ .Values.nodeplugin.plugin.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.plugin.image.pullPolicy }} args: - "--csi-address=$(ADDRESS)" - "--connection-timeout=15s" @@ -83,7 +83,7 @@ spec: fieldPath: spec.nodeName - name: CSI_ENDPOINT value: "unix:/{{ .Values.socketDir }}/{{ .Values.socketFile }}" - imagePullPolicy: {{ .Values.nodeplugin.plugin.image.imagePullPolicy }} + imagePullPolicy: {{ .Values.nodeplugin.plugin.image.pullPolicy }} volumeMounts: - name: socket-dir mountPath: {{ .Values.socketDir }} From b488a5ae8525308ed183b803d9411193624ae197 Mon Sep 17 00:00:00 2001 From: Dylan Redding Date: Wed, 24 Apr 2019 17:55:32 -0500 Subject: [PATCH 06/12] Fix loading data from configmaps. --- Gopkg.lock | 1 + pkg/rbd/controllerserver.go | 12 ++++++------ pkg/rbd/rbd_util.go | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index d3270adf6..d3cf700d8 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -528,6 +528,7 @@ "k8s.io/apimachinery/pkg/api/errors", "k8s.io/apimachinery/pkg/apis/meta/v1", "k8s.io/apimachinery/pkg/util/sets", + "k8s.io/apimachinery/pkg/util/validation", "k8s.io/apimachinery/pkg/util/wait", "k8s.io/client-go/kubernetes", "k8s.io/client-go/rest", diff --git a/pkg/rbd/controllerserver.go b/pkg/rbd/controllerserver.go index 27c407fdf..84159c078 100644 --- a/pkg/rbd/controllerserver.go +++ b/pkg/rbd/controllerserver.go @@ -50,8 +50,8 @@ type ControllerServer struct { } var ( - rbdVolumes = map[string]*rbdVolume{} - rbdSnapshots = map[string]*rbdSnapshot{} + rbdVolumes = map[string]rbdVolume{} + rbdSnapshots = map[string]rbdSnapshot{} ) // LoadExDataFromMetadataStore loads the rbd volume and snapshot @@ -60,14 +60,14 @@ func (cs *ControllerServer) LoadExDataFromMetadataStore() error { vol := &rbdVolume{} // nolint cs.MetadataStore.ForAll("csi-rbd-vol-", vol, func(identifier string) error { - rbdVolumes[identifier] = vol + rbdVolumes[identifier] = *vol return nil }) snap := &rbdSnapshot{} // nolint cs.MetadataStore.ForAll("csi-rbd-(.*)-snap-", snap, func(identifier string) error { - rbdSnapshots[identifier] = snap + rbdSnapshots[identifier] = *snap return nil }) @@ -194,7 +194,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol // size in bytes) rbdVol.VolSize = rbdVol.VolSize * util.MiB - rbdVolumes[rbdVol.VolID] = rbdVol + rbdVolumes[rbdVol.VolID] = *rbdVol if err = storeVolumeMetadata(rbdVol, cs.MetadataStore); err != nil { return nil, status.Error(codes.Internal, err.Error()) @@ -444,7 +444,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS rbdSnap.CreatedAt = ptypes.TimestampNow().GetSeconds() - rbdSnapshots[snapshotID] = rbdSnap + rbdSnapshots[snapshotID] = *rbdSnap if err = storeSnapshotMetadata(rbdSnap, cs.MetadataStore); err != nil { return nil, status.Error(codes.Internal, err.Error()) diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 14fcc0ebf..0b04d8a7f 100644 --- a/pkg/rbd/rbd_util.go +++ b/pkg/rbd/rbd_util.go @@ -400,7 +400,7 @@ func hasSnapshotFeature(imageFeatures string) bool { func getRBDVolumeByID(volumeID string) (*rbdVolume, error) { if rbdVol, ok := rbdVolumes[volumeID]; ok { - return rbdVol, nil + return &rbdVol, nil } return nil, fmt.Errorf("volume id %s does not exit in the volumes list", volumeID) } @@ -408,7 +408,7 @@ func getRBDVolumeByID(volumeID string) (*rbdVolume, error) { func getRBDVolumeByName(volName string) (*rbdVolume, error) { for _, rbdVol := range rbdVolumes { if rbdVol.VolName == volName { - return rbdVol, nil + return &rbdVol, nil } } return nil, fmt.Errorf("volume name %s does not exit in the volumes list", volName) @@ -417,7 +417,7 @@ func getRBDVolumeByName(volName string) (*rbdVolume, error) { func getRBDSnapshotByName(snapName string) (*rbdSnapshot, error) { for _, rbdSnap := range rbdSnapshots { if rbdSnap.SnapName == snapName { - return rbdSnap, nil + return &rbdSnap, nil } } return nil, fmt.Errorf("snapshot name %s does not exit in the snapshots list", snapName) @@ -467,7 +467,7 @@ func protectSnapshot(pOpts *rbdSnapshot, adminID string, credentials map[string] return nil } -func extractStoredVolOpt(r *rbdVolume) map[string]string { +func extractStoredVolOpt(r rbdVolume) map[string]string { volOptions := make(map[string]string) volOptions["pool"] = r.Pool From 6826694618ff6a2089cc25c338a7789761528aae Mon Sep 17 00:00:00 2001 From: Dylan Redding Date: Wed, 24 Apr 2019 18:24:20 -0500 Subject: [PATCH 07/12] Added unit test. --- pkg/rbd/controllerserver_test.go | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 pkg/rbd/controllerserver_test.go diff --git a/pkg/rbd/controllerserver_test.go b/pkg/rbd/controllerserver_test.go new file mode 100644 index 000000000..ab92ba112 --- /dev/null +++ b/pkg/rbd/controllerserver_test.go @@ -0,0 +1,81 @@ +package rbd + +import ( + "testing" + + "github.com/ceph/ceph-csi/pkg/util" +) + +type testCachePersister struct { + volumes map[string]rbdVolume + snapshots map[string]rbdSnapshot +} + +func (t *testCachePersister) Create(identifier string, data interface{}) error { + return nil +} + +func (t *testCachePersister) Get(identifier string, data interface{}) error { + return nil +} + +func (t *testCachePersister) ForAll(pattern string, destObj interface{}, f util.ForAllFunc) error { + + switch pattern { + case "csi-rbd-vol-": + for identifier, vol := range t.volumes { + *destObj.(*rbdVolume) = vol + if err := f(identifier); err != nil { + return err + } + } + case "csi-rbd-(.*)-snap-": + for identifier, snap := range t.snapshots { + *destObj.(*rbdSnapshot) = snap + if err := f(identifier); err != nil { + return err + } + } + } + + return nil +} + +func (t *testCachePersister) Delete(identifier string) error { + return nil +} + +func TestLoadExDataFromMetadataStore(t *testing.T) { + cs := &ControllerServer{ + MetadataStore: &testCachePersister{ + volumes: map[string]rbdVolume{ + "item1": rbdVolume{ + VolID: "1", + }, + "item2": rbdVolume{ + VolID: "2", + }, + }, + snapshots: map[string]rbdSnapshot{ + "item1": rbdSnapshot{ + SnapID: "1", + }, + "item2": rbdSnapshot{ + SnapID: "2", + }, + }, + }, + } + + if err := cs.LoadExDataFromMetadataStore(); err != nil { + t.Error(err) + } + + if rbdVolumes["item1"] == rbdVolumes["item2"] { + t.Error("rbd volume entries contain pointer to same volume") + } + + if rbdSnapshots["item1"] == rbdSnapshots["item2"] { + t.Error("rbd snapshot entries contain pointer to same snapshot") + } +} From e0a1661beedc962b42c41296984f12a8ea7cd2ad Mon Sep 17 00:00:00 2001 From: Dylan Redding Date: Wed, 24 Apr 2019 18:57:01 -0500 Subject: [PATCH 08/12] linter fixes --- pkg/rbd/controllerserver_test.go | 8 ++++---- pkg/rbd/rbd_util.go | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/rbd/controllerserver_test.go b/pkg/rbd/controllerserver_test.go index ab92ba112..d9eadc25d 100644 --- a/pkg/rbd/controllerserver_test.go +++ b/pkg/rbd/controllerserver_test.go @@ -49,18 +49,18 @@ func TestLoadExDataFromMetadataStore(t *testing.T) { cs := &ControllerServer{ MetadataStore: &testCachePersister{ volumes: map[string]rbdVolume{ - "item1": rbdVolume{ + "item1": { VolID: "1", }, - "item2": rbdVolume{ + "item2": { VolID: "2", }, }, snapshots: map[string]rbdSnapshot{ - "item1": rbdSnapshot{ + "item1": { SnapID: "1", }, - "item2": rbdSnapshot{ + "item2": { SnapID: "2", }, }, diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 0b04d8a7f..6a5555de6 100644 --- a/pkg/rbd/rbd_util.go +++ b/pkg/rbd/rbd_util.go @@ -408,7 +408,8 @@ func getRBDVolumeByID(volumeID string) (*rbdVolume, error) { func getRBDVolumeByName(volName string) (*rbdVolume, error) { for _, rbdVol := range rbdVolumes { if rbdVol.VolName == volName { - return &rbdVol, nil + v := rbdVol + return &v, nil } } return nil, fmt.Errorf("volume name %s does not exit in the volumes list", volName) @@ -417,7 +418,8 @@ func getRBDVolumeByName(volName string) (*rbdVolume, error) { func getRBDSnapshotByName(snapName string) (*rbdSnapshot, error) { for _, rbdSnap := range rbdSnapshots { if rbdSnap.SnapName == snapName { - return &rbdSnap, nil + s := rbdSnap + return &s, nil } } return nil, fmt.Errorf("snapshot name %s does not exit in the snapshots list", snapName) From b213b3b626f900939a90fd21aeee1ec5cdcae232 Mon Sep 17 00:00:00 2001 From: Mike Wilson Date: Wed, 1 May 2019 17:08:08 -0400 Subject: [PATCH 09/12] Nitpick spelling chats -> charts --- deploy.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deploy.sh b/deploy.sh index 9eb02b2a8..06df0f4e9 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,6 +1,6 @@ #!/bin/bash -push_helm_chats() { +push_helm_charts() { PACKAGE=$1 CHANGED=0 VERSION=$(grep 'version:' deploy/"$PACKAGE"/helm/Chart.yaml | awk '{print $2}') @@ -53,6 +53,6 @@ if [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then mkdir -p csi-charts/docs popd >/dev/null - push_helm_chats rbd - push_helm_chats cephfs + push_helm_charts rbd + push_helm_charts cephfs fi From 00e7e29996726c0b712f36905528c273841bf5b2 Mon Sep 17 00:00:00 2001 From: Miao Zhou Date: Mon, 6 May 2019 15:52:45 +0800 Subject: [PATCH 10/12] bump up the chart version --- deploy/cephfs/helm/Chart.yaml | 2 +- deploy/rbd/helm/Chart.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/cephfs/helm/Chart.yaml b/deploy/cephfs/helm/Chart.yaml index f324e7f57..dc94bb2af 100644 --- a/deploy/cephfs/helm/Chart.yaml +++ b/deploy/cephfs/helm/Chart.yaml @@ -4,7 +4,7 @@ appVersion: "1.0.0" description: "Container Storage Interface (CSI) driver, provisioner, and attacher for Ceph cephfs" name: ceph-csi-cephfs -version: 0.5.1 +version: 0.6.0 keywords: - ceph - cephfs diff --git a/deploy/rbd/helm/Chart.yaml b/deploy/rbd/helm/Chart.yaml index 30585b9d8..a36450e34 100644 --- a/deploy/rbd/helm/Chart.yaml +++ b/deploy/rbd/helm/Chart.yaml @@ -4,7 +4,7 @@ appVersion: "1.0.0" description: "Container Storage Interface (CSI) driver, provisioner, snapshotter, and attacher for Ceph RBD" name: ceph-csi-rbd -version: 0.5.1 +version: 0.6.0 keywords: - ceph - rbd From 68ff602391bb91598618a2b15d64d636fb9e8ce8 Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Tue, 7 May 2019 15:25:11 +0530 Subject: [PATCH 11/12] Resolve merge conflict Signed-off-by: Humble Chirammal --- deploy/cephfs/helm/Chart.yaml | 4 ---- deploy/rbd/helm/Chart.yaml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/deploy/cephfs/helm/Chart.yaml b/deploy/cephfs/helm/Chart.yaml index 35fd2dd91..dc94bb2af 100644 --- a/deploy/cephfs/helm/Chart.yaml +++ b/deploy/cephfs/helm/Chart.yaml @@ -4,11 +4,7 @@ appVersion: "1.0.0" description: "Container Storage Interface (CSI) driver, provisioner, and attacher for Ceph cephfs" name: ceph-csi-cephfs -<<<<<<< HEAD version: 0.6.0 -======= -version: 0.5.3 ->>>>>>> 882bebf1d8507d6bcd4b4bfae23a861057353785 keywords: - ceph - cephfs diff --git a/deploy/rbd/helm/Chart.yaml b/deploy/rbd/helm/Chart.yaml index 15debafe0..a36450e34 100644 --- a/deploy/rbd/helm/Chart.yaml +++ b/deploy/rbd/helm/Chart.yaml @@ -4,11 +4,7 @@ appVersion: "1.0.0" description: "Container Storage Interface (CSI) driver, provisioner, snapshotter, and attacher for Ceph RBD" name: ceph-csi-rbd -<<<<<<< HEAD version: 0.6.0 -======= -version: 0.5.3 ->>>>>>> 882bebf1d8507d6bcd4b4bfae23a861057353785 keywords: - ceph - rbd From dd31e6e9474c25dd424d20d3fd97fa9ca512e009 Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Tue, 7 May 2019 16:20:03 +0530 Subject: [PATCH 12/12] Remove duplicate entries from Makefile and resolve merge conflict. Signed-off-by: Humble Chirammal --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 28e351256..e9b5ee223 100644 --- a/Makefile +++ b/Makefile @@ -25,9 +25,6 @@ CEPHFS_IMAGE_VERSION=$(if $(ENV_CEPHFS_IMAGE_VERSION),$(ENV_CEPHFS_IMAGE_VERSION CSI_IMAGE_NAME?=quay.io/cephcsi/cephcsi CSI_IMAGE_VERSION?=v1.0.0 -CSI_IMAGE_NAME?=quay.io/cephcsi/cephcsi -CSI_IMAGE_VERSION?=v1.0.0 - $(info rbd image settings: $(RBD_IMAGE_NAME) version $(RBD_IMAGE_VERSION)) $(info cephfs image settings: $(CEPHFS_IMAGE_NAME) version $(CEPHFS_IMAGE_VERSION))