From aefbba12c17b434a5456eb1d5d82dac399e454df Mon Sep 17 00:00:00 2001 From: Vicente Cheng Date: Mon, 7 Oct 2024 00:42:39 +0800 Subject: [PATCH] ci: improve the ci for webhook installation Signed-off-by: Vicente Cheng --- .github/workflows/basic-ci.yaml | 8 +- ci/charts/ndm-override.yaml | 6 ++ .../{deploy_ndm.sh => deploy_ndm_chart.sh} | 0 ci/scripts/deploy_ndm_current.sh | 91 +++++++++++++++++++ ci/scripts/get-debug-info.sh | 2 +- ci/scripts/patch-ttl-repo.sh | 5 +- ci/scripts/upgrade_ndm.sh | 2 +- 7 files changed, 107 insertions(+), 7 deletions(-) rename ci/scripts/{deploy_ndm.sh => deploy_ndm_chart.sh} (100%) create mode 100755 ci/scripts/deploy_ndm_current.sh diff --git a/.github/workflows/basic-ci.yaml b/.github/workflows/basic-ci.yaml index fd4d7884..1f5a523c 100644 --- a/.github/workflows/basic-ci.yaml +++ b/.github/workflows/basic-ci.yaml @@ -59,9 +59,9 @@ jobs: - name: "Deploy NDM" run: | pushd ndm-new-vagrant-k3s - cp ../ci/scripts/deploy_ndm.sh ./deploy_ndm.sh + cp ../ci/scripts/deploy_ndm_current.sh ./deploy_ndm_current.sh cp ../ci/charts/ndm-override.yaml ./ndm-override.yaml - ./deploy_ndm.sh + ./deploy_ndm_current.sh popd - name: "Add disk" run: | @@ -123,8 +123,8 @@ jobs: echo "VM_DEPLOYED=true" >> "$GITHUB_ENV" yq e -i ".longhorn_version = \"1.7.1\"" settings.yaml ./scripts/deploy_longhorn.sh - cp ../ci/scripts/deploy_ndm.sh ./deploy_ndm.sh - ./deploy_ndm.sh + cp ../ci/scripts/deploy_ndm_chart.sh ./deploy_ndm_chart.sh + ./deploy_ndm_chart.sh popd - name: "Add disk" run: | diff --git a/ci/charts/ndm-override.yaml b/ci/charts/ndm-override.yaml index c11140a2..82f0e533 100644 --- a/ci/charts/ndm-override.yaml +++ b/ci/charts/ndm-override.yaml @@ -4,6 +4,12 @@ image: # Overrides the image tag whose default is the chart appVersion. tag: "" +webhook: + repository: rancher/harvester-node-disk-manager + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + autoProvisionFilter: [/dev/sd*] debug: true diff --git a/ci/scripts/deploy_ndm.sh b/ci/scripts/deploy_ndm_chart.sh similarity index 100% rename from ci/scripts/deploy_ndm.sh rename to ci/scripts/deploy_ndm_chart.sh diff --git a/ci/scripts/deploy_ndm_current.sh b/ci/scripts/deploy_ndm_current.sh new file mode 100755 index 00000000..3a6693d1 --- /dev/null +++ b/ci/scripts/deploy_ndm_current.sh @@ -0,0 +1,91 @@ +#!/bin/bash -e + +TOP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" &> /dev/null && pwd )" + +ensure_command() { + local cmd=$1 + if ! which $cmd &> /dev/null; then + echo 1 + return + fi + echo 0 +} + +wait_ndm_ready() { + while [ true ]; do + running_num=$(kubectl get ds harvester-node-disk-manager -n harvester-system -o 'jsonpath={.status.numberReady}') + if [[ $running_num -eq ${cluster_nodes} ]]; then + echo "harvester-node-disk-manager pods are ready!" + break + fi + echo "harvester-node-disk-manager pods are not ready, sleep 10 seconds." + sleep 10 + done +} + +ensure_longhorn_ready() { + # ensure longhorn-manager first + while [ true ]; do + running_num=$(kubectl get ds longhorn-manager -n longhorn-system -o 'jsonpath={.status.numberReady}') + if [[ $running_num -eq ${cluster_nodes} ]]; then + echo "longhorn-manager pods are ready!" + break + fi + echo "check longhorn-manager failure, please deploy longhorn first." + exit 1 + done + + # ensure instance-manager-e ready + while [ true ]; do + running_num=$(kubectl get pods -n longhorn-system |grep ^instance-manager |grep Running |awk '{print $3}' |wc -l) + if [[ $running_num -eq ${cluster_nodes} ]]; then + echo "instance-manager pods are ready!" + break + fi + echo "check instance-manager failure, please deploy longhorn first." + exit 1 + done +} + +if [ ! -f $TOP_DIR/kubeconfig ]; then + echo "kubeconfig does not exist. Please create cluster first." + echo "Maybe try new_cluster.sh" + exit 1 +fi +echo $TOP_DIR/kubeconfig +export KUBECONFIG=$TOP_DIR/kubeconfig + +if [[ $(ensure_command helm) -eq 1 ]]; then + echo "no helm, try to curl..." + curl -O https://get.helm.sh/helm-v3.9.4-linux-amd64.tar.gz + tar -zxvf helm-v3.9.4-linux-amd64.tar.gz + HELM=$TOP_DIR/linux-amd64/helm + $HELM version +else + echo "Get helm, version info as below" + HELM=$(which helm) + $HELM version +fi + +cluster_nodes=$(yq -e e '.cluster_size' $TOP_DIR/settings.yaml) +echo "cluster nodes: $cluster_nodes" +ensure_longhorn_ready + +pushd $TOP_DIR +cat >> ndm-override.yaml.default << 'EOF' +autoProvisionFilter: [/dev/sd*] +EOF + +if [ ! -f ndm-override.yaml ]; then + mv ndm-override.yaml.default ndm-override.yaml +fi + +cp -r ../deploy/charts/harvester-node-disk-manager harvester-node-disk-manager + +target_img=$(yq -e .image.repository ndm-override.yaml) +echo "install target image: ${target_img}" +$HELM install -f $TOP_DIR/ndm-override.yaml harvester-node-disk-manager ./harvester-node-disk-manager --create-namespace -n harvester-system + +wait_ndm_ready +echo "harvester-node-disk-manager is ready" +popd \ No newline at end of file diff --git a/ci/scripts/get-debug-info.sh b/ci/scripts/get-debug-info.sh index 7bfe44c7..02d076eb 100755 --- a/ci/scripts/get-debug-info.sh +++ b/ci/scripts/get-debug-info.sh @@ -4,7 +4,7 @@ TARGETNODE="node1" export KUBECONFIG=kubeconfig -NDMPOD=$(kubectl get pods -n harvester-system --field-selector spec.nodeName=$TARGETNODE |grep ^harvester-node-disk-manager |awk '{print $1}') +NDMPOD=$(kubectl get pods -n harvester-system --field-selector spec.nodeName=$TARGETNODE | grep ^harvester-node-disk-manager |grep -v webhook |awk '{print $1}') # filter out the redundant Skip log kubectl logs $NDMPOD -n harvester-system |grep -v Skip diff --git a/ci/scripts/patch-ttl-repo.sh b/ci/scripts/patch-ttl-repo.sh index b551bc66..8fd28722 100755 --- a/ci/scripts/patch-ttl-repo.sh +++ b/ci/scripts/patch-ttl-repo.sh @@ -2,6 +2,9 @@ COMMIT=$(git rev-parse --short HEAD) IMAGE=ttl.sh/node-disk-manager-${COMMIT} +IMAGE_WEBHOOK=ttl.sh/node-disk-manager-webhook-${COMMIT} yq e -i ".image.repository = \"${IMAGE}\"" ci/charts/ndm-override.yaml -yq e -i ".image.tag = \"1h\"" ci/charts/ndm-override.yaml \ No newline at end of file +yq e -i ".image.tag = \"1h\"" ci/charts/ndm-override.yaml +yq e -i ".webhook.image.repository = \"${IMAGE_WEBHOOK}\"" ci/charts/ndm-override.yaml +yq e -i ".webhook.image.tag = \"1h\"" ci/charts/ndm-override.yaml \ No newline at end of file diff --git a/ci/scripts/upgrade_ndm.sh b/ci/scripts/upgrade_ndm.sh index f8ad3593..8f3640df 100755 --- a/ci/scripts/upgrade_ndm.sh +++ b/ci/scripts/upgrade_ndm.sh @@ -62,7 +62,7 @@ sleep 30 # wait 30 seconds for ndm respawn pods wait_ndm_ready # check image -pod_name=$(kubectl get pods -n harvester-system |grep Running |grep ^harvester-node-disk-manager|head -n1 |awk '{print $1}') +pod_name=$(kubectl get pods -n harvester-system |grep Running |grep -v webhook |grep ^harvester-node-disk-manager|head -n1 |awk '{print $1}') container_img=$(kubectl get pods ${pod_name} -n harvester-system -o yaml |yq -e .spec.containers[0].image |tr ":" \n) yaml_img=$(yq -e .image.repository ndm-override.yaml) if grep -q ${yaml_img} <<< ${container_img}; then