Skip to content

Commit

Permalink
Merge pull request rook#12973 from raghavendra-talur/rtalur-support-c…
Browse files Browse the repository at this point in the history
…ontext

import-external-cluster.sh: allow specifying the kubernetes context
  • Loading branch information
subhamkrai authored Feb 12, 2024
2 parents b5eeb5d + cb702d3 commit a2ba8da
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
11 changes: 10 additions & 1 deletion Documentation/CRDs/Cluster/external-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ export RGW_POOL_PREFIX=default

1. Paste the above output from `create-external-cluster-resources.py` into your current shell to allow importing the source data.

2. Run the [import](https://github.com/rook/rook/blob/master/deploy/examples/import-external-cluster.sh) script.
1. The import script in the next step uses the current kubeconfig context by
default. If you want to specify the kubernetes cluster to use without
changing the current context, you can specify the cluster name by setting
the KUBECONTEXT environment variable.

```console
export KUBECONTEXT=hub-cluster
```

1. Run the [import](https://github.com/rook/rook/blob/master/deploy/examples/import-external-cluster.sh) script.

!!! note
If your Rook cluster nodes are running a kernel earlier than or equivalent to 5.4, remove
Expand Down
66 changes: 36 additions & 30 deletions deploy/examples/import-external-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ function checkEnvVars() {
echo "Providing both ROOK_EXTERNAL_ADMIN_SECRET and ROOK_EXTERNAL_USER_SECRET is not supported, choose one only."
exit 1
fi
if [ -n "$KUBECONTEXT" ]; then
echo "Using $KUBECONTEXT as the context value for kubectl commands"
KUBECTL="kubectl --context=$KUBECONTEXT"
else
KUBECTL="kubectl"
fi
}

function createClusterNamespace() {
if ! kubectl get namespace "$NAMESPACE" &>/dev/null; then
kubectl \
if ! $KUBECTL get namespace "$NAMESPACE" &>/dev/null; then
$KUBECTL \
create \
namespace \
"$NAMESPACE"
Expand All @@ -80,8 +86,8 @@ function createClusterNamespace() {
}

function createRadosNamespaceCR() {
if ! kubectl -n "$NAMESPACE" get CephBlockPoolRadosNamespace $RADOS_NAMESPACE &>/dev/null; then
cat <<eof | kubectl create -f -
if ! $KUBECTL -n "$NAMESPACE" get CephBlockPoolRadosNamespace $RADOS_NAMESPACE &>/dev/null; then
cat <<eof | $KUBECTL create -f -
apiVersion: ceph.rook.io/v1
kind: CephBlockPoolRadosNamespace
metadata:
Expand All @@ -97,8 +103,8 @@ eof
}

function createSubvolumeGroupCR() {
if ! kubectl -n "$NAMESPACE" get CephFilesystemSubVolumeGroup $SUBVOLUME_GROUP &>/dev/null; then
cat <<eof | kubectl create -f -
if ! $KUBECTL -n "$NAMESPACE" get CephFilesystemSubVolumeGroup $SUBVOLUME_GROUP &>/dev/null; then
cat <<eof | $KUBECTL create -f -
---
apiVersion: ceph.rook.io/v1
kind: CephFilesystemSubVolumeGroup
Expand All @@ -117,19 +123,19 @@ eof
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}')
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}')
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
}

function importSecret() {
if ! kubectl -n "$NAMESPACE" get secret "$MON_SECRET_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get secret "$MON_SECRET_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
secret \
generic \
Expand All @@ -147,8 +153,8 @@ function importSecret() {
}

function importConfigMap() {
if ! kubectl -n "$NAMESPACE" get configmap "$MON_ENDPOINT_CONFIGMAP_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get configmap "$MON_ENDPOINT_CONFIGMAP_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
configmap \
"$MON_ENDPOINT_CONFIGMAP_NAME" \
Expand All @@ -161,8 +167,8 @@ function importConfigMap() {
}

function importCsiRBDNodeSecret() {
if ! kubectl -n "$NAMESPACE" get secret "rook-$CSI_RBD_NODE_SECRET_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get secret "rook-$CSI_RBD_NODE_SECRET_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
secret \
generic \
Expand All @@ -176,8 +182,8 @@ function importCsiRBDNodeSecret() {
}

function importCsiRBDProvisionerSecret() {
if ! kubectl -n "$NAMESPACE" get secret "rook-$CSI_RBD_PROVISIONER_SECRET_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get secret "rook-$CSI_RBD_PROVISIONER_SECRET_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
secret \
generic \
Expand All @@ -191,8 +197,8 @@ function importCsiRBDProvisionerSecret() {
}

function importCsiCephFSNodeSecret() {
if ! kubectl -n "$NAMESPACE" get secret "rook-$CSI_CEPHFS_NODE_SECRET_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get secret "rook-$CSI_CEPHFS_NODE_SECRET_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
secret \
generic \
Expand All @@ -206,8 +212,8 @@ function importCsiCephFSNodeSecret() {
}

function importCsiCephFSProvisionerSecret() {
if ! kubectl -n "$NAMESPACE" get secret "rook-$CSI_CEPHFS_PROVISIONER_SECRET_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get secret "rook-$CSI_CEPHFS_PROVISIONER_SECRET_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
secret \
generic \
Expand All @@ -221,8 +227,8 @@ function importCsiCephFSProvisionerSecret() {
}

function importRGWAdminOpsUser() {
if ! kubectl -n "$NAMESPACE" get secret "$RGW_ADMIN_OPS_USER_SECRET_NAME" &>/dev/null; then
kubectl -n "$NAMESPACE" \
if ! $KUBECTL -n "$NAMESPACE" get secret "$RGW_ADMIN_OPS_USER_SECRET_NAME" &>/dev/null; then
$KUBECTL -n "$NAMESPACE" \
create \
secret \
generic \
Expand All @@ -236,8 +242,8 @@ function importRGWAdminOpsUser() {
}

function createECRBDStorageClass() {
if ! kubectl -n "$NAMESPACE" get storageclass $RBD_STORAGE_CLASS_NAME &>/dev/null; then
cat <<eof | kubectl create -f -
if ! $KUBECTL -n "$NAMESPACE" get storageclass $RBD_STORAGE_CLASS_NAME &>/dev/null; then
cat <<eof | $KUBECTL create -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
Expand Down Expand Up @@ -265,8 +271,8 @@ eof
}

function createRBDStorageClass() {
if ! kubectl -n "$NAMESPACE" get storageclass $RBD_STORAGE_CLASS_NAME &>/dev/null; then
cat <<eof | kubectl create -f -
if ! $KUBECTL -n "$NAMESPACE" get storageclass $RBD_STORAGE_CLASS_NAME &>/dev/null; then
cat <<eof | $KUBECTL create -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
Expand All @@ -293,8 +299,8 @@ eof
}

function createCephFSStorageClass() {
if ! kubectl -n "$NAMESPACE" get storageclass $CEPHFS_STORAGE_CLASS_NAME &>/dev/null; then
cat <<eof | kubectl create -f -
if ! $KUBECTL -n "$NAMESPACE" get storageclass $CEPHFS_STORAGE_CLASS_NAME &>/dev/null; then
cat <<eof | $KUBECTL create -f -
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
Expand Down

0 comments on commit a2ba8da

Please sign in to comment.