From 36af10705adf5fed7a2587f0865581ba3fc5249c Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 25 Jul 2024 17:40:24 +0200 Subject: [PATCH 1/2] Add golden tests for GitLab job generator Jsonnet script --- .yamllint.yml | 2 + gitlab/Makefile | 23 +++ gitlab/Makefile.vars.mk | 3 + gitlab/tests/default.env | 2 + gitlab/tests/external-catalog.env | 2 + gitlab/tests/golden/default.yml | 61 ++++++++ gitlab/tests/golden/external-catalog.yml | 175 ++++++++++++++++++++++ gitlab/tests/golden/k8s-resources.yml | 179 +++++++++++++++++++++++ gitlab/tests/k8s-resources.env | 5 + gitlab/tests/run-instance.sh | 18 +++ 10 files changed, 470 insertions(+) create mode 100644 gitlab/tests/default.env create mode 100644 gitlab/tests/external-catalog.env create mode 100644 gitlab/tests/golden/default.yml create mode 100644 gitlab/tests/golden/external-catalog.yml create mode 100644 gitlab/tests/golden/k8s-resources.yml create mode 100644 gitlab/tests/k8s-resources.env create mode 100755 gitlab/tests/run-instance.sh diff --git a/.yamllint.yml b/.yamllint.yml index b29fc4e..9d4e669 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -1,5 +1,7 @@ --- extends: default +ignore: + - /gitlab/tests/golden/ rules: line-length: disable trailing-spaces: diff --git a/gitlab/Makefile b/gitlab/Makefile index e6d26f3..670ed47 100644 --- a/gitlab/Makefile +++ b/gitlab/Makefile @@ -12,3 +12,26 @@ jsonnetfmt_check: jsonnetfmt: JSONNET_ENTRYPOINT=jsonnetfmt jsonnetfmt: $(JSONNET_DOCKER) --in-place --pad-arrays -- *.jsonnet + +.PHONY: gen-golden +gen-golden: + @rm -f tests/golden/$(instance).yml + $(JSONNET_DOCKER) tests/run-instance.sh $(instance).env > tests/golden/$(instance).yml + +.PHONY: golden-diff +golden-diff: + @mkdir -p /tmp/commodore-compile-pipelines + $(JSONNET_DOCKER) tests/run-instance.sh $(instance).env > /tmp/commodore-compile-pipelines/$(instance).yml + @git diff --exit-code --minimal --no-index -- tests/golden/$(instance).yml /tmp/commodore-compile-pipelines/$(instance).yml + +.PHONY: golden-diff-all +golden-diff-all: recursive_target=golden-diff +golden-diff-all: $(test_instances) + +.PHONY: gen-golden-all +gen-golden-all: recursive_target=gen-golden +gen-golden-all: $(test_instances) + +.PHONY: $(test_instances) +$(test_instances): + $(MAKE) $(recursive_target) -e instance=$(basename $(@F)) diff --git a/gitlab/Makefile.vars.mk b/gitlab/Makefile.vars.mk index c47c751..518a814 100644 --- a/gitlab/Makefile.vars.mk +++ b/gitlab/Makefile.vars.mk @@ -10,3 +10,6 @@ DOCKER_ARGS ?= run --rm -u "$$(id -u):$$(id -g)" --userns=$(DOCKER_USERNS) -w /w JSONNET_IMAGE ?= docker.io/bitnami/jsonnet:latest JSONNET_ENTRYPOINT ?= bash JSONNET_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) -v "$${PWD}:/work" --entrypoint=$(JSONNET_ENTRYPOINT) $(JSONNET_IMAGE) + +test_instances=$(shell find tests/ -maxdepth 1 -name '*.env') +instance=default diff --git a/gitlab/tests/default.env b/gitlab/tests/default.env new file mode 100644 index 0000000..8176525 --- /dev/null +++ b/gitlab/tests/default.env @@ -0,0 +1,2 @@ +CLUSTERS="c-cluster-id-1234" +CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git" diff --git a/gitlab/tests/external-catalog.env b/gitlab/tests/external-catalog.env new file mode 100644 index 0000000..9c842bc --- /dev/null +++ b/gitlab/tests/external-catalog.env @@ -0,0 +1,2 @@ +CLUSTERS="c-cluster-id-1234 c-cluster-id-5678 c-cluster-id-1111" +CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git c-cluster-id-5678=ssh://git@git.example.com/cluster-catalogs/c-cluster-id-5678.git c-cluster-id-1111=https://user:pass@git.vshn.net/cluster-catalogs/c-cluster-id-1111.git5" diff --git a/gitlab/tests/golden/default.yml b/gitlab/tests/golden/default.yml new file mode 100644 index 0000000..d745dc2 --- /dev/null +++ b/gitlab/tests/golden/default.yml @@ -0,0 +1,61 @@ +{ + "c-cluster-id-1234_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_1234}@git.vshn.net:80/cluster-catalogs/c-cluster-id-1234.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-1234.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-1234", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-1234_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_1234}@git.vshn.net:80/cluster-catalogs/c-cluster-id-1234.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-1234.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-1234" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + } +} diff --git a/gitlab/tests/golden/external-catalog.yml b/gitlab/tests/golden/external-catalog.yml new file mode 100644 index 0000000..b00e7b6 --- /dev/null +++ b/gitlab/tests/golden/external-catalog.yml @@ -0,0 +1,175 @@ +{ + "c-cluster-id-1111_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-1111", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-1111_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-1111" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-1234_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_1234}@git.vshn.net:80/cluster-catalogs/c-cluster-id-1234.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-1234.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-1234", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-1234_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_1234}@git.vshn.net:80/cluster-catalogs/c-cluster-id-1234.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-1234.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-1234" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-5678_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-5678", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-5678_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-5678" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + } +} diff --git a/gitlab/tests/golden/k8s-resources.yml b/gitlab/tests/golden/k8s-resources.yml new file mode 100644 index 0000000..61ccc16 --- /dev/null +++ b/gitlab/tests/golden/k8s-resources.yml @@ -0,0 +1,179 @@ +{ + "c-cluster-id-0099_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_0099}@git.vshn.net:80/cluster-catalogs/c-cluster-id-0099.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-0099.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-0099", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2500m", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-0099_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_0099}@git.vshn.net:80/cluster-catalogs/c-cluster-id-0099.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-0099.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-0099" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2500m", + "KUBERNETES_CPU_REQUEST": "800m", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-1234_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_1234}@git.vshn.net:80/cluster-catalogs/c-cluster-id-1234.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-1234.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-1234", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "1200m", + "KUBERNETES_MEMORY_LIMIT": "3Gi" + } + }, + "c-cluster-id-1234_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_1234}@git.vshn.net:80/cluster-catalogs/c-cluster-id-1234.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-1234.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-1234" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "1200m", + "KUBERNETES_MEMORY_LIMIT": "3Gi" + } + }, + "c-cluster-id-5678_compile": { + "artifacts": { + "expire_in": "1 week", + "paths": [ + "diff.txt" + ] + }, + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_5678}@git.vshn.net:80/cluster-catalogs/c-cluster-id-5678.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-5678.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --tenant-repo-revision-override $CI_COMMIT_SHA c-cluster-id-5678", + "(cd catalog/ && git --no-pager diff --staged --output ../diff.txt)" + ], + "stage": "build", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "2", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + }, + "c-cluster-id-5678_deploy": { + "before_script": [ + "install --directory --mode=0700 ~/.ssh", + "echo \"$SSH_KNOWN_HOSTS\" >> ~/.ssh/known_hosts", + "echo \"$SSH_CONFIG\" >> ~/.ssh/config" + ], + "image": { + "name": "docker.io/projectsyn/commodore:v1.22.1" + }, + "rules": [ + { + "if": "$CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH" + } + ], + "script": [ + "git config --global url.\"https://gitlab-ci-token:${CI_JOB_TOKEN}@git.vshn.net:80\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}", + "git config --global url.\"https://gitlab-ci-token:${ACCESS_TOKEN_c_cluster_id_5678}@git.vshn.net:80/cluster-catalogs/c-cluster-id-5678.git\".insteadOf ssh://git@${CI_SERVER_SHELL_SSH_HOST}/cluster-catalogs/c-cluster-id-5678.git", + "/usr/local/bin/entrypoint.sh commodore catalog compile --push c-cluster-id-5678" + ], + "stage": "deploy", + "variables": { + "KUBERNETES_CPU_LIMIT": "2", + "KUBERNETES_CPU_REQUEST": "2", + "KUBERNETES_MEMORY_LIMIT": "2Gi" + } + } +} diff --git a/gitlab/tests/k8s-resources.env b/gitlab/tests/k8s-resources.env new file mode 100644 index 0000000..2f5d966 --- /dev/null +++ b/gitlab/tests/k8s-resources.env @@ -0,0 +1,5 @@ +CLUSTERS="c-cluster-id-1234 c-cluster-id-5678 c-cluster-id-0099" +CLUSTER_CATALOG_URLS="c-cluster-id-1234=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-1234.git c-cluster-id-5678=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-5678.git c-cluster-id-0099=ssh://git@git.vshn.net/cluster-catalogs/c-cluster-id-0099.git " +MEMORY_LIMITS="c-cluster-id-1234=3Gi" +CPU_REQUESTS="c-cluster-id-1234=1200m c-cluster-id-5678=2" +CPU_LIMITS="c-cluster-id-0099=2500m" diff --git a/gitlab/tests/run-instance.sh b/gitlab/tests/run-instance.sh new file mode 100755 index 0000000..aaa0df1 --- /dev/null +++ b/gitlab/tests/run-instance.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e -u -x + +testdir=$(dirname "$0") +env="${testdir}/${1}" + +# shellcheck source=/dev/null +source "${env}" + +jsonnet --ext-str clusters="$CLUSTERS" \ + --ext-str cluster_catalog_urls="$CLUSTER_CATALOG_URLS" \ + --ext-str server_fqdn="git.vshn.net:80" \ + --ext-str server_ssh_host="git.vshn.net" \ + --ext-str memory_limits="${MEMORY_LIMITS:-}" \ + --ext-str cpu_limits="${CPU_LIMITS:-}" \ + --ext-str cpu_requests="${CPU_REQUESTS:-}" \ + commodore-compile.jsonnet From d4dd4fd0d3e41999edb6e329fc257d48dc9b0bcb Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Thu, 25 Jul 2024 17:58:49 +0200 Subject: [PATCH 2/2] Add GitHub actions jobs which runs `golden-diff` for each test case --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ gitlab/Makefile | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d7d0be..ca91155 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,3 +31,27 @@ jobs: pattern: | *.sh step-* + + test_gitlab_generator_script_discover_cases: + name: Discover golden test cases + runs-on: ubuntu-latest + outputs: + instances: ${{ steps.instances.outputs.instances }} + steps: + - uses: actions/checkout@v4 + - name: Find test cases + id: instances + run: | + echo "instances=$(make -sC gitlab list_test_instances)" >> "$GITHUB_OUTPUT" + + test_gitlab_generator_script: + needs: test_gitlab_generator_script_discover_cases + strategy: + matrix: + instance: ${{ fromJSON(needs.test_gitlab_generator_script_discover_cases.outputs.instances) }} + runs-on: ubuntu-latest + name: 'Golden test: ${{ matrix.instance }}' + steps: + - uses: actions/checkout@v4 + - run: | + make -C gitlab golden-diff -e instance=${{ matrix.instance }} diff --git a/gitlab/Makefile b/gitlab/Makefile index 670ed47..abe4062 100644 --- a/gitlab/Makefile +++ b/gitlab/Makefile @@ -35,3 +35,8 @@ gen-golden-all: $(test_instances) .PHONY: $(test_instances) $(test_instances): $(MAKE) $(recursive_target) -e instance=$(basename $(@F)) + +.PHONY: list_test_instances +list_test_instances: JSONNET_ENTRYPOINT=jsonnet +list_test_instances: + $(JSONNET_DOCKER) --ext-str instances="$(basename $(notdir $(test_instances)))" -e 'std.split(std.extVar("instances"), " ")' | jq -c