Skip to content
Snippets Groups Projects
Commit 329f1df1 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason :baby:
Browse files

feat: add defaults to improve k8s agent experience

- Set KUBE_NAMESPACE to a sensible default unless present, because
  this variable is not always set by the CI/CD tunnel.
- Use KUBE_CONTEXT if present. This makes it possible for YAML-less Auto
  DevOps users to use the agent.

Part of gitlab-org/gitlab#299350
parent 9c1d950c
No related branches found
No related tags found
No related merge requests found
Pipeline #402454032 failed
......@@ -53,20 +53,12 @@ test-kube-domain:
script:
- auto-deploy check_kube_domain
test-kube-domain-legacy:
test-kube-domain-warning:
<<: *test-job
variables:
GIT_STRATEGY: none
AUTO_DEVOPS_DOMAIN: example.com
script:
- auto-deploy check_kube_domain && expected_error || failed_as_expected
test-kube-domain_error:
<<: *test-job
variables:
GIT_STRATEGY: none
script:
- auto-deploy check_kube_domain && expected_error || failed_as_expected
- auto-deploy check_kube_domain | grep KUBE_INGRESS_BASE_DOMAIN is not defined
test-download-chart:
<<: *test-job
......@@ -255,17 +247,15 @@ test-install-postgres:
- helm get values production-postgresql --namespace "$KUBE_NAMESPACE" --output json | grep -q '"custom_key":"custom_value"' || exit 1
- kubectl get statefulset production-postgresql -n $KUBE_NAMESPACE
test-deploy:
test-deploy-defaults:
<<: *test-job
variables: &deploy-variables
CI_APPLICATION_REPOSITORY: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/auto-build-image-with-psql"
CI_APPLICATION_TAG: "5d248f6fa69a"
CI_ENVIRONMENT_SLUG: production
CI_ENVIRONMENT_URL: example.com
ADDITIONAL_HOSTS: '*.example.com, extra.host.com'
CI_PROJECT_PATH_SLUG: "gitlab-org/cluster-integration/auto-build-image"
CI_PROJECT_VISIBILITY: public
KUBE_NAMESPACE: default
KUBE_INGRESS_BASE_DOMAIN: example.com
POSTGRES_USER: user
POSTGRES_PASSWORD: testing-password
......@@ -279,6 +269,16 @@ test-deploy:
- helm get values production --output json | grep "postgres://user:testing-password@production-postgresql:5432/production"
- ./test/verify-deployment-database production postgresql
test-deploy-custom-context:
extends: test-deploy
variables: &deploy-variables
KUBE_CONTEXT: default
test-deploy-custom-namespace:
extends: test-deploy
variables: &deploy-variables
KUBE_NAMESPACE: custom-namespace
test-deploy-postgres-disabled:
extends: test-deploy
variables:
......
......@@ -15,8 +15,9 @@ auto-deploy-image provides the following APIs to orchestrate [GitLab Auto Deploy
| `CI_PROJECT_PATH_SLUG` | string | yes | See [GitLab CI Predefined Variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). | v0.1.0 ~ |
| `CI_PROJECT_VISIBILITY` | string | yes | See [GitLab CI Predefined Variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). | v0.1.0 ~ |
| `CI_REGISTRY_IMAGE` | string | yes | See [GitLab CI Predefined Variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). | v0.1.0 ~ |
| `KUBE_CONTEXT` | string | no | Context to use from within `KUBECONFIG` | v2.16.0 ~ |
| `KUBE_INGRESS_BASE_DOMAIN` | string | yes | See [GitLab Cluster Integration Deployment Variables](https://docs.gitlab.com/ee/user/project/clusters/). | v0.1.0 ~ |
| `KUBE_NAMESPACE` | string | yes | See [GitLab Cluster Integration Deployment Variables](https://docs.gitlab.com/ee/user/project/clusters/). | v0.1.0 ~ |
| `KUBE_NAMESPACE` | string | no | The deployment namespace. If not specified, the context default will be used. If the context has no default, falls back to `default` | v0.1.0 ~ |
| `KUBECONFIG` | string | yes | See [GitLab Cluster Integration Deployment Variables](https://docs.gitlab.com/ee/user/project/clusters/). | v0.1.0 ~ |
| `AUTO_DEVOPS_DEPLOY_DEBUG` | boolean | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | [v0.16.0](https://gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/compare/v0.15.0...v0.16.0) ~ |
| `HELM_RELEASE_NAME` | string | no | See [Customizing Auto DevOps](https://docs.gitlab.com/ee/topics/autodevops/customize.html). | v0.1.0 ~ |
......
......@@ -12,6 +12,25 @@ export ASSETS_DIR='/assets'
export ASSETS_CHART_DIR="${ASSETS_DIR}/auto-deploy-app"
export ROLLOUT_RESOURCE_TYPE="${ROLLOUT_RESOURCE_TYPE:-deployment}"
if [[ -z "$KUBE_NAMESPACE" ]]; then
local namespace
namespace=$(kubectl config view --minify -o jsonpath='{..namespace}')
if [[ -n "$namespace" ]]; then
export KUBE_NAMESPACE="$namespace"
else
export KUBE_NAMESPACE='default'
fi
fi
function use_kube_context() {
if [[ -z "$KUBE_CONTEXT" ]]; then
echo "KUBE_CONTEXT not defined. The default context (if present) will be used"
return
fi
echo "Using context '$KUBE_CONTEXT'"
kubectl config use-context "$KUBE_CONTEXT"
}
function check_kube_domain() {
if [[ -z "$KUBE_INGRESS_BASE_DOMAIN" ]]; then
echo "In order to deploy or use Review Apps,"
......@@ -57,7 +76,6 @@ function download_chart() {
else
helm dependency update chart/
fi
}
function add_chart_repositories() {
......@@ -534,7 +552,7 @@ function get_replicas() {
option=$1
case $option in
use_kube_context) use_kube_context ;;
check_kube_domain) check_kube_domain ;;
download_chart) download_chart ;;
ensure_namespace) ensure_namespace ;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment