external: add support for rados namespace for external cluster
change the json output of storageclass to also inclusde rados namespace, and also added the changes in the csi secret Signed-off-by: parth-gr <paarora@redhat.com>
This commit is contained in:
1 parent
4e58be48c3
commit
df7c401d35
4 files changed
+122
-19
No files matched your search
@@ -146,8 +146,8 @@ jobs:
|
||||
run: |
|
||||
toolbox=$(kubectl get pod -l app=rook-ceph-tools -n rook-ceph -o jsonpath='{.items[*].metadata.name}')
|
||||
# create `radosNamespace1` rados-namespace for `replicapool` rbd data-pool
|
||||
kubectl -n rook-ceph exec $toolbox -- rbd namespace create replicapool/radosNamespace1
|
||||
kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool --rados-namespace radosNamespace1
|
||||
kubectl -n rook-ceph exec $toolbox -- rbd namespace create replicapool/radosnamespace1
|
||||
kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool --rados-namespace radosnamespace1
|
||||
# test the rados namespace which not exit for replicapool(false testing)
|
||||
if output=$(kubectl -n rook-ceph exec $toolbox -- python3 /etc/ceph/create-external-cluster-resources.py --rbd-data-pool-name replicapool --rados-namespace false-test-namespace); then
|
||||
echo "unexpectedly succeeded after passing the wrong rados namespace: $output"
|
||||
|
||||
@@ -52,7 +52,7 @@ python3 create-external-cluster-resources.py --rbd-data-pool-name <pool_name> --
|
||||
* `--cephfs-metadata-pool-name`: (optional) Provides the name of the cephfs metadata pool
|
||||
* `--cephfs-filesystem-name`: (optional) The name of the filesystem, used for creating CephFS StorageClass
|
||||
* `--cephfs-data-pool-name`: (optional) Provides the name of the CephFS data pool, used for creating CephFS StorageClass
|
||||
* `--rados-namespace`: (optional) Divides a pool into separate logical namespaces, used for creating RBD PVC in a RadosNamespaces
|
||||
* `--rados-namespace`: (optional) Divides a pool into separate logical namespaces, used for creating RBD PVC in a CephBlockPoolRadosNamespace (should be lower case)
|
||||
* `--subvolume-group`: (optional) Provides the name of the subvolume group, used for creating CephFS PVC in a subvolumeGroup
|
||||
* `--rgw-realm-name`: (optional) Provides the name of the rgw-realm
|
||||
* `--rgw-zone-name`: (optional) Provides the name of the rgw-zone
|
||||
|
||||
@@ -444,7 +444,7 @@ class RadosJSON:
|
||||
"--rados-namespace",
|
||||
default="",
|
||||
required=False,
|
||||
help="divides a pool into separate logical namespaces",
|
||||
help="Divides a pool into separate logical namespaces, used for creating RBD PVC in a CephBlockPoolRadosNamespace (should be lower case)",
|
||||
)
|
||||
output_group.add_argument(
|
||||
"--subvolume-group",
|
||||
@@ -893,7 +893,14 @@ class RadosJSON:
|
||||
|
||||
return caps, entity
|
||||
|
||||
def get_entity(self, entity, rbd_pool_name, alias_rbd_pool_name, k8s_cluster_name):
|
||||
def get_entity(
|
||||
self,
|
||||
entity,
|
||||
rbd_pool_name,
|
||||
alias_rbd_pool_name,
|
||||
k8s_cluster_name,
|
||||
rados_namespace,
|
||||
):
|
||||
if (
|
||||
rbd_pool_name.count(".") != 0
|
||||
or rbd_pool_name.count("_") != 0
|
||||
@@ -915,6 +922,8 @@ class RadosJSON:
|
||||
else:
|
||||
entity = f"{entity}-{k8s_cluster_name}-{rbd_pool_name}"
|
||||
|
||||
if rados_namespace:
|
||||
entity = f"{entity}-{rados_namespace}"
|
||||
return entity
|
||||
|
||||
def get_rbd_provisioner_caps_and_entity(self):
|
||||
@@ -928,6 +937,7 @@ class RadosJSON:
|
||||
rbd_pool_name = self._arg_parser.rbd_data_pool_name
|
||||
alias_rbd_pool_name = self._arg_parser.alias_rbd_data_pool_name
|
||||
k8s_cluster_name = self._arg_parser.k8s_cluster_name
|
||||
rados_namespace = self._arg_parser.rados_namespace
|
||||
if rbd_pool_name == "":
|
||||
raise ExecutionFailureException(
|
||||
"mandatory flag not found, please set the '--rbd-data-pool-name' flag"
|
||||
@@ -937,9 +947,18 @@ class RadosJSON:
|
||||
"mandatory flag not found, please set the '--k8s-cluster-name' flag"
|
||||
)
|
||||
entity = self.get_entity(
|
||||
entity, rbd_pool_name, alias_rbd_pool_name, k8s_cluster_name
|
||||
entity,
|
||||
rbd_pool_name,
|
||||
alias_rbd_pool_name,
|
||||
k8s_cluster_name,
|
||||
rados_namespace,
|
||||
)
|
||||
caps["osd"] = f"profile rbd pool={rbd_pool_name}"
|
||||
if rados_namespace != "":
|
||||
caps[
|
||||
"osd"
|
||||
] = f"profile rbd pool={rbd_pool_name} namespace={rados_namespace}"
|
||||
else:
|
||||
caps["osd"] = f"profile rbd pool={rbd_pool_name}"
|
||||
|
||||
return caps, entity
|
||||
|
||||
@@ -953,6 +972,7 @@ class RadosJSON:
|
||||
rbd_pool_name = self._arg_parser.rbd_data_pool_name
|
||||
alias_rbd_pool_name = self._arg_parser.alias_rbd_data_pool_name
|
||||
k8s_cluster_name = self._arg_parser.k8s_cluster_name
|
||||
rados_namespace = self._arg_parser.rados_namespace
|
||||
if rbd_pool_name == "":
|
||||
raise ExecutionFailureException(
|
||||
"mandatory flag not found, please set the '--rbd-data-pool-name' flag"
|
||||
@@ -962,9 +982,18 @@ class RadosJSON:
|
||||
"mandatory flag not found, please set the '--k8s-cluster-name' flag"
|
||||
)
|
||||
entity = self.get_entity(
|
||||
entity, rbd_pool_name, alias_rbd_pool_name, k8s_cluster_name
|
||||
entity,
|
||||
rbd_pool_name,
|
||||
alias_rbd_pool_name,
|
||||
k8s_cluster_name,
|
||||
rados_namespace,
|
||||
)
|
||||
caps["osd"] = f"profile rbd pool={rbd_pool_name}"
|
||||
if rados_namespace != "":
|
||||
caps[
|
||||
"osd"
|
||||
] = f"profile rbd pool={rbd_pool_name} namespace={rados_namespace}"
|
||||
else:
|
||||
caps["osd"] = f"profile rbd pool={rbd_pool_name}"
|
||||
|
||||
return caps, entity
|
||||
|
||||
@@ -1315,6 +1344,11 @@ class RadosJSON:
|
||||
rados_namespace = self._arg_parser.rados_namespace
|
||||
if rados_namespace == "":
|
||||
return
|
||||
if rados_namespace.islower() == False:
|
||||
raise ExecutionFailureException(
|
||||
f"The provided rados Namespace, '{rados_namespace}', "
|
||||
f"contains upper case"
|
||||
)
|
||||
rbd_inst = rbd.RBD()
|
||||
ioctx = self.cluster.open_ioctx(rbd_pool_name)
|
||||
if rbd_inst.namespace_exists(ioctx, rados_namespace) is False:
|
||||
@@ -1731,24 +1765,25 @@ class RadosJSON:
|
||||
},
|
||||
}
|
||||
)
|
||||
if self.out_map["RBD_METADATA_EC_POOL_NAME"]:
|
||||
# if 'RADOS_NAMESPACE' exists, then only add the "RADOS_NAMESPACE" namespace
|
||||
if (
|
||||
self.out_map["RADOS_NAMESPACE"]
|
||||
and self.out_map["RESTRICTED_AUTH_PERMISSION"]
|
||||
and not self.out_map["RBD_METADATA_EC_POOL_NAME"]
|
||||
):
|
||||
json_out.append(
|
||||
{
|
||||
"name": "ceph-rbd",
|
||||
"kind": "StorageClass",
|
||||
"name": "rados-namespace",
|
||||
"kind": "CephBlockPoolRadosNamespace",
|
||||
"data": {
|
||||
"dataPool": self.out_map["RBD_POOL_NAME"],
|
||||
"pool": self.out_map["RBD_METADATA_EC_POOL_NAME"],
|
||||
"csi.storage.k8s.io/provisioner-secret-name": f"rook-{self.out_map['CSI_RBD_PROVISIONER_SECRET_NAME']}",
|
||||
"csi.storage.k8s.io/controller-expand-secret-name": f"rook-{self.out_map['CSI_RBD_PROVISIONER_SECRET_NAME']}",
|
||||
"csi.storage.k8s.io/node-stage-secret-name": f"rook-{self.out_map['CSI_RBD_NODE_SECRET_NAME']}",
|
||||
"radosNamespaceName": self.out_map["RADOS_NAMESPACE"],
|
||||
"pool": self.out_map["RBD_POOL_NAME"],
|
||||
},
|
||||
}
|
||||
)
|
||||
else:
|
||||
json_out.append(
|
||||
{
|
||||
"name": "ceph-rbd",
|
||||
"name": "ceph-rbd-rados-namespace",
|
||||
"kind": "StorageClass",
|
||||
"data": {
|
||||
"pool": self.out_map["RBD_POOL_NAME"],
|
||||
@@ -1758,6 +1793,35 @@ class RadosJSON:
|
||||
},
|
||||
}
|
||||
)
|
||||
else:
|
||||
if self.out_map["RBD_METADATA_EC_POOL_NAME"]:
|
||||
json_out.append(
|
||||
{
|
||||
"name": "ceph-rbd",
|
||||
"kind": "StorageClass",
|
||||
"data": {
|
||||
"dataPool": self.out_map["RBD_POOL_NAME"],
|
||||
"pool": self.out_map["RBD_METADATA_EC_POOL_NAME"],
|
||||
"csi.storage.k8s.io/provisioner-secret-name": f"rook-{self.out_map['CSI_RBD_PROVISIONER_SECRET_NAME']}",
|
||||
"csi.storage.k8s.io/controller-expand-secret-name": f"rook-{self.out_map['CSI_RBD_PROVISIONER_SECRET_NAME']}",
|
||||
"csi.storage.k8s.io/node-stage-secret-name": f"rook-{self.out_map['CSI_RBD_NODE_SECRET_NAME']}",
|
||||
},
|
||||
}
|
||||
)
|
||||
else:
|
||||
json_out.append(
|
||||
{
|
||||
"name": "ceph-rbd",
|
||||
"kind": "StorageClass",
|
||||
"data": {
|
||||
"pool": self.out_map["RBD_POOL_NAME"],
|
||||
"csi.storage.k8s.io/provisioner-secret-name": f"rook-{self.out_map['CSI_RBD_PROVISIONER_SECRET_NAME']}",
|
||||
"csi.storage.k8s.io/controller-expand-secret-name": f"rook-{self.out_map['CSI_RBD_PROVISIONER_SECRET_NAME']}",
|
||||
"csi.storage.k8s.io/node-stage-secret-name": f"rook-{self.out_map['CSI_RBD_NODE_SECRET_NAME']}",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
# if 'CEPHFS_FS_NAME' exists, then only add 'cephfs' StorageClass
|
||||
if self.out_map["CEPHFS_FS_NAME"]:
|
||||
json_out.append(
|
||||
|
||||
@@ -78,11 +78,50 @@ function createClusterNamespace() {
|
||||
fi
|
||||
}
|
||||
|
||||
function createRadosNamespaceCR() {
|
||||
if ! kubectl -n "$NAMESPACE" get CephBlockPoolRadosNamespace $RADOS_NAMESPACE &>/dev/null; then
|
||||
cat <<eof | kubectl create -f -
|
||||
apiVersion: ceph.rook.io/v1
|
||||
kind: CephBlockPoolRadosNamespace
|
||||
metadata:
|
||||
name: $RADOS_NAMESPACE
|
||||
namespace: $NAMESPACE # namespace:cluster
|
||||
spec:
|
||||
# blockPoolName is the name of the CephBlockPool CR where the namespace will be created.
|
||||
blockPoolName: $RBD_POOL_NAME
|
||||
eof
|
||||
else
|
||||
echo "radosnamespace $RADOS_NAMESPACE already exists"
|
||||
fi
|
||||
}
|
||||
|
||||
function createSubvolumeGroupCR() {
|
||||
if ! kubectl -n "$NAMESPACE" get CephFilesystemSubVolumeGroup $SUBVOLUME_GROUP &>/dev/null; then
|
||||
cat <<eof | kubectl create -f -
|
||||
---
|
||||
apiVersion: ceph.rook.io/v1
|
||||
kind: CephFilesystemSubVolumeGroup
|
||||
metadata:
|
||||
name: $SUBVOLUME_GROUP
|
||||
namespace: $NAMESPACE # namespace:cluster
|
||||
spec:
|
||||
# filesystemName is the metadata name of the CephFilesystem CR where the subvolume group will be created
|
||||
filesystemName: $CEPHFS_FS_NAME
|
||||
eof
|
||||
else
|
||||
echo "subvolumegroup $SUBVOLUME_GROUP already exists"
|
||||
fi
|
||||
}
|
||||
|
||||
function importClusterID() {
|
||||
if [ -n "$RADOS_NAMESPACE" ]; then
|
||||
createRadosNamespaceCR
|
||||
timeout 20 sh -c "until [ $(kubectl -n "$NAMESPACE" get CephBlockPoolRadosNamespace/"$RADOS_NAMESPACE" -o jsonpath='{.status.phase}' | grep -c "Ready") -eq 1 ]; do echo "waiting for radosNamespace to get created" && sleep 1; done"
|
||||
CLUSTER_ID_RBD=$(kubectl -n "$NAMESPACE" get cephblockpoolradosnamespace.ceph.rook.io/"$RADOS_NAMESPACE" -o jsonpath='{.status.info.clusterID}')
|
||||
fi
|
||||
if [ -n "$SUBVOLUME_GROUP" ]; then
|
||||
createSubvolumeGroupCR
|
||||
timeout 20 sh -c "until [ $(kubectl -n "$NAMESPACE" get CephFilesystemSubVolumeGroup/"$SUBVOLUME_GROUP" -o jsonpath='{.status.phase}' | grep -c "Ready") -eq 1 ]; do echo "waiting for radosNamespace to get created" && sleep 1; done"
|
||||
CLUSTER_ID_CEPHFS=$(kubectl -n "$NAMESPACE" get cephfilesystemsubvolumegroup.ceph.rook.io/"$SUBVOLUME_GROUP" -o jsonpath='{.status.info.clusterID}')
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user