updated storage class parameter clusterName to clusterNamespace

cluster name and namespace are required to match.
clusterName still works for backward compatiblity

Signed-off-by: rohan47 <rohanrgupta1996@gmail.com>
This commit is contained in:
rohan47 committed 2018-04-25 18:24:13 +00:00
1 parent e11b3d8637
commit c80decbba8
14 files changed
+165 -140

No files matched your search

+3 -3
View File
@@ -171,17 +171,17 @@ kubectl -n rook-system logs `kubectl -n rook-system -l app=rook-operator get pod
If the volume is failing to be created, there should be details in the `rook-operator` log output, especially those tagged with `op-provisioner`.
One common cause for the `rook-operator` failing to create the volume is when the `clusterName` field of the `StorageClass` doesn't match the **namespace** of the Rook cluster, as described in [#1502](https://github.com/rook/rook/issues/1502).
One common cause for the `rook-operator` failing to create the volume is when the `clusterNamespace` field of the `StorageClass` doesn't match the **namespace** of the Rook cluster, as described in [#1502](https://github.com/rook/rook/issues/1502).
In that scenario, the `rook-operator` log would show a failure similar to the following:
```
2018-03-28 18:58:32.041603 I | op-provisioner: creating volume with configuration {pool:replicapool clusterName:rook fstype:}
2018-03-28 18:58:32.041603 I | op-provisioner: creating volume with configuration {pool:replicapool clusterNamespace:rook fstype:}
2018-03-28 18:58:32.041728 I | exec: Running command: rbd create replicapool/pvc-fd8aba49-32b9-11e8-978e-08002762c796 --size 20480 --cluster=rook --conf=/var/lib/rook/rook/rook.config --keyring=/var/lib/rook/rook/client.admin.keyring
E0328 18:58:32.060893 5 controller.go:801] Failed to provision volume for claim "default/mysql-pv-claim" with StorageClass "rook-block": Failed to create rook block image replicapool/pvc-fd8aba49-32b9-11e8-978e-08002762c796: failed to create image pvc-fd8aba49-32b9-11e8-978e-08002762c796 in pool replicapool of size 21474836480: Failed to complete '': exit status 1. global_init: unable to open config file from search list /var/lib/rook/rook/rook.config
. output:
```
The solution is to ensure that the [`clusterName`](https://github.com/rook/rook/blob/master/cluster/examples/kubernetes/rook-storageclass.yaml#L25) field matches the **namespace** of the Rook cluster when creating the `StorageClass`.
The solution is to ensure that the [`clusterNamespace`](https://github.com/rook/rook/blob/master/cluster/examples/kubernetes/rook-storageclass.yaml#L25) field matches the **namespace** of the Rook cluster when creating the `StorageClass`.
### Volume Mounting
The final step in preparing Rook storage for your pod is for the `rook-agent` pod to mount and format it.
+1 -1
View File
@@ -113,7 +113,7 @@ spec:
fsType: ceph
options:
fsName: myfs # name of the filesystem specified in the filesystem CRD.
clusterName: rook # namespace where the Rook cluster is deployed
clusterNamespace: rook # namespace where the Rook cluster is deployed
# by default the path is /, but you can override and mount a specific path of the filesystem by using the path attribute
# path: /some/path/inside/cephfs
```
@@ -19,9 +19,9 @@ metadata:
provisioner: rook.io/block
parameters:
pool: replicapool
# Specify the Rook cluster from which to create volumes.
# If not specified, it will use `rook` as the name of the cluster.
# Specify the namespace of the rook cluster from which to create volumes.
# If not specified, it will use `rook` as the default namespace of the cluster.
# This is also the namespace where the cluster will be
clusterName: rook
clusterNamespace: rook
# Specify the filesystem type of the volume. If not specified, it will use `ext4`.
# fstype: ext4
+8 -4
View File
@@ -195,15 +195,19 @@ func mountCephFS(client *rpc.Client, opts *flexvolume.AttachOptions) error {
log(client, fmt.Sprintf("mounting ceph filesystem %s on %s", opts.FsName, opts.MountDir), false)
if opts.ClusterName == "" {
return fmt.Errorf("Rook: Attach filesystem %s failed: cluster is not provided", opts.FsName)
if opts.ClusterNamespace == "" {
if opts.ClusterName == "" {
return fmt.Errorf("Rook: Attach filesystem %s failed: cluster namespace is not provided", opts.FsName)
} else {
opts.ClusterNamespace = opts.ClusterName
}
}
// Get client access info
var clientAccessInfo flexvolume.ClientAccessInfo
err := client.Call("Controller.GetClientAccessInfo", opts.ClusterName, &clientAccessInfo)
err := client.Call("Controller.GetClientAccessInfo", opts.ClusterNamespace, &clientAccessInfo)
if err != nil {
errorMsg := fmt.Sprintf("Attach filesystem %s on cluster %s failed: %v", opts.FsName, opts.ClusterName, err)
errorMsg := fmt.Sprintf("Attach filesystem %s on cluster %s failed: %v", opts.FsName, opts.ClusterNamespace, err)
log(client, errorMsg, true)
return fmt.Errorf("Rook: %v", errorMsg)
}
+22 -16
View File
@@ -88,7 +88,7 @@ func (c *Controller) Attach(attachOpts AttachOptions, devicePath *string) error
}
// No volumeattach CRD for this volume found. Create one
volumeattachObj = rookalpha.NewVolumeAttachment(crdName, namespace, node, attachOpts.PodNamespace, attachOpts.Pod,
attachOpts.ClusterName, attachOpts.MountDir, strings.ToLower(attachOpts.RW) == ReadOnly)
attachOpts.ClusterNamespace, attachOpts.MountDir, strings.ToLower(attachOpts.RW) == ReadOnly)
logger.Infof("Creating Volume attach Resource %s/%s: %+v", volumeattachObj.Namespace, volumeattachObj.Name, attachOpts)
err = c.volumeAttachment.Create(volumeattachObj)
if err != nil {
@@ -134,7 +134,7 @@ func (c *Controller) Attach(attachOpts AttachOptions, devicePath *string) error
attachment.MountDir = attachOpts.MountDir
attachment.PodNamespace = attachOpts.PodNamespace
attachment.PodName = attachOpts.Pod
attachment.ClusterName = attachOpts.ClusterName
attachment.ClusterName = attachOpts.ClusterNamespace
attachment.ReadOnly = attachOpts.RW == ReadOnly
err = c.volumeAttachment.Update(volumeattachObj)
if err != nil {
@@ -158,7 +158,7 @@ func (c *Controller) Attach(attachOpts AttachOptions, devicePath *string) error
Node: node,
PodNamespace: attachOpts.PodNamespace,
PodName: attachOpts.Pod,
ClusterName: attachOpts.ClusterName,
ClusterName: attachOpts.ClusterNamespace,
MountDir: attachOpts.MountDir,
ReadOnly: attachOpts.RW == ReadOnly,
}
@@ -170,7 +170,7 @@ func (c *Controller) Attach(attachOpts AttachOptions, devicePath *string) error
}
}
}
*devicePath, err = c.volumeManager.Attach(attachOpts.Image, attachOpts.Pool, attachOpts.ClusterName)
*devicePath, err = c.volumeManager.Attach(attachOpts.Image, attachOpts.Pool, attachOpts.ClusterNamespace)
if err != nil {
return fmt.Errorf("failed to attach volume %s/%s: %+v", attachOpts.Pool, attachOpts.Image, err)
}
@@ -187,7 +187,7 @@ func (c *Controller) DetachForce(detachOpts AttachOptions, _ *struct{} /* void r
}
func (c *Controller) doDetach(detachOpts AttachOptions, force bool) error {
err := c.volumeManager.Detach(detachOpts.Image, detachOpts.Pool, detachOpts.ClusterName, force)
err := c.volumeManager.Detach(detachOpts.Image, detachOpts.Pool, detachOpts.ClusterNamespace, force)
if err != nil {
return fmt.Errorf("Failed to detach volume %s/%s: %+v", detachOpts.Pool, detachOpts.Image, err)
}
@@ -245,18 +245,24 @@ func (c *Controller) Log(message LogMessage, _ *struct{} /* void reply */) error
return nil
}
func (c *Controller) parseClusterName(storageClassName string) (string, error) {
func (c *Controller) parseClusterNamespace(storageClassName string) (string, error) {
sc, err := c.context.Clientset.Storage().StorageClasses().Get(storageClassName, metav1.GetOptions{})
if err != nil {
return "", err
}
clusterName, ok := sc.Parameters["clusterName"]
clusterNamespace, ok := sc.Parameters["clusterNamespace"]
if !ok {
// Defaults to rook if not found
logger.Infof("clusterName not specified in the storage class %s. Defaulting to '%s'", storageClassName, cluster.DefaultClusterName)
return cluster.DefaultClusterName, nil
// Checks for older version of parameter i.e., clusterName if clusterNamespace not found
logger.Infof("clusterNamespace not specified in the storage class %s. Checking for clusterName", storageClassName)
clusterNamespace, ok := sc.Parameters["clusterName"]
if !ok {
// Defaults to rook if not found
logger.Infof("clusterNamespace not specified in the storage class %s. Defaulting to '%s'", storageClassName, cluster.DefaultClusterName)
return cluster.DefaultClusterName, nil
}
return clusterNamespace, nil
}
return clusterName, nil
return clusterNamespace, nil
}
// GetAttachInfoFromMountDir obtain pod and volume information from the mountDir. K8s does not provide
@@ -309,9 +315,9 @@ func (c *Controller) GetAttachInfoFromMountDir(mountDir string, attachOptions *A
if attachOptions.StorageClass == "" {
attachOptions.StorageClass = pv.Spec.PersistentVolumeSource.FlexVolume.Options[StorageClassKey]
}
attachOptions.ClusterName, err = c.parseClusterName(attachOptions.StorageClass)
attachOptions.ClusterNamespace, err = c.parseClusterNamespace(attachOptions.StorageClass)
if err != nil {
return fmt.Errorf("Failed to parse clusterName from storageClass %s: %+v", attachOptions.StorageClass, err)
return fmt.Errorf("Failed to parse clusterNamespace from storageClass %s: %+v", attachOptions.StorageClass, err)
}
return nil
}
@@ -324,10 +330,10 @@ func (c *Controller) GetGlobalMountPath(volumeName string, globalMountPath *stri
}
// GetClientAccessInfo obtains the cluster monitor endpoints, username and secret
func (c *Controller) GetClientAccessInfo(clusterName string, clientAccessInfo *ClientAccessInfo) error {
clusterInfo, _, _, err := mon.LoadClusterInfo(c.context, clusterName)
func (c *Controller) GetClientAccessInfo(clusterNamespace string, clientAccessInfo *ClientAccessInfo) error {
clusterInfo, _, _, err := mon.LoadClusterInfo(c.context, clusterNamespace)
if err != nil {
return fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterName, err)
return fmt.Errorf("failed to load cluster information from clusters namespace %s: %+v", clusterNamespace, err)
}
monEndpoints := make([]string, 0, len(clusterInfo.Monitors))
+54 -46
View File
@@ -57,15 +57,15 @@ func TestAttach(t *testing.T) {
devicePath := ""
opts := AttachOptions{
Image: "image123",
Pool: "testpool",
ClusterName: "testCluster",
StorageClass: "storageclass1",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "rw",
Image: "image123",
Pool: "testpool",
ClusterNamespace: "testCluster",
StorageClass: "storageclass1",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "rw",
}
att, err := attachment.New(context)
assert.Nil(t, err)
@@ -306,14 +306,14 @@ func TestMultipleAttachReadOnly(t *testing.T) {
}
opts := AttachOptions{
Image: "image123",
Pool: "testpool",
ClusterName: "testCluster",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "ro",
Image: "image123",
Pool: "testpool",
ClusterNamespace: "testCluster",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "ro",
}
existingCRD := &rookalpha.VolumeAttachment{
ObjectMeta: metav1.ObjectMeta{
@@ -382,14 +382,14 @@ func TestOrphanAttachOriginalPodDoesntExist(t *testing.T) {
}
opts := AttachOptions{
Image: "image123",
Pool: "testpool",
ClusterName: "testCluster",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "newPod",
PodNamespace: "Default",
RW: "rw",
Image: "image123",
Pool: "testpool",
ClusterNamespace: "testCluster",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "newPod",
PodNamespace: "Default",
RW: "rw",
}
existingCRD := &rookalpha.VolumeAttachment{
ObjectMeta: metav1.ObjectMeta{
@@ -490,14 +490,14 @@ func TestOrphanAttachOriginalPodNameSame(t *testing.T) {
// the pod resource is a different one but for the same pod metadata. This is reflected in the MountDir.
// The namespace and name, however, must match.
opts := AttachOptions{
Image: "image123",
Pool: "testpool",
ClusterName: "testCluster",
MountDir: "/test/pods/pod456/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "rw",
Image: "image123",
Pool: "testpool",
ClusterNamespace: "testCluster",
MountDir: "/test/pods/pod456/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "rw",
}
att, err := attachment.New(context)
@@ -547,14 +547,14 @@ func TestVolumeAttachmentExistAttach(t *testing.T) {
}
opts := AttachOptions{
Image: "image123",
Pool: "testpool",
ClusterName: "testCluster",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "rw",
Image: "image123",
Pool: "testpool",
ClusterNamespace: "testCluster",
MountDir: "/test/pods/pod123/volumes/rook.io~rook/pvc-123",
VolumeName: "pvc-123",
Pod: "myPod",
PodNamespace: "Default",
RW: "rw",
}
existingCRD := &rookalpha.VolumeAttachment{
@@ -739,7 +739,7 @@ func TestGetAttachInfoFromMountDir(t *testing.T) {
Name: "storageClass1",
},
Provisioner: "rook.io/rook",
Parameters: map[string]string{"pool": "testpool", "clusterName": "testCluster", "fsType": "ext3"},
Parameters: map[string]string{"pool": "testpool", "clusterNamespace": "testCluster", "fsType": "ext3"},
}
clientset.StorageV1().StorageClasses().Create(&sc)
@@ -775,10 +775,18 @@ func TestGetAttachInfoFromMountDir(t *testing.T) {
assert.Equal(t, "pvc-123", opts.Image)
assert.Equal(t, "pool123", opts.Pool)
assert.Equal(t, "storageClass1", opts.StorageClass)
assert.Equal(t, "testCluster", opts.ClusterName)
assert.Equal(t, "testCluster", opts.ClusterNamespace)
}
func TestParseClusterNamespace(t *testing.T) {
testParseClusterNamespace(t, "clusterNamespace")
}
func TestParseClusterName(t *testing.T) {
testParseClusterNamespace(t, "clusterName")
}
func testParseClusterNamespace(t *testing.T, namespaceParameter string) {
clientset := test.New(3)
context := &clusterd.Context{
@@ -790,7 +798,7 @@ func TestParseClusterName(t *testing.T) {
Name: "rook-storageclass",
},
Provisioner: "rook.io/rook",
Parameters: map[string]string{"pool": "testpool", "clusterName": "testCluster", "fsType": "ext3"},
Parameters: map[string]string{"pool": "testpool", namespaceParameter: "testCluster", "fsType": "ext3"},
}
clientset.StorageV1().StorageClasses().Create(&sc)
volumeAttachment, err := attachment.New(context)
@@ -800,8 +808,8 @@ func TestParseClusterName(t *testing.T) {
context: context,
volumeAttachment: volumeAttachment,
}
clusterName, _ := fc.parseClusterName("rook-storageclass")
assert.Equal(t, "testCluster", clusterName)
clusterNamespace, _ := fc.parseClusterNamespace("rook-storageclass")
assert.Equal(t, "testCluster", clusterNamespace)
}
func TestGetPodAndPVNameFromMountDir(t *testing.T) {
@@ -48,7 +48,7 @@ type devicePathFinder struct{}
// DevicePathFinder is used to find the device path after the volume has been attached
type pathFinder interface {
FindDevicePath(image, pool, clusterName string) (string, error)
FindDevicePath(image, pool, clusterNamespace string) (string, error)
}
// NewVolumeManager create attacher for ceph volumes
@@ -86,10 +86,10 @@ func (vm *VolumeManager) Init() error {
}
// Attach a ceph image to the node
func (vm *VolumeManager) Attach(image, pool, clusterName string) (string, error) {
func (vm *VolumeManager) Attach(image, pool, clusterNamespace string) (string, error) {
// check if the volume is already attached
devicePath, err := vm.isAttached(image, pool, clusterName)
devicePath, err := vm.isAttached(image, pool, clusterNamespace)
if err != nil {
return "", fmt.Errorf("failed to check if volume %s/%s is already attached: %+v", pool, image, err)
}
@@ -99,24 +99,24 @@ func (vm *VolumeManager) Attach(image, pool, clusterName string) (string, error)
}
// attach and poll until volume is mapped
logger.Infof("attaching volume %s/%s cluster %s", pool, image, clusterName)
monitors, keyring, err := getClusterInfo(vm.context, clusterName)
logger.Infof("attaching volume %s/%s cluster %s", pool, image, clusterNamespace)
monitors, keyring, err := getClusterInfo(vm.context, clusterNamespace)
defer os.Remove(keyring)
if err != nil {
return "", fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterName, err)
return "", fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterNamespace, err)
}
err = cephclient.MapImage(vm.context, image, pool, clusterName, keyring, monitors)
err = cephclient.MapImage(vm.context, image, pool, clusterNamespace, keyring, monitors)
if err != nil {
return "", fmt.Errorf("failed to map image %s/%s cluster %s. %+v", pool, image, clusterName, err)
return "", fmt.Errorf("failed to map image %s/%s cluster %s. %+v", pool, image, clusterNamespace, err)
}
// poll for device path
retryCount := 0
for {
devicePath, err := vm.devicePathFinder.FindDevicePath(image, pool, clusterName)
devicePath, err := vm.devicePathFinder.FindDevicePath(image, pool, clusterNamespace)
if err != nil {
return "", fmt.Errorf("failed to poll for mapped image %s/%s cluster %s. %+v", pool, image, clusterName, err)
return "", fmt.Errorf("failed to poll for mapped image %s/%s cluster %s. %+v", pool, image, clusterNamespace, err)
}
if devicePath != "" {
@@ -134,49 +134,49 @@ func (vm *VolumeManager) Attach(image, pool, clusterName string) (string, error)
}
// Detach the volume
func (vm *VolumeManager) Detach(image, pool, clusterName string, force bool) error {
func (vm *VolumeManager) Detach(image, pool, clusterNamespace string, force bool) error {
// check if the volume is attached
devicePath, err := vm.isAttached(image, pool, clusterName)
devicePath, err := vm.isAttached(image, pool, clusterNamespace)
if err != nil {
return fmt.Errorf("failed to check if volume %s/%s is attached cluster %s", pool, image, clusterName)
return fmt.Errorf("failed to check if volume %s/%s is attached cluster %s", pool, image, clusterNamespace)
}
if devicePath == "" {
logger.Infof("volume %s/%s is already detached cluster %s", pool, image, clusterName)
logger.Infof("volume %s/%s is already detached cluster %s", pool, image, clusterNamespace)
return nil
}
logger.Infof("detaching volume %s/%s cluster %s", pool, image, clusterName)
monitors, keyring, err := getClusterInfo(vm.context, clusterName)
logger.Infof("detaching volume %s/%s cluster %s", pool, image, clusterNamespace)
monitors, keyring, err := getClusterInfo(vm.context, clusterNamespace)
defer os.Remove(keyring)
if err != nil {
return fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterName, err)
return fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterNamespace, err)
}
err = cephclient.UnMapImage(vm.context, image, pool, clusterName, keyring, monitors, force)
err = cephclient.UnMapImage(vm.context, image, pool, clusterNamespace, keyring, monitors, force)
if err != nil {
return fmt.Errorf("failed to detach volume %s/%s cluster %s. %+v", pool, image, clusterName, err)
return fmt.Errorf("failed to detach volume %s/%s cluster %s. %+v", pool, image, clusterNamespace, err)
}
logger.Infof("detached volume %s/%s", pool, image)
return nil
}
// Check if the volume is attached
func (vm *VolumeManager) isAttached(image, pool, clusterName string) (string, error) {
devicePath, err := vm.devicePathFinder.FindDevicePath(image, pool, clusterName)
func (vm *VolumeManager) isAttached(image, pool, clusterNamespace string) (string, error) {
devicePath, err := vm.devicePathFinder.FindDevicePath(image, pool, clusterNamespace)
if err != nil {
return "", err
}
return devicePath, nil
}
func getClusterInfo(context *clusterd.Context, clusterName string) (string, string, error) {
clusterInfo, _, _, err := mon.LoadClusterInfo(context, clusterName)
func getClusterInfo(context *clusterd.Context, clusterNamespace string) (string, string, error) {
clusterInfo, _, _, err := mon.LoadClusterInfo(context, clusterNamespace)
if err != nil {
return "", "", fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterName, err)
return "", "", fmt.Errorf("failed to load cluster information from cluster %s: %+v", clusterNamespace, err)
}
// create temp keyring file
keyringFile, err := ioutil.TempFile("", clusterName+".keyring")
keyringFile, err := ioutil.TempFile("", clusterNamespace+".keyring")
if err != nil {
return "", "", err
}
@@ -194,7 +194,7 @@ func getClusterInfo(context *clusterd.Context, clusterName string) (string, stri
}
// FindDevicePath polls and wait for the mapped ceph image device to show up
func (f *devicePathFinder) FindDevicePath(image, pool, clusterName string) (string, error) {
func (f *devicePathFinder) FindDevicePath(image, pool, clusterNamespace string) (string, error) {
mappedFile, err := util.FindRBDMappedFile(image, pool, util.RBDSysBusPathDefault)
if err != nil {
return "", fmt.Errorf("failed to find mapped image: %+v", err)
@@ -39,7 +39,7 @@ type fakeDevicePathFinder struct {
called int
}
func (f *fakeDevicePathFinder) FindDevicePath(image, pool, clusterName string) (string, error) {
func (f *fakeDevicePathFinder) FindDevicePath(image, pool, clusterNamespace string) (string, error) {
response := f.response[f.called]
f.called++
return response, nil
@@ -105,7 +105,7 @@ func TestInitLoadRBDModNoSingleMajor(t *testing.T) {
func TestAttach(t *testing.T) {
clientset := test.New(3)
clusterName := "testCluster"
clusterNamespace := "testCluster"
configDir, _ := ioutil.TempDir("", "")
defer os.RemoveAll(configDir)
cm := &v1.ConfigMap{
@@ -114,12 +114,12 @@ func TestAttach(t *testing.T) {
},
}
cm.Name = "rook-ceph-mon-endpoints"
clientset.CoreV1().ConfigMaps(clusterName).Create(cm)
clientset.CoreV1().ConfigMaps(clusterNamespace).Create(cm)
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(debug bool, actionName string, command string, args ...string) (string, error) {
if strings.Contains(command, "ceph-authtool") {
cephtest.CreateConfigDir(path.Join(configDir, clusterName))
cephtest.CreateConfigDir(path.Join(configDir, clusterNamespace))
}
return "", nil
@@ -150,9 +150,9 @@ func TestAttach(t *testing.T) {
called: 0,
},
}
mon.CreateOrLoadClusterInfo(context, clusterName, &metav1.OwnerReference{})
mon.CreateOrLoadClusterInfo(context, clusterNamespace, &metav1.OwnerReference{})
devicePath, err := vm.Attach("image1", "testpool", clusterName)
devicePath, err := vm.Attach("image1", "testpool", clusterNamespace)
assert.Equal(t, "/dev/rbd3", devicePath)
assert.Nil(t, err)
}
@@ -172,7 +172,7 @@ func TestAttachAlreadyExists(t *testing.T) {
func TestDetach(t *testing.T) {
clientset := test.New(3)
clusterName := "testCluster"
clusterNamespace := "testCluster"
configDir, _ := ioutil.TempDir("", "")
defer os.RemoveAll(configDir)
cm := &v1.ConfigMap{
@@ -181,12 +181,12 @@ func TestDetach(t *testing.T) {
},
}
cm.Name = "rook-ceph-mon-endpoints"
clientset.CoreV1().ConfigMaps(clusterName).Create(cm)
clientset.CoreV1().ConfigMaps(clusterNamespace).Create(cm)
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(debug bool, actionName string, command string, args ...string) (string, error) {
if strings.Contains(command, "ceph-authtool") {
cephtest.CreateConfigDir(path.Join(configDir, clusterName))
cephtest.CreateConfigDir(path.Join(configDir, clusterNamespace))
}
return "", nil
@@ -217,8 +217,8 @@ func TestDetach(t *testing.T) {
called: 0,
},
}
mon.CreateOrLoadClusterInfo(context, clusterName, &metav1.OwnerReference{})
err := vm.Detach("image1", "testpool", clusterName, false)
mon.CreateOrLoadClusterInfo(context, clusterNamespace, &metav1.OwnerReference{})
err := vm.Detach("image1", "testpool", clusterNamespace, false)
assert.Nil(t, err)
}
+14 -13
View File
@@ -38,19 +38,20 @@ type VolumeController interface {
}
type AttachOptions struct {
Image string `json:"image"`
Pool string `json:"pool"`
ClusterName string `json:"clusterName"`
StorageClass string `json:"storageClass"`
MountDir string `json:"mountDir"`
FsName string `json:"fsName"`
Path string `json:"path"` // Path within the CephFS to mount
RW string `json:"kubernetes.io/readwrite"`
FsType string `json:"kubernetes.io/fsType"`
VolumeName string `json:"kubernetes.io/pvOrVolumeName"` // only available on 1.7
Pod string `json:"kubernetes.io/pod.name"`
PodID string `json:"kubernetes.io/pod.uid"`
PodNamespace string `json:"kubernetes.io/pod.namespace"`
Image string `json:"image"`
Pool string `json:"pool"`
ClusterNamespace string `json:"clusterNamespace"`
ClusterName string `json:"clusterName"`
StorageClass string `json:"storageClass"`
MountDir string `json:"mountDir"`
FsName string `json:"fsName"`
Path string `json:"path"` // Path within the CephFS to mount
RW string `json:"kubernetes.io/readwrite"`
FsType string `json:"kubernetes.io/fsType"`
VolumeName string `json:"kubernetes.io/pvOrVolumeName"` // only available on 1.7
Pod string `json:"kubernetes.io/pod.name"`
PodID string `json:"kubernetes.io/pod.uid"`
PodNamespace string `json:"kubernetes.io/pod.namespace"`
}
type LogMessage struct {
+8 -6
View File
@@ -52,7 +52,7 @@ type provisionerConfig struct {
pool string
// Optional: Name of the cluster. Default is `rook`
clusterName string
clusterNamespace string
// Optional: File system type used for mounting the image. Default is `ext4`
fstype string
@@ -128,7 +128,7 @@ func (p *RookVolumeProvisioner) createVolume(image, pool string, size int64) err
return fmt.Errorf("image missing required fields (image=%s, pool=%s, size=%d)", image, pool, size)
}
createdImage, err := ceph.CreateImage(p.context, p.provConfig.clusterName, image, pool, uint64(size))
createdImage, err := ceph.CreateImage(p.context, p.provConfig.clusterNamespace, image, pool, uint64(size))
if err != nil {
return fmt.Errorf("Failed to create rook block image %s/%s: %v", pool, image, err)
}
@@ -148,7 +148,7 @@ func (p *RookVolumeProvisioner) Delete(volume *v1.PersistentVolume) error {
return fmt.Errorf("Failed to delete rook block image %s/%s: %v", p.provConfig.pool, volume.Name, "PersistentVolume has no image defined for the FlexVolume")
}
name := volume.Spec.PersistentVolumeSource.FlexVolume.Options[flexvolume.ImageKey]
err := ceph.DeleteImage(p.context, p.provConfig.clusterName, name, p.provConfig.pool)
err := ceph.DeleteImage(p.context, p.provConfig.clusterNamespace, name, p.provConfig.pool)
if err != nil {
return fmt.Errorf("Failed to delete rook block image %s/%s: %v", p.provConfig.pool, volume.Name, err)
}
@@ -176,8 +176,10 @@ func parseClassParameters(params map[string]string) (*provisionerConfig, error)
switch strings.ToLower(k) {
case "pool":
cfg.pool = v
case "clusternamespace":
cfg.clusterNamespace = v
case "clustername":
cfg.clusterName = v
cfg.clusterNamespace = v
case "fstype":
cfg.fstype = v
default:
@@ -189,8 +191,8 @@ func parseClassParameters(params map[string]string) (*provisionerConfig, error)
return nil, fmt.Errorf("StorageClass for provisioner %s must contain 'pool' parameter", "rookVolumeProvisioner")
}
if len(cfg.clusterName) == 0 {
cfg.clusterName = cluster.DefaultClusterName
if len(cfg.clusterNamespace) == 0 {
cfg.clusterNamespace = cluster.DefaultClusterName
}
return &cfg, nil
+3 -3
View File
@@ -65,7 +65,7 @@ func TestProvisionImage(t *testing.T) {
}
provisioner := New(context)
volume := newVolumeOptions(newStorageClass("class-1", "rook.io/block", map[string]string{"pool": "testpool", "clusterName": "testCluster", "fsType": "ext3"}), newClaim("claim-1", "uid-1-1", "class-1", "", "class-1", nil))
volume := newVolumeOptions(newStorageClass("class-1", "rook.io/block", map[string]string{"pool": "testpool", "clusterNamespace": "testCluster", "fsType": "ext3"}), newClaim("claim-1", "uid-1-1", "class-1", "", "class-1", nil))
pv, err := provisioner.Provision(volume)
assert.Nil(t, err)
@@ -89,7 +89,7 @@ func TestParseClassParameters(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, "testPool", provConfig.pool)
assert.Equal(t, "myname", provConfig.clusterName)
assert.Equal(t, "myname", provConfig.clusterNamespace)
assert.Equal(t, "ext4", provConfig.fstype)
}
@@ -101,7 +101,7 @@ func TestParseClassParametersDefault(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, "testPool", provConfig.pool)
assert.Equal(t, "rook", provConfig.clusterName)
assert.Equal(t, "rook", provConfig.clusterNamespace)
assert.Equal(t, "", provConfig.fstype)
}
+8 -4
View File
@@ -19,7 +19,11 @@ spec:
size: ` + replicaSize
}
func GetBlockStorageClassDef(poolName string, storageClassName string, namespace string) string {
func GetBlockStorageClassDef(poolName string, storageClassName string, namespace string, varClusterName bool) string {
namespaceParameter := "clusterNamespace"
if varClusterName {
namespaceParameter = "clusterName"
}
return `apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
@@ -27,7 +31,7 @@ metadata:
provisioner: rook.io/block
parameters:
pool: ` + poolName + `
clusterName: ` + namespace
` + namespaceParameter + `: ` + namespace
}
func GetBlockPvcDef(claimName string, storageClassName string, accessModes string) string {
@@ -53,9 +57,9 @@ func concatYaml(first, second string) string {
func GetBlockPoolStorageClassAndPvcDef(namespace string, poolName string, storageClassName string, blockName string, accessMode string) string {
return concatYaml(GetBlockPoolDef(poolName, namespace, "1"),
concatYaml(GetBlockStorageClassDef(poolName, storageClassName, namespace), GetBlockPvcDef(blockName, storageClassName, accessMode)))
concatYaml(GetBlockStorageClassDef(poolName, storageClassName, namespace, false), GetBlockPvcDef(blockName, storageClassName, accessMode)))
}
func GetBlockPoolStorageClass(namespace string, poolName string, storageClassName string) string {
return concatYaml(GetBlockPoolDef(poolName, namespace, "1"), GetBlockStorageClassDef(poolName, storageClassName, namespace))
return concatYaml(GetBlockPoolDef(poolName, namespace, "1"), GetBlockStorageClassDef(poolName, storageClassName, namespace, false))
}
@@ -109,7 +109,7 @@ func (s *BlockCreateSuite) TestCreateSamePVCTwice() {
result0, err0 := s.testClient.PoolClient.Create(pool, s.namespace)
require.Contains(s.T(), result0, fmt.Sprintf("pool \"%s\" created", poolName), "Make sure test pool is created")
require.NoError(s.T(), err0)
result1, err1 := installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace), "create")
result1, err1 := installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace, true), "create")
require.Contains(s.T(), result1, fmt.Sprintf("storageclass \"%s\" created", storageClassName), "Make sure storageclass is created")
require.NoError(s.T(), err1)
@@ -205,7 +205,7 @@ func (s *BlockCreateSuite) statefulSetDataCleanup(namespace, poolName, storageCl
func (s *BlockCreateSuite) tearDownTest(claimName string, poolName string, storageClassName string, accessMode string) {
installer.BlockResourceOperation(s.kh, installer.GetBlockPvcDef(claimName, storageClassName, accessMode), "delete")
installer.BlockResourceOperation(s.kh, installer.GetBlockPoolDef(poolName, s.namespace, "1"), "delete")
installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace), "delete")
installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace, true), "delete")
}
@@ -224,7 +224,7 @@ func (s *BlockCreateSuite) CheckCreatingPVC(pvcName, pvcAccessMode string) {
result0, err0 := installer.BlockResourceOperation(s.kh, installer.GetBlockPoolDef(poolName, s.namespace, "1"), "create")
require.Contains(s.T(), result0, fmt.Sprintf("pool \"%s\" created", poolName), "Make sure test pool is created")
require.NoError(s.T(), err0)
result1, err1 := installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace), "create")
result1, err1 := installer.BlockResourceOperation(s.kh, installer.GetBlockStorageClassDef(poolName, storageClassName, s.namespace, true), "create")
require.Contains(s.T(), result1, fmt.Sprintf("storageclass \"%s\" created", storageClassName), "Make sure storageclass is created")
require.NoError(s.T(), err1)
+1 -1
View File
@@ -23,7 +23,7 @@ func createStorageClassAndPool(t func() *testing.T, kh *utils.K8sHelper, namespa
logger.Infof("Install pool and storage class for rook block")
_, err := installer.BlockResourceOperation(kh, installer.GetBlockPoolDef(poolName, namespace, "3"), "create")
require.NoError(t(), err)
_, err = installer.BlockResourceOperation(kh, installer.GetBlockStorageClassDef(poolName, storageClassName, namespace), "create")
_, err = installer.BlockResourceOperation(kh, installer.GetBlockStorageClassDef(poolName, storageClassName, namespace, false), "create")
require.NoError(t(), err)
//make sure storageclass is created