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/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 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/controllerserver_test.go b/pkg/rbd/controllerserver_test.go new file mode 100644 index 000000000..d9eadc25d --- /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": { + VolID: "1", + }, + "item2": { + VolID: "2", + }, + }, + snapshots: map[string]rbdSnapshot{ + "item1": { + SnapID: "1", + }, + "item2": { + 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") + } +} diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 14fcc0ebf..6a5555de6 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,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) @@ -467,7 +469,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