From df22d00354ba9d002360dffed5b047d0dc73b815 Mon Sep 17 00:00:00 2001 From: Praveen M Date: Wed, 23 Oct 2024 13:39:19 +0530 Subject: [PATCH] ci: script to deploy ceph-csi via ceph-csi-operator Signed-off-by: Praveen M --- build.env | 3 + scripts/deploy-ceph-csi-operator.sh | 143 ++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100755 scripts/deploy-ceph-csi-operator.sh diff --git a/build.env b/build.env index f25018ad3..ecbb2818b 100644 --- a/build.env +++ b/build.env @@ -14,6 +14,9 @@ CSI_IMAGE_VERSION=canary # cephcsi upgrade version CSI_UPGRADE_VERSION=v3.12.1 +# ceph-csi-operator version used for e2e test +CEPH_CSI_OPERATOR_VERSION=v0.2.0 + # Ceph version to use BASE_IMAGE=quay.io/ceph/ceph:v19 CEPH_VERSION=squid diff --git a/scripts/deploy-ceph-csi-operator.sh b/scripts/deploy-ceph-csi-operator.sh new file mode 100755 index 000000000..4993c033c --- /dev/null +++ b/scripts/deploy-ceph-csi-operator.sh @@ -0,0 +1,143 @@ +#!/bin/bash -E + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +# shellcheck disable=SC1091 +[ ! -e "${SCRIPT_DIR}"/utils.sh ] || source "${SCRIPT_DIR}"/utils.sh + +# shellcheck disable=SC1091 +source "${SCRIPT_DIR}/../build.env" + +OPERATOR_VERSION=${OPERATOR_VERSION:-"main"} +OPERATOR_URL="https://raw.githubusercontent.com/ceph/ceph-csi-operator/${OPERATOR_VERSION}" + +# operator deployment files +OPERATOR_INSTALL="${OPERATOR_URL}/deploy/all-in-one/install.yaml" + +OPERATOR_NAMESPACE="ceph-csi-operator-system" +IMAGESET_CONFIGMAP_NAME="ceph-csi-imageset" +ENCRYPTION_CONFIGMAP_NAME="ceph-csi-encryption-kms-config" + +# csi drivers +RBD_DRIVER_NAME="rbd.csi.ceph.com" +CEPHFS_DRIVER_NAME="cephfs.csi.ceph.com" +NFS_DRIVER_NAME="nfs.csi.ceph.com" + +# k8s csi sidecar image +K8S_IMAGE_REPO=${K8S_IMAGE_REPO:-"registry.k8s.io/sig-storage"} + +TEMP_DIR="$(mktemp -d)" +trap 'rm -rf "$TEMP_DIR"' EXIT + +function create_or_delete_imageset_configmap() { + local operation=$1 + temp_file=$(mktemp "${TEMP_DIR}/imageset-configmap.XXXXXX.yaml") + cat <"${temp_file}" +apiVersion: v1 +kind: ConfigMap +metadata: + name: ${IMAGESET_CONFIGMAP_NAME} + namespace: ${OPERATOR_NAMESPACE} +data: + "plugin": "quay.io/cephcsi/cephcsi:canary" # test image + "attacher": "${K8S_IMAGE_REPO}/csi-attacher:${CSI_ATTACHER_VERSION}" + "snapshotter": "${K8S_IMAGE_REPO}/csi-snapshotter:${CSI_SNAPSHOTTER_VERSION}" + "provisioner": "${K8S_IMAGE_REPO}/csi-provisioner:${CSI_PROVISIONER_VERSION}" + "registrar": "${K8S_IMAGE_REPO}/csi-node-driver-registrar:${CSI_NODE_DRIVER_REGISTRAR_VERSION}" + "resizer": "${K8S_IMAGE_REPO}/csi-resizer:${CSI_RESIZER_VERSION}" +EOF + kubectl_retry "$operation" -f "${temp_file}" +} + +function create_or_delete_encryption_configmap() { + local operation=$1 + temp_file=$(mktemp "${TEMP_DIR}/encryption-configmap.XXXXXX.yaml") + cat <"${temp_file}" +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: ${OPERATOR_NAMESPACE} + name: ${ENCRYPTION_CONFIGMAP_NAME} +data: + config.json: "" +EOF + kubectl_retry "$operation" -f "${temp_file}" +} + +function create_or_delete_operator_config() { + # TODO: encryption config + local operation=$1 + create_or_delete_imageset_configmap "$operation" + create_or_delete_encryption_configmap "$operation" + + temp_file=$(mktemp "${TEMP_DIR}/operatorconfig.XXXXXX.yaml") + cat <"${temp_file}" +apiVersion: csi.ceph.io/v1alpha1 +kind: OperatorConfig +metadata: + name: ceph-csi-operator-config + namespace: ${OPERATOR_NAMESPACE} +spec: + driverSpecDefaults: + snapshotPolicy: volumeGroupSnapshot + controllerPlugin: + deploymentStrategy: + type: Recreate + generateOMapInfo: true + enableMetadata: true + log: + verbosity: 5 # csi pods log level + imageSet: + name: ${IMAGESET_CONFIGMAP_NAME} + encryption: + configMapName: + name: ${ENCRYPTION_CONFIGMAP_NAME} + log: + verbosity: 3 # operator log level +EOF + kubectl_retry "$operation" -f "${temp_file}" +} + +function deploy_or_delete_driver() { + local operator=$1 + local driver_name=$2 + temp_file=$(mktemp "${TEMP_DIR}/${driver_name}.XXXXXX.yaml") + cat <"${temp_file}" +apiVersion: csi.ceph.io/v1alpha1 +kind: Driver +metadata: + name: ${driver_name} + namespace: ${OPERATOR_NAMESPACE} +EOF + kubectl_retry "$operator" -f "${temp_file}" +} + +function deploy_operator() { + kubectl_retry create -f "${OPERATOR_INSTALL}" + create_or_delete_operator_config "create" + deploy_or_delete_driver "create" $RBD_DRIVER_NAME + deploy_or_delete_driver "create" $CEPHFS_DRIVER_NAME + deploy_or_delete_driver "create" $NFS_DRIVER_NAME +} + +function cleanup() { + deploy_or_delete_driver "delete" $RBD_DRIVER_NAME + deploy_or_delete_driver "delete" $CEPHFS_DRIVER_NAME + deploy_or_delete_driver "delete" $NFS_DRIVER_NAME + create_or_delete_operator_config "delete" + kubectl_retry "delete" -f "${OPERATOR_INSTALL}" +} + +case "${1:-}" in +deploy) + deploy_operator + ;; +cleanup) + cleanup + ;; +*) + echo "Usage:" >&2 + echo " $0 deploy" >&2 + echo " $0 cleanup" >&2 + exit 1 + ;; +esac