Skip to content

Commit

Permalink
chore: support to handle the old cd/cmpv when using dual operator mode (
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Dec 30, 2024
1 parent ed79737 commit d1b1007
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 29 deletions.
20 changes: 0 additions & 20 deletions deploy/helm/scripts/change_addon_release.sh

This file was deleted.

56 changes: 47 additions & 9 deletions deploy/helm/scripts/change_kb_release.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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=(
Expand All @@ -59,7 +94,7 @@ addons=(
)

for addon in "${addons[@]}"; do
updateRelease Addon "$addon"
takeOverResources Addon "$addon"
done

# 3. change storageProvider
Expand All @@ -76,8 +111,11 @@ storageProviders=(
)

for sp in "${storageProviders[@]}"; do
updateRelease StorageProviders "$sp"
takeOverResources StorageProviders "$sp"
done

# 4. change backupRepo
updateRelease BackupRepo ${release}-backuprepo
takeOverResources BackupRepo ${release}-backuprepo

# 5. set kubeblocks.io/crd-api-version: apps.kubeblocks.io/v1alpha1 to old componentDefinition
setCRDAPIVersion ComponentDefinition
29 changes: 29 additions & 0 deletions deploy/helm/scripts/post_install_1.0_addon.sh
Original file line number Diff line number Diff line change
@@ -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 -

44 changes: 44 additions & 0 deletions deploy/helm/scripts/pre_install_1.0_addon.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit d1b1007

Please sign in to comment.