mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-03-06 15:39:29 +00:00
144 lines
4.1 KiB
Bash
Executable File
144 lines
4.1 KiB
Bash
Executable File
#!/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 <<EOF >"${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 <<EOF >"${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 <<EOF >"${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 <<EOF >"${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
|