From 33738a3a79e1a6b4d66862b24390d5b6323401c7 Mon Sep 17 00:00:00 2001 From: Joe Borg Date: Tue, 18 Jan 2022 06:32:46 -0500 Subject: [PATCH] Deprecate storage addon (#2833) * Replace 'storage' with 'hostpath-storage' --- .../actions/disable.hostpath-storage.sh | 23 +++++++++++++++ .../actions/disable.registry.sh | 2 +- microk8s-resources/actions/disable.storage.sh | 19 ++----------- .../actions/enable.hostpath-storage.sh | 28 +++++++++++++++++++ .../actions/enable.portainer.sh | 4 +-- microk8s-resources/actions/enable.registry.sh | 4 +-- microk8s-resources/actions/enable.storage.sh | 16 ++--------- microk8s-resources/wrappers/addon-lists.yaml | 2 +- .../wrappers/microk8s-join.wrapper | 10 +++++-- .../wrappers/microk8s-reset.wrapper | 2 +- tests/test-addons.py | 10 +++---- 11 files changed, 77 insertions(+), 43 deletions(-) create mode 100755 microk8s-resources/actions/disable.hostpath-storage.sh create mode 100755 microk8s-resources/actions/enable.hostpath-storage.sh diff --git a/microk8s-resources/actions/disable.hostpath-storage.sh b/microk8s-resources/actions/disable.hostpath-storage.sh new file mode 100755 index 00000000000..e20c0ee3727 --- /dev/null +++ b/microk8s-resources/actions/disable.hostpath-storage.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -e + +source $SNAP/actions/common/utils.sh + +echo "Disabling hostpath storage." +read -ra ARGUMENTS <<< "$1" + +declare -A map +map[\$SNAP_COMMON]="$SNAP_COMMON" +use_manifest storage delete "$(declare -p map)" +sleep 5 +echo "Storage removed." +if [ ! -z "${ARGUMENTS[@]}" ] && [ "${ARGUMENTS[@]}" = "destroy-storage" ] +then + run_with_sudo rm -rf "$SNAP_COMMON/default-storage" + echo "Storage space reclaimed." +else + read -p "Remove PVC storage at $SNAP_COMMON/default-storage ? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 + run_with_sudo rm -rf "$SNAP_COMMON/default-storage" + echo "Storage space reclaimed." +fi diff --git a/microk8s-resources/actions/disable.registry.sh b/microk8s-resources/actions/disable.registry.sh index 7f4c72f89d7..ef9212d0fb7 100755 --- a/microk8s-resources/actions/disable.registry.sh +++ b/microk8s-resources/actions/disable.registry.sh @@ -7,4 +7,4 @@ source $SNAP/actions/common/utils.sh echo "Disabling the private registry" use_manifest registry delete use_manifest registry-help apply -echo "The registry is disabled. Use 'microk8s disable storage:destroy-storage' to free the storage space." +echo "The registry is disabled. Use 'microk8s disable hostpath-storage:destroy-storage' to free the storage space." diff --git a/microk8s-resources/actions/disable.storage.sh b/microk8s-resources/actions/disable.storage.sh index 93320136fb0..e1e076aade8 100755 --- a/microk8s-resources/actions/disable.storage.sh +++ b/microk8s-resources/actions/disable.storage.sh @@ -4,20 +4,7 @@ set -e source $SNAP/actions/common/utils.sh -echo "Disabling default storage" -read -ra ARGUMENTS <<< "$1" +echo "DEPRECIATION WARNING: 'storage' is deprecated and will soon be removed. Please use 'hostpath-storage' instead." +echo "" -declare -A map -map[\$SNAP_COMMON]="$SNAP_COMMON" -use_manifest storage delete "$(declare -p map)" -sleep 5 -echo "Storage removed" -if [ ! -z "${ARGUMENTS[@]}" ] && [ "${ARGUMENTS[@]}" = "destroy-storage" ] -then - run_with_sudo rm -rf "$SNAP_COMMON/default-storage" - echo "Storage space reclaimed" -else - read -p "Remove PVC storage at $SNAP_COMMON/default-storage ? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 - run_with_sudo rm -rf "$SNAP_COMMON/default-storage" - echo "Storage space reclaimed" -fi +"$SNAP/microk8s-disable.wrapper" hostpath-storage $1 diff --git a/microk8s-resources/actions/enable.hostpath-storage.sh b/microk8s-resources/actions/enable.hostpath-storage.sh new file mode 100755 index 00000000000..284fc34887e --- /dev/null +++ b/microk8s-resources/actions/enable.hostpath-storage.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -e + +source $SNAP/actions/common/utils.sh + +if [ -d "$SNAP_COMMON/default-storage" ] +then + echo "Hostpath storage is already enabled." + exit 0 +fi + +echo "Enabling default storage class." +echo "WARNING: Hostpath storage is not suitable for production environments." +echo "" +run_with_sudo mkdir -p ${SNAP_COMMON}/default-storage + +declare -A map +map[\$SNAP_COMMON]="$SNAP_COMMON" +use_manifest storage apply "$(declare -p map)" +echo "Storage will be available soon." + +if [ -e ${SNAP_DATA}/var/lock/clustered.lock ] +then + echo "" + echo "WARNING: The storage class enabled does not persist volumes across nodes." + echo "" +fi diff --git a/microk8s-resources/actions/enable.portainer.sh b/microk8s-resources/actions/enable.portainer.sh index b604a5b2180..013024fd3c2 100755 --- a/microk8s-resources/actions/enable.portainer.sh +++ b/microk8s-resources/actions/enable.portainer.sh @@ -10,8 +10,8 @@ MANIFEST_PTR="https://raw.githubusercontent.com/portainer/k8s/master/deploy/mani KUBECTL="$SNAP/kubectl --kubeconfig=${SNAP_DATA}/credentials/client.config" -microk8s enable storage -microk8s enable dns +"$SNAP/microk8s-enable.wrapper" hostpath-storage +"$SNAP/microk8s-enable.wrapper" dns echo "Enabling portainer" diff --git a/microk8s-resources/actions/enable.registry.sh b/microk8s-resources/actions/enable.registry.sh index 92adfc9cc62..f3ea6de8f9c 100755 --- a/microk8s-resources/actions/enable.registry.sh +++ b/microk8s-resources/actions/enable.registry.sh @@ -12,7 +12,7 @@ if [ -z "${ARGUMENTS[@]}" ]; then echo "You can use the \"size\" argument while enabling the registry, eg microk8s.enable registry:size=30Gi" declare -A map map[\$DISKSIZE]="20Gi" - "$SNAP/microk8s-enable.wrapper" storage + "$SNAP/microk8s-enable.wrapper" hostpath-storage echo "Applying registry manifest" use_manifest registry apply "$(declare -p map)" echo "The registry is enabled" @@ -29,7 +29,7 @@ elif [[ ${ARGUMENTS[@]} =~ $regex_args ]]; then echo "The size of the registry should be higher or equal to 20Gi and match the regex: (^[2-9][0-9]{1,}|^[1-9][0-9]{2,})(Gi$)" exit 1 elif [ "$key" = "size" ] && [[ $value =~ $REGEX_DISK_SIZE ]]; then - "$SNAP/microk8s-enable.wrapper" storage + "$SNAP/microk8s-enable.wrapper" hostpath-storage declare -A map map[\$DISKSIZE]=$value fi diff --git a/microk8s-resources/actions/enable.storage.sh b/microk8s-resources/actions/enable.storage.sh index 9e683b395bb..e8db4b27363 100755 --- a/microk8s-resources/actions/enable.storage.sh +++ b/microk8s-resources/actions/enable.storage.sh @@ -4,17 +4,7 @@ set -e source $SNAP/actions/common/utils.sh -echo "Enabling default storage class" -run_with_sudo mkdir -p ${SNAP_COMMON}/default-storage +echo "DEPRECIATION WARNING: 'storage' is deprecated and will soon be removed. Please use 'hostpath-storage' instead." +echo "" -declare -A map -map[\$SNAP_COMMON]="$SNAP_COMMON" -use_manifest storage apply "$(declare -p map)" -echo "Storage will be available soon" - -if [ -e ${SNAP_DATA}/var/lock/clustered.lock ] -then - echo "" - echo "WARNING: The storage class enabled does not persist volumes across nodes" - echo "" -fi +"$SNAP/microk8s-enable.wrapper" hostpath-storage diff --git a/microk8s-resources/wrappers/addon-lists.yaml b/microk8s-resources/wrappers/addon-lists.yaml index 9faf97e7dec..8db636f7f8b 100644 --- a/microk8s-resources/wrappers/addon-lists.yaml +++ b/microk8s-resources/wrappers/addon-lists.yaml @@ -44,7 +44,7 @@ microk8s-addons: - arm64 - amd64 - - name: "storage" + - name: "hostpath-storage" description: "Storage class; allocates storage from host directory" version: "1.0.0" check_status: "pod/hostpath-provisioner" diff --git a/microk8s-resources/wrappers/microk8s-join.wrapper b/microk8s-resources/wrappers/microk8s-join.wrapper index db7dc0a5059..a7d4a6177d9 100755 --- a/microk8s-resources/wrappers/microk8s-join.wrapper +++ b/microk8s-resources/wrappers/microk8s-join.wrapper @@ -9,11 +9,17 @@ export PYTHONNOUSERSITE=false source $SNAP/actions/common/utils.sh -if [ -e "$SNAP_DATA/args/cni-network/cni.yaml.disabled" ] && [ -e "$SNAP_DATA/args/cni-network/05-cilium-cni.conf" ] ; then - echo "Cilium is enabled and is not suitable for multi node clusters." +if [ -e "$SNAP_DATA/args/cni-network/cni.yaml.disabled" ] && [ -e "$SNAP_DATA/args/cni-network/05-cilium-cni.conf" ] ; then + echo "WARNING: Cilium is enabled and is not suitable for multi node clusters." exit 1 fi +if [ -d "$SNAP_COMMON/default-storage" ] +then + echo "WARNING: Hostpath storage is enabled and is not suitable for multi node clusters." + echo "" +fi + exit_if_no_permissions sudo -E LD_LIBRARY_PATH=$IN_SNAP_LD_LIBRARY_PATH ${SNAP}/usr/bin/python3 ${SNAP}/scripts/cluster/join.py $@ diff --git a/microk8s-resources/wrappers/microk8s-reset.wrapper b/microk8s-resources/wrappers/microk8s-reset.wrapper index 34904cd350c..2b5bbce56ed 100755 --- a/microk8s-resources/wrappers/microk8s-reset.wrapper +++ b/microk8s-resources/wrappers/microk8s-reset.wrapper @@ -27,7 +27,7 @@ disable_addons() { fi echo "Disabling addon : $action" addon_arguments="" - if [ "$action" = "storage" ] && [ ${destroy_storage_enabled} ] + if [ "$action" = "hostpath-storage" ] && [ ${destroy_storage_enabled} ] then microk8s disable $action:destroy-storage > /dev/null 2>&1 || true else diff --git a/tests/test-addons.py b/tests/test-addons.py index cd0497478d0..606b1ed036a 100644 --- a/tests/test-addons.py +++ b/tests/test-addons.py @@ -134,9 +134,9 @@ def test_basic(self): validate_dashboard_ingress() print("Disabling dashboard-ingress") microk8s_disable("dashboard-ingress") - print("Enabling storage") - microk8s_enable("storage") - print("Validating storage") + print("Enabling hostpath-storage") + microk8s_enable("hostpath-storage") + print("Validating hostpath-storage") validate_storage() microk8s_enable("registry") print("Validating registry") @@ -151,8 +151,8 @@ def test_basic(self): microk8s_disable("registry") print("Disabling dashboard") microk8s_disable("dashboard") - print("Disabling storage") - microk8s_disable("storage:destroy-storage") + print("Disabling hostpath-storage") + microk8s_disable("hostpath-storage:destroy-storage") """ We would disable DNS here but this freezes any terminating pods. We let microk8s reset to do the cleanup.