Commit d01f68d5 authored by Thong Kuah's avatar Thong Kuah
Browse files

Merge branch 'fix-handling-of-remote-repositories' into 'master'

fix: Always add remote chart repository

See merge request gitlab-org/cluster-integration/auto-deploy-image!111
parents 30687df8 d584521b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -65,10 +65,16 @@ test-download-chart:
test-download-chart-from-repo:
  <<: *test-job
  variables:
    AUTO_DEVOPS_CHART_REPOSITORY: https://charts.gitlab.io
    AUTO_DEVOPS_CHART_REPOSITORY_NAME: gitlab
    AUTO_DEVOPS_CHART: gitlab/auto-deploy-app
  script:
    - auto-deploy download_chart
    - ./test/verify-chart-version 0
    # test that a custom repo gets added even if the chart/ folder is present
    - export AUTO_DEVOPS_CHART_REPOSITORY_NAME=custom
    - auto-deploy download_chart
    - helm fetch custom/auto-deploy-app

test-deploy-name:
  <<: *test-job
@@ -454,6 +460,9 @@ test-delete-canary-postgresql:

test-chart-major-version-upgrade:
  extends: test-deploy
  variables:
    AUTO_DEVOPS_CHART_REPOSITORY: https://charts.gitlab.io
    AUTO_DEVOPS_CHART_REPOSITORY_NAME: gitlab
  script:
    - unset ADDITIONAL_HOSTS # The legacy chart is not compatible wildcard hosts on ADDITIONAL_HOSTS
    - auto-deploy initialize_tiller
+41 −20
Original line number Diff line number Diff line
@@ -33,35 +33,56 @@ function check_kube_domain() {
function download_chart() {
  helm init --client-only

  add_chart_repository

  if [[ -d chart ]]; then
    echo "Download is skipped. The bundled chart in user's repository will be used."
  elif [[ -n "${AUTO_DEVOPS_CHART}${AUTO_DEVOPS_CHART_REPOSITORY_NAME}${AUTO_DEVOPS_CHART_REPOSITORY}" ]]; then
    echo "Downloading the chart from the chart repository..."
    local auto_chart
    echo "Download skipped. Using the chart at local path 'chart/'..."
  elif [[ -n "$AUTO_DEVOPS_CHART" ]]; then
    # user specified a custom chart to use, but it can be a local directory or a remote chart
    if [[ -d "$AUTO_DEVOPS_CHART" ]]; then
      echo "Download skipped. Using the chart at local path '$AUTO_DEVOPS_CHART' (moving to 'chart/' first)..."
      mv "$AUTO_DEVOPS_CHART" chart/
    else
      echo "Downloading remote chart '$AUTO_DEVOPS_CHART'..."
      local auto_chart_name

    auto_chart=${AUTO_DEVOPS_CHART:-gitlab/auto-deploy-app}
    # shellcheck disable=SC2086 # double quote variables to prevent globbing
    auto_chart_name=$(basename $auto_chart)
      auto_chart_name=$(basename "$AUTO_DEVOPS_CHART")
      auto_chart_name=${auto_chart_name%.tgz}
      auto_chart_name=${auto_chart_name%.tar.gz}

    # shellcheck disable=SC2086 # double quote variables to prevent globbing
    # shellcheck disable=SC2140 # ambiguous quoting warning
    helm repo add ${AUTO_DEVOPS_CHART_REPOSITORY_NAME:-gitlab} ${AUTO_DEVOPS_CHART_REPOSITORY:-https://charts.gitlab.io} ${AUTO_DEVOPS_CHART_REPOSITORY_USERNAME:+"--username" "$AUTO_DEVOPS_CHART_REPOSITORY_USERNAME"} ${AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD:+"--password" "$AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD"}
    helm fetch "${auto_chart}" --untar
    if [ "$auto_chart_name" != "chart" ]; then
      mv "${auto_chart_name}" chart
      helm fetch "$AUTO_DEVOPS_CHART" --untar
      if [[ "$auto_chart_name" != "chart" ]]; then
        mv "$auto_chart_name" chart
      fi
    fi
  else
    echo "Download is skipped. The bundled chart in auto-deploy-image will be used."
    cp -R $ASSETS_CHART_DIR chart
    echo "Download skipped. Using the default chart included in auto-deploy-image..."
    cp -R "$ASSETS_CHART_DIR" chart
  fi

  helm dependency update chart/
  helm dependency build chart/
}

function add_chart_repository() {
  if [[ -z "$AUTO_DEVOPS_CHART_REPOSITORY" ]]; then
    return
  fi

  echo "Adding Helm chart repository '$AUTO_DEVOPS_CHART_REPOSITORY_NAME'"

  # repo should always be added when present, because any chart can have external dependencies
  local helm_repo_auth=()
  if [[ -n "$AUTO_DEVOPS_CHART_REPOSITORY_USERNAME" ]]; then
    helm_repo_auth+=('--username' "$AUTO_DEVOPS_CHART_REPOSITORY_USERNAME")
  fi
  if [[ -n "$AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD" ]]; then
    helm_repo_auth+=('--password' "$AUTO_DEVOPS_CHART_REPOSITORY_PASSWORD")
  fi
  helm repo add \
    "${AUTO_DEVOPS_CHART_REPOSITORY_NAME}" \
    "${AUTO_DEVOPS_CHART_REPOSITORY}" \
    "${helm_repo_auth[@]}"
}

function ensure_namespace() {
  kubectl get namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
}