diff --git a/deploy/helm/scripts/change_addon_release.sh b/deploy/helm/scripts/change_addon_release.sh deleted file mode 100644 index bf8b95bef22..00000000000 --- a/deploy/helm/scripts/change_addon_release.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -release=$1 -namespace=$2 - -function updateRelease() { - local kind=$1 - crs=$(kubectl get $kind -l app.kubernetes.io/instance=${release} --no-headers) - OLD_IFS=$IFS - IFS=$'\n' - for line in $crs; do - name=$(echo "$line" | awk '{print $1}') - kubectl annotate $kind $name --overwrite meta.helm.sh/release-name=$release - kubectl annotate $kind $name --overwrite meta.helm.sh/release-namespace=$namespace - done - IFS=$OLD_IFS -} - -updateRelease clusterdefinition -updateRelease componentversion - diff --git a/deploy/helm/scripts/change_kb_release.sh b/deploy/helm/scripts/change_kb_release.sh index bf1c92ffa4c..2ec92013277 100644 --- a/deploy/helm/scripts/change_kb_release.sh +++ b/deploy/helm/scripts/change_kb_release.sh @@ -1,14 +1,49 @@ #!/bin/bash -release=$1 -namespace=$2 +release= +namespace= -function updateRelease() { +for i in "$@"; do + case $i in + --release-name=*) + release="${i#*=}" + shift + ;; + --namespace=*) + namespace="${i#*=}" + shift + ;; + *) + echo "Unknown option $i" + exit 1 + ;; + esac +done +if [ "$release" == "" ] || [ "$namespace" == "" ]; then + echo "--release-name and --namespace are required" + exit 1 +fi +echo "KubeBlocks release name: $release, namespace: $namespace" + + +function takeOverResources() { local kind=$1 local name=$2 kubectl annotate $kind $name --overwrite meta.helm.sh/release-name=$release kubectl annotate $kind $name --overwrite meta.helm.sh/release-namespace=$namespace } +function setCRDAPIVersion() { + local kind=$1 + crs=$(kubectl get $kind) + OLD_IFS=$IFS + IFS=$'\n' + for line in $crs; do + name=$(echo "$line" | awk '{print $1}') + kubectl annotate $kind $name --overwrite kubeblocks.io/crd-api-version=apps.kubeblocks.io/v1alpha1 + done + IFS=$OLD_IFS +} + # 1. change clusterRoles clusterRoles=( "cluster-editor-role" @@ -33,10 +68,10 @@ clusterRoles=( ) for role in "${clusterRoles[@]}"; do - updateRelease ClusterRole "${release}-${role}" + takeOverResources ClusterRole "${release}-${role}" done -updateRelease ClusterRole "${release}" -updateRelease ClusterRole "kubeblocks-cluster-pod-role" +takeOverResources ClusterRole "${release}" +takeOverResources ClusterRole "kubeblocks-cluster-pod-role" # 2. change addons addons=( @@ -59,7 +94,7 @@ addons=( ) for addon in "${addons[@]}"; do - updateRelease Addon "$addon" + takeOverResources Addon "$addon" done # 3. change storageProvider @@ -76,8 +111,11 @@ storageProviders=( ) for sp in "${storageProviders[@]}"; do - updateRelease StorageProviders "$sp" + takeOverResources StorageProviders "$sp" done # 4. change backupRepo -updateRelease BackupRepo ${release}-backuprepo \ No newline at end of file +takeOverResources BackupRepo ${release}-backuprepo + +# 5. set kubeblocks.io/crd-api-version: apps.kubeblocks.io/v1alpha1 to old componentDefinition +setCRDAPIVersion ComponentDefinition \ No newline at end of file diff --git a/deploy/helm/scripts/post_install_1.0_addon.sh b/deploy/helm/scripts/post_install_1.0_addon.sh new file mode 100644 index 00000000000..0732fc63c49 --- /dev/null +++ b/deploy/helm/scripts/post_install_1.0_addon.sh @@ -0,0 +1,29 @@ +#!/bin/bash +release= +namespace= +addon= + +for i in "$@"; do + case $i in + --release-name=*) + release="${i#*=}" + shift + ;; + --namespace=*) + namespace="${i#*=}" + shift + ;; + *) + echo "Unknown option $i" + exit 1 + ;; + esac +done +if [ "$release" == "" ] || [ "$namespace" == "" ]; then + echo "--release-name, --namespace" + exit 1 +fi +echo "release: $release, namespace: $namespace" + +helm get manifest -n $namespace $release | kubectl apply -f - + diff --git a/deploy/helm/scripts/pre_install_1.0_addon.sh b/deploy/helm/scripts/pre_install_1.0_addon.sh new file mode 100644 index 00000000000..71cc5e2da77 --- /dev/null +++ b/deploy/helm/scripts/pre_install_1.0_addon.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +for i in "$@"; do + case $i in + --release-name=*) + release="${i#*=}" + shift + ;; + --namespace=*) + namespace="${i#*=}" + shift + ;; + --addon-name=*) + addon="${i#*=}" + shift + ;; + *) + echo "Unknown option $i" + exit 1 + ;; + esac +done +if [ "$release" == "" ] || [ "$namespace" == "" ] || [ "$addon" == "" ]; then + echo "--release-name, --namespace and --addon-name are required" + exit 1 +fi +echo "release: $release, namespace: $namespace, addon: $addon" + +function takeOverResources() { + local kind=$1 + local kind=$1 + crs=$(kubectl get $kind -l app.kubernetes.io/name=${addon} --no-headers) + OLD_IFS=$IFS + IFS=$'\n' + for line in $crs; do + name=$(echo "$line" | awk '{print $1}') + kubectl annotate $kind $name --overwrite meta.helm.sh/release-name=$release + kubectl annotate $kind $name --overwrite meta.helm.sh/release-namespace=$namespace + done + IFS=$OLD_IFS +} + +takeOverResources "ClusterDefinition" +takeOverResources "ComponentVersion" \ No newline at end of file