Skip to content
Snippets Groups Projects
Commit e8655646 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'awkenvsubst-kustomize' into 'master'

fix missing awkenvsubst when using kustomize based deployment

Closes #47

See merge request to-be-continuous/kubernetes!86
parents e29f9778 ad7d3b65
Branches
Tags
No related merge requests found
......@@ -145,7 +145,7 @@ The Kubernetes template supports three techniques to deploy your code:
1. script-based deployment,
2. template-based deployment using raw Kubernetes manifests (with [variables substitution](#variables-substitution-mechanism)),
3. template-based deployment using [Kustomization files](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/).
3. template-based deployment using [Kustomization files](https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/) (with [variables substitution](#variables-substitution-mechanism)).
#### 1: script-based deployment
......@@ -182,15 +182,12 @@ in your project structure, and let the template [`kubectl apply`](https://kubern
The template processes the following steps:
1. _optionally_ executes the `k8s-pre-apply.sh` script in your project to perform specific environment pre-initialization (for e.g. create required services),
2. looks for your Kustomization file, performs variables substitution and [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) it,
2. looks for your Kustomization file, performs [variables substitution](#variables-substitution-mechanism), generates the manifests with [`kubectl kustomize`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#kustomize) and [`kubectl apply`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) it,
1. looks for an environment-specific [overlay](https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#overlay) file `./$environment_type/kustomization.yaml` (e.g. `./staging/kustomization.yaml ` for staging environment),
2. fallbacks to default `kustomization.yaml`.
3. _optionally_ executes the `k8s-post-apply.sh` script in your project to perform specific environment post-initialization stuff,
:warning: `k8s-pre-apply.sh` or `k8s-post-apply.sh` needs to be executable, you can add flag execution with: `git update-index --chmod=+x k8s-pre-apply.sh`
Variables substitution is performed by the deprecated feature from Kustomize based on `configMapGenerator`, using a non-valuated variable from a config map.
#### Readiness script
After deployment (either script-based or template-based), the GitLab CI template _optionally_ executes the `k8s-readiness-check.sh` hook script to wait & check for the application to be ready (if not found, the template assumes the application was successfully started).
......@@ -228,7 +225,7 @@ In this mode, you mainly let Kubernetes delete all objects from your Kubernetes
The template processes the following steps:
1. _optionally_ executes the `k8s-pre-cleanup.sh` script in your project to perform specific environment pre-cleanup stuff,
2. looks for your Kubernetes deployment file, performs [variables substitution](#using-variables) and [`kubectl delete`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) it,
2. looks for your Kubernetes deployment file, performs [variables substitution](#variables-substitution-mechanism) and [`kubectl delete`](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#apply) it,
1. look for a specific `deployment-$environment_type.yml` in your project (e.g. `deployment-staging.yml` for staging environment),
2. fallbacks to default `deployment.yml`.
3. _optionally_ executes the `k8s-post-cleanup.sh` script in your project to perform specific environment post-cleanup (for e.g. delete bound services).
......
......@@ -593,10 +593,16 @@ stages:
fi
deploymentdir=$(dirname "$kustofile")
# variables substitution
tbc_envsubst "$kustofile" > generated-kustomization.yml
# overwrite kustomization file with substitued variables
mv generated-kustomization.yml "$kustofile"
# apply/delete deployment descriptor
log_info "--- \\e[32mkustomize\\e[0m"
# shellcheck disable=SC2086
kubectl kustomize "$deploymentdir" ${K8S_KUSTOMIZE_ARGS} > ./generated-deployment.yml
kubectl kustomize "$deploymentdir" ${K8S_KUSTOMIZE_ARGS} > generated-deployment.yml
log_info "--- \\e[32mkubectl $action\\e[0m"
kubectl ${TRACE+-v=5} "$action" -f ./generated-deployment.yml
else
......@@ -785,7 +791,7 @@ stages:
log_info "--- \\e[32mpre-cleanup hook\\e[0m (\\e[33;1m${prescript}\\e[0m) not found: skip"
fi
# has to be valuated for envsubst
# has to be valuated for tbc_envsubst
export hostname=hostname
do_kubectl delete
......@@ -813,8 +819,18 @@ stages:
fi
deploymentdir=$(dirname "$kustofile")
# variables substitution
tbc_envsubst "$kustofile" > generated-kustomization.yml
# overwrite kustomization file with substitued variables
mv generated-kustomization.yml "$kustofile"
# apply/delete deployment descriptor
log_info "--- \\e[32mkustomize\\e[0m"
# shellcheck disable=SC2086
kustomize build ${K8S_KUSTOMIZE_ARGS} "${deploymentdir}" | /usr/bin/kube-score score $K8S_SCORE_EXTRA_OPTS -
kustomize build ${K8S_KUSTOMIZE_ARGS} "$deploymentdir" > generated-deployment.yml
# shellcheck disable=SC2086
/usr/bin/kube-score score $K8S_SCORE_EXTRA_OPTS generated-deployment.yml
else
# find deployment file
deploymentfile=$(ls -1 "$K8S_SCRIPTS_DIR/deployment-${environment_type}.yml" 2>/dev/null || ls -1 "$K8S_SCRIPTS_DIR/deployment.yml" 2>/dev/null || echo "")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment