Commit d5385655 authored by Ruben ten Hove's avatar Ruben ten Hove
Browse files

include envsubst for helm values

parent a8c3f73d
Loading
Loading
Loading
Loading
+40 −1
Original line number Diff line number Diff line
---
variables:
  K8S_CONFIG_DIR: ${CI_JOB_NAME}

.kube-context:
  image: registry.gitlab.com/gitlab-org/cluster-integration/cluster-applications:latest
  stage: deploy
@@ -7,5 +10,41 @@
    action: prepare
  before_script:
    - gl-use-kube-context
    - chmod 400 $KUBECONFIG
    - chmod 400 ${KUBECONFIG}
  needs: []

.kubectl:
  extends: .kube-context
  script:
    - |
      if test -d ${K8S_CONFIG_DIR}/envsubst; then
        echo "[*] Processing envsubst folder..."
        apk add gettext
        for FILE in $(ls ${K8S_CONFIG_DIR}/envsubst/); do
          if [ "${FILE}" = "values.yaml" ]; then
            envsubst < ${K8S_CONFIG_DIR}/envsubst/${FILE} > ${K8S_CONFIG_DIR}/values.yaml
          else
            mkdir -p ${K8S_CONFIG_DIR}/apply
            envsubst < ${K8S_CONFIG_DIR}/envsubst/${FILE} > ${K8S_CONFIG_DIR}/apply/${FILE}
          fi
        done
      fi
    - |
      if [ "${CI_COMMIT_BRANCH}" = "${CI_DEFAULT_BRANCH}" ]; then
        if test -f ${K8S_CONFIG_DIR}/apply/namespace.yaml; then
          echo "[*] Ensuring namespace availability..."
          kubectl apply --wait -f ${K8S_CONFIG_DIR}/apply/namespace.yaml
        fi
        if test -d ${K8S_CONFIG_DIR}/apply; then
          echo "[*] Running apply folder..."
          kubectl apply --wait --recursive -f ${K8S_CONFIG_DIR}/apply
        fi
        if test -d ${K8S_CONFIG_DIR}/create; then
          echo "[*] Running create folder..."
          kubectl create --recursive -f ${K8S_CONFIG_DIR}/create
        fi
      fi
  artifacts:
    paths:
      - ${K8S_CONFIG_DIR}/
    when: always
+5 −4
Original line number Diff line number Diff line
@@ -14,9 +14,11 @@ include:
      --render-subchart-notes
    EXTRA_ARGS: ""
  script:
    - !reference [.kubectl, script]
    - |
      if test -f "${CI_JOB_NAME}/values.yaml"; then
        VALUES_ARG="-f ${CI_JOB_NAME}/values.yaml"
      if test -f "${K8S_CONFIG_DIR}/values.yaml"; then
        echo "[+] Including '${K8S_CONFIG_DIR}/values.yaml'."
        EXTRA_ARGS="${EXTRA_ARGS} -f ${K8S_CONFIG_DIR}/values.yaml"
      fi
    - |
      echo "[*] Will helm with the following variables:
@@ -24,9 +26,8 @@ include:
      REPO_URL=${REPO_URL}
      CHART=${CHART}
      RELEASE=${RELEASE}
      CI_JOB_NAME=${CI_JOB_NAME}
      K8S_CONFIG_DIR=${K8S_CONFIG_DIR}
      DEFAULT_ARGS=${DEFAULT_ARGS}
      VALUES_ARG=${VALUES_ARG}
      EXTRA_ARGS=${EXTRA_ARGS}
      NAMESPACE=${NAMESPACE:=default}"
    - helm repo add ${REPO_NAME} ${REPO_URL}
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ repo-root
In that `job.yml` add the following content. Ensure the name of the job equals the name of the subfolder.

```yaml
---
deployment-name:
  extends: .helm
  variables: