From d83d33f216e00ba442fe44a802bce97d3d922a6b Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Sat, 15 Jun 2024 14:22:10 +0800 Subject: [PATCH] enable config a ready cluster Signed-off-by: Sam Yuan --- .github/workflows/test.yml | 58 +++++++++++++++++++++----------------- lib/prometheus.sh | 5 +++- main.sh | 24 ++++++++-------- verify.sh | 1 - 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 384104d..754e8e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,46 +31,24 @@ jobs: fail-fast: false matrix: include: - - cluster_provider: kind - prometheus_operator_version: v0.12.0 - PROMETHEUS_ENABLE: false - GRAFANA_ENABLE: false - TEKTON_ENABLE: false - - cluster_provider: kind - prometheus_operator_version: v0.12.0 - PROMETHEUS_ENABLE: true - GRAFANA_ENABLE: true - TEKTON_ENABLE: false - - cluster_provider: kind - prometheus_operator_version: v0.12.0 - PROMETHEUS_ENABLE: false - GRAFANA_ENABLE: false - TEKTON_ENABLE: true - cluster_provider: kind prometheus_operator_version: v0.12.0 PROMETHEUS_ENABLE: true GRAFANA_ENABLE: true TEKTON_ENABLE: true + LOADPROMETHEUSIMAGE: true - cluster_provider: microshift prometheus_operator_version: v0.12.0 PROMETHEUS_ENABLE: false GRAFANA_ENABLE: false TEKTON_ENABLE: false + LOADPROMETHEUSIMAGE: true - cluster_provider: microshift prometheus_operator_version: v0.12.0 PROMETHEUS_ENABLE: true GRAFANA_ENABLE: true TEKTON_ENABLE: false - #- cluster_provider: microshift - # prometheus_operator_version: v0.12.0 - # PROMETHEUS_ENABLE: false - # GRAFANA_ENABLE: false - # TEKTON_ENABLE: true - #- cluster_provider: microshift - # prometheus_operator_version: v0.12.0 - # PROMETHEUS_ENABLE: true - # GRAFANA_ENABLE: true - # TEKTON_ENABLE: true + LOADPROMETHEUSIMAGE: true steps: - uses: actions/checkout@v3 - name: start from local @@ -80,13 +58,41 @@ jobs: export GRAFANA_ENABLE=${{matrix.GRAFANA_ENABLE}} export CLUSTER_PROVIDER=${{matrix.cluster_provider}} export TEKTON_ENABLE=${{matrix.TEKTON_ENABLE}} - ./main.sh prerequisites + export LOADPROMETHEUSIMAGE=${{matrix.LOADPROMETHEUSIMAGE}} ./main.sh up - name: verify run: | export CLUSTER_PROVIDER=${{matrix.cluster_provider}} ./verify.sh + # test local cluster without prometheus grafana + test_precreated_cluster: + needs: + - shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: start a cluster from local + run: | + export PROMETHEUS_ENABLE=false + export TEKTON_ENABLE=false + export LOADPROMETHEUSIMAGE=false + export CLUSTER_CONFIG=false + ./main.sh up + mkdir -p /tmp/kubeconfig + cp .kube/config /tmp/kubeconfig + ls /tmp/kubeconfig + - name: config a cluster + run: | + export PROMETHEUS_ENABLE=true + export TEKTON_ENABLE=true + export LOADPROMETHEUSIMAGE=false + export KUBECONFIG_ROOT_DIR=/tmp/kubeconfig + ./main.sh config + - name: verify cluster + run: | + ./verify.sh verify_cluster + containertestubuntu: needs: - shellcheck diff --git a/lib/prometheus.sh b/lib/prometheus.sh index e42301a..61107ef 100755 --- a/lib/prometheus.sh +++ b/lib/prometheus.sh @@ -20,6 +20,7 @@ # configuration declare -r PROMETHEUS_OPERATOR_VERSION=${PROMETHEUS_OPERATOR_VERSION:-v0.11.0} declare -r PROMETHEUS_REPLICAS=${PROMETHEUS_REPLICAS:-1} +declare -r LOADPROMETHEUSIMAGE=${LOADPROMETHEUSIMAGE:-true} # constants declare -r KUBE_PROM_DIR="$PROJECT_ROOT/tmp/kube-prometheus" @@ -44,7 +45,9 @@ deploy_prometheus_operator() { mv kube-prometheus/manifests/prometheus-prometheus.yaml.tmp \ kube-prometheus/manifests/prometheus-prometheus.yaml - _load_prometheus_operator_images_to_local_registry + if is_set "$LOADPROMETHEUSIMAGE"; then + _load_prometheus_operator_images_to_local_registry + fi kubectl create -f kube-prometheus/manifests/setup kubectl wait \ --for condition=Established \ diff --git a/main.sh b/main.sh index 2a455a8..c7223c4 100755 --- a/main.sh +++ b/main.sh @@ -56,18 +56,14 @@ declare -r KUBEVIRT_ENABLE=${KUBEVIRT_ENABLE:-false} declare -r LIBBPF_VERSION=${LIBBPF_VERSION:-v1.2.0} declare -r RESTARTCONTAINERRUNTIME=${RESTARTCONTAINERRUNTIME:-false} declare -r REDHAT_SUB=${REDHAT_SUB:-false} +declare -r CLUSTER_CONFIG=${CLUSTER_CONFIG:-true} source "$PROJECT_ROOT/lib/utils.sh" config_cluster() { - kubeconfig="$KUBECONFIG_ROOT_DIR/config":$(find "$KUBECONFIG_ROOT_DIR" \ - -type f -name "*config*" | tr '\n' ':') - kubeconfig=${kubeconfig%:} - KUBECONFIG=$kubeconfig kubectl config view --merge --flatten >all-in-one-kubeconfig.yaml - mv -f all-in-one-kubeconfig.yaml "${KUBECONFIG_ROOT_DIR}/config" - + info "start config cluster" export KUBECONFIG="${KUBECONFIG_ROOT_DIR}/$KEPLER_KUBECONFIG" - + info "finish load kubeconfig" if is_set "$PROMETHEUS_ENABLE" || is_set "$GRAFANA_ENABLE"; then source "$PROJECT_ROOT/lib/prometheus.sh" deploy_prometheus_operator @@ -98,7 +94,15 @@ cluster_up() { mkdir -p "$(basename "$KUBECONFIG_ROOT_DIR")" mv -f "$kubeconfig" "${KUBECONFIG_ROOT_DIR}/${KEPLER_KUBECONFIG}" - config_cluster + kubeconfig="$KUBECONFIG_ROOT_DIR/$KEPLER_KUBECONFIG":$(find "$KUBECONFIG_ROOT_DIR" \ + -type f -name "*config*" | tr '\n' ':') + kubeconfig=${kubeconfig%:} + KUBECONFIG=$kubeconfig kubectl config view --merge --flatten >all-in-one-kubeconfig.yaml + mv -f all-in-one-kubeconfig.yaml "${KUBECONFIG_ROOT_DIR}/config" + + if is_set "$CLUSTER_CONFIG"; then + config_cluster + fi } cluster_down() { @@ -107,8 +111,6 @@ cluster_down() { } print_config() { - local cluster_config - cluster_config=$("${CLUSTER_PROVIDER}"_print_config) local prom_install_msg="$PROMETHEUS_ENABLE" if ! is_set "$PROMETHEUS_ENABLE" && is_set "$GRAFANA_ENABLE"; then @@ -136,7 +138,6 @@ print_config() { KubeVirt * Install KubeVirt : $KUBEVIRT_ENABLE - $cluster_config ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ EOF @@ -265,6 +266,7 @@ main() { ;; config) source "$cluster_lib" + print_config config_cluster return $? ;; diff --git a/verify.sh b/verify.sh index bd6e3e1..ff39682 100755 --- a/verify.sh +++ b/verify.sh @@ -80,7 +80,6 @@ main() { containerruntime ;; all | *) - verify_bcc verify_cluster ;; esac