From ec41262b3a50510b639b4b0bd560560d0847a266 Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Fri, 13 Sep 2024 14:59:35 +0200 Subject: [PATCH] adjust kustomize --- resources/apply-resources-istio.sh | 15 +++++++------ resources/apply-resources.sh | 21 ++++++++++++------- resources/{ => base}/backend/deployment.yaml | 0 resources/{ => base}/backend/hpa.yaml | 0 .../{ => base}/backend/kustomization.yaml | 0 resources/{ => base}/backend/service.yaml | 0 resources/base/environment.env | 1 + ...builtin-resource-extensions.configmap.yaml | 0 .../extensions-patch/kustomization.yaml | 0 .../web-deployment.patch.yaml | 0 .../{ingress.yaml => base/ingress.tpl.yaml} | 2 +- resources/{ => base}/ingressClass.yaml | 0 resources/{ => base}/kustomization.yaml | 1 - .../rule-sets/datree/rules.yaml | 0 .../rule-sets/default/policies.yaml | 0 .../policies.yaml | 0 .../rules.yaml | 0 .../resource-validation/rulesetSchema.json | 0 resources/{ => base}/web/configmap.yaml | 0 resources/{ => base}/web/deployment.yaml | 8 ++++++- resources/{ => base}/web/hpa.yaml | 0 resources/{ => base}/web/kustomization.yaml | 0 resources/{ => base}/web/service.yaml | 0 resources/environments/dev/environment.env | 1 + resources/environments/dev/kustomization.yaml | 6 ++++++ resources/environments/prod/environment.env | 1 + .../environments/prod/kustomization.yaml | 6 ++++++ resources/environments/stage/environment.env | 1 + .../environments/stage/kustomization.yaml | 6 ++++++ resources/istio/kustomization.yaml | 4 ---- ...te.yaml => virtualservice-busola.tpl.yaml} | 0 31 files changed, 52 insertions(+), 21 deletions(-) rename resources/{ => base}/backend/deployment.yaml (100%) rename resources/{ => base}/backend/hpa.yaml (100%) rename resources/{ => base}/backend/kustomization.yaml (100%) rename resources/{ => base}/backend/service.yaml (100%) create mode 100644 resources/base/environment.env rename resources/{ => base}/extensions-patch/builtin-resource-extensions.configmap.yaml (100%) rename resources/{ => base}/extensions-patch/kustomization.yaml (100%) rename resources/{ => base}/extensions-patch/web-deployment.patch.yaml (100%) rename resources/{ingress.yaml => base/ingress.tpl.yaml} (97%) rename resources/{ => base}/ingressClass.yaml (100%) rename resources/{ => base}/kustomization.yaml (95%) rename resources/{ => base}/resource-validation/rule-sets/datree/rules.yaml (100%) rename resources/{ => base}/resource-validation/rule-sets/default/policies.yaml (100%) rename resources/{ => base}/resource-validation/rule-sets/kubernetes-pod-security-standards/policies.yaml (100%) rename resources/{ => base}/resource-validation/rule-sets/kubernetes-pod-security-standards/rules.yaml (100%) rename resources/{ => base}/resource-validation/rulesetSchema.json (100%) rename resources/{ => base}/web/configmap.yaml (100%) rename resources/{ => base}/web/deployment.yaml (80%) rename resources/{ => base}/web/hpa.yaml (100%) rename resources/{ => base}/web/kustomization.yaml (100%) rename resources/{ => base}/web/service.yaml (100%) create mode 100644 resources/environments/dev/environment.env create mode 100644 resources/environments/dev/kustomization.yaml create mode 100644 resources/environments/prod/environment.env create mode 100644 resources/environments/prod/kustomization.yaml create mode 100644 resources/environments/stage/environment.env create mode 100644 resources/environments/stage/kustomization.yaml rename resources/istio/{virtualservice-busola-template.yaml => virtualservice-busola.tpl.yaml} (100%) diff --git a/resources/apply-resources-istio.sh b/resources/apply-resources-istio.sh index 89f8cb0ddf..f1c10eade5 100755 --- a/resources/apply-resources-istio.sh +++ b/resources/apply-resources-istio.sh @@ -1,15 +1,18 @@ -if [ -z "$1" ] ; then +#!/bin/bash +set -e + +if [ -z "$1" ] ; then echo "No domain passed as first argument, aborting." exit 1 fi export DOMAIN=$1 export NAMESPACE=${2:-busola} +export ENVIRONMENT=$3 +TMP_DIR="../temp/resources" -mkdir -p ../temp/resources -cp -rf . ../temp/resources - -envsubst < ../temp/resources/istio/virtualservice-busola-template.yaml > ../temp/resources/istio/virtualservice-busola.yaml +./apply-resources.sh "$@" -kubectl apply -k ../temp/resources/istio --namespace=$NAMESPACE +envsubst < "${TMP_DIR}"/istio/virtualservice-busola.tpl.yaml > "${TMP_DIR}"/istio/virtualservice-busola.yaml +kubectl apply -k "${TMP_DIR}"/istio --namespace=$NAMESPACE diff --git a/resources/apply-resources.sh b/resources/apply-resources.sh index d7eca07ace..f624eec7ef 100755 --- a/resources/apply-resources.sh +++ b/resources/apply-resources.sh @@ -1,16 +1,21 @@ -if [ -z "$1" ] ; then +#!/bin/bash +set -e + +if [ -z "$1" ] ; then echo "No domain passed as first argument, aborting." exit 1 fi -namespace=${2:-busola} +export DOMAIN=$1 +NAMESPACE=${2:-busola} +export ENVIRONMENT=$3 +TMP_DIR="../temp/resources" -mkdir -p ../temp/resources -cp -rf . ../temp/resources +mkdir -p "${TMP_DIR}" +cp -rf . "${TMP_DIR}" -for i in ../temp/resources/**{/*,}.yaml; do - sed -i'' "s/%DOMAIN%/$1/g" $i -done +envsubst < "${TMP_DIR}"/base/ingress.tpl.yaml > "${TMP_DIR}"/base/ingress.yaml -kubectl apply -k ../temp/resources --namespace=$namespace +kubectl create namespace "${NAMESPACE}" || true +kubectl apply -k "${TMP_DIR}/environments/${ENVIRONMENT}" --namespace="${NAMESPACE}" diff --git a/resources/backend/deployment.yaml b/resources/base/backend/deployment.yaml similarity index 100% rename from resources/backend/deployment.yaml rename to resources/base/backend/deployment.yaml diff --git a/resources/backend/hpa.yaml b/resources/base/backend/hpa.yaml similarity index 100% rename from resources/backend/hpa.yaml rename to resources/base/backend/hpa.yaml diff --git a/resources/backend/kustomization.yaml b/resources/base/backend/kustomization.yaml similarity index 100% rename from resources/backend/kustomization.yaml rename to resources/base/backend/kustomization.yaml diff --git a/resources/backend/service.yaml b/resources/base/backend/service.yaml similarity index 100% rename from resources/backend/service.yaml rename to resources/base/backend/service.yaml diff --git a/resources/base/environment.env b/resources/base/environment.env new file mode 100644 index 0000000000..52ad709329 --- /dev/null +++ b/resources/base/environment.env @@ -0,0 +1 @@ +ENVIRONMENT="test" diff --git a/resources/extensions-patch/builtin-resource-extensions.configmap.yaml b/resources/base/extensions-patch/builtin-resource-extensions.configmap.yaml similarity index 100% rename from resources/extensions-patch/builtin-resource-extensions.configmap.yaml rename to resources/base/extensions-patch/builtin-resource-extensions.configmap.yaml diff --git a/resources/extensions-patch/kustomization.yaml b/resources/base/extensions-patch/kustomization.yaml similarity index 100% rename from resources/extensions-patch/kustomization.yaml rename to resources/base/extensions-patch/kustomization.yaml diff --git a/resources/extensions-patch/web-deployment.patch.yaml b/resources/base/extensions-patch/web-deployment.patch.yaml similarity index 100% rename from resources/extensions-patch/web-deployment.patch.yaml rename to resources/base/extensions-patch/web-deployment.patch.yaml diff --git a/resources/ingress.yaml b/resources/base/ingress.tpl.yaml similarity index 97% rename from resources/ingress.yaml rename to resources/base/ingress.tpl.yaml index ba3589f0f4..afda2cee0a 100644 --- a/resources/ingress.yaml +++ b/resources/base/ingress.tpl.yaml @@ -10,7 +10,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: %DOMAIN% + - host: $DOMAIN http: paths: - backend: diff --git a/resources/ingressClass.yaml b/resources/base/ingressClass.yaml similarity index 100% rename from resources/ingressClass.yaml rename to resources/base/ingressClass.yaml diff --git a/resources/kustomization.yaml b/resources/base/kustomization.yaml similarity index 95% rename from resources/kustomization.yaml rename to resources/base/kustomization.yaml index 2fcd961732..79ab6dae88 100644 --- a/resources/kustomization.yaml +++ b/resources/base/kustomization.yaml @@ -3,6 +3,5 @@ kind: Kustomization resources: - ingress.yaml - ingressClass.yaml -bases: - backend - web diff --git a/resources/resource-validation/rule-sets/datree/rules.yaml b/resources/base/resource-validation/rule-sets/datree/rules.yaml similarity index 100% rename from resources/resource-validation/rule-sets/datree/rules.yaml rename to resources/base/resource-validation/rule-sets/datree/rules.yaml diff --git a/resources/resource-validation/rule-sets/default/policies.yaml b/resources/base/resource-validation/rule-sets/default/policies.yaml similarity index 100% rename from resources/resource-validation/rule-sets/default/policies.yaml rename to resources/base/resource-validation/rule-sets/default/policies.yaml diff --git a/resources/resource-validation/rule-sets/kubernetes-pod-security-standards/policies.yaml b/resources/base/resource-validation/rule-sets/kubernetes-pod-security-standards/policies.yaml similarity index 100% rename from resources/resource-validation/rule-sets/kubernetes-pod-security-standards/policies.yaml rename to resources/base/resource-validation/rule-sets/kubernetes-pod-security-standards/policies.yaml diff --git a/resources/resource-validation/rule-sets/kubernetes-pod-security-standards/rules.yaml b/resources/base/resource-validation/rule-sets/kubernetes-pod-security-standards/rules.yaml similarity index 100% rename from resources/resource-validation/rule-sets/kubernetes-pod-security-standards/rules.yaml rename to resources/base/resource-validation/rule-sets/kubernetes-pod-security-standards/rules.yaml diff --git a/resources/resource-validation/rulesetSchema.json b/resources/base/resource-validation/rulesetSchema.json similarity index 100% rename from resources/resource-validation/rulesetSchema.json rename to resources/base/resource-validation/rulesetSchema.json diff --git a/resources/web/configmap.yaml b/resources/base/web/configmap.yaml similarity index 100% rename from resources/web/configmap.yaml rename to resources/base/web/configmap.yaml diff --git a/resources/web/deployment.yaml b/resources/base/web/deployment.yaml similarity index 80% rename from resources/web/deployment.yaml rename to resources/base/web/deployment.yaml index 54d5c4630f..cfb4d8ff2c 100644 --- a/resources/web/deployment.yaml +++ b/resources/base/web/deployment.yaml @@ -16,8 +16,14 @@ spec: spec: containers: - name: busola - image: europe-docker.pkg.dev/kyma-project/prod/busola-web:latest + image: europe-docker.pkg.dev/kyma-project/prod/busola-kyma-web:latest imagePullPolicy: Always + env: + - name: ENVIRONMENT + valueFrom: + configMapKeyRef: + key: ENVIRONMENT + name: environment resources: requests: cpu: 100m diff --git a/resources/web/hpa.yaml b/resources/base/web/hpa.yaml similarity index 100% rename from resources/web/hpa.yaml rename to resources/base/web/hpa.yaml diff --git a/resources/web/kustomization.yaml b/resources/base/web/kustomization.yaml similarity index 100% rename from resources/web/kustomization.yaml rename to resources/base/web/kustomization.yaml diff --git a/resources/web/service.yaml b/resources/base/web/service.yaml similarity index 100% rename from resources/web/service.yaml rename to resources/base/web/service.yaml diff --git a/resources/environments/dev/environment.env b/resources/environments/dev/environment.env new file mode 100644 index 0000000000..baf48fa88b --- /dev/null +++ b/resources/environments/dev/environment.env @@ -0,0 +1 @@ +ENVIRONMENT=dev diff --git a/resources/environments/dev/kustomization.yaml b/resources/environments/dev/kustomization.yaml new file mode 100644 index 0000000000..407303f71f --- /dev/null +++ b/resources/environments/dev/kustomization.yaml @@ -0,0 +1,6 @@ +resources: + - ../../base +configMapGenerator: + - name: environment + envs: + - environment.env diff --git a/resources/environments/prod/environment.env b/resources/environments/prod/environment.env new file mode 100644 index 0000000000..2237a08b79 --- /dev/null +++ b/resources/environments/prod/environment.env @@ -0,0 +1 @@ +ENVIRONMENT=prod diff --git a/resources/environments/prod/kustomization.yaml b/resources/environments/prod/kustomization.yaml new file mode 100644 index 0000000000..407303f71f --- /dev/null +++ b/resources/environments/prod/kustomization.yaml @@ -0,0 +1,6 @@ +resources: + - ../../base +configMapGenerator: + - name: environment + envs: + - environment.env diff --git a/resources/environments/stage/environment.env b/resources/environments/stage/environment.env new file mode 100644 index 0000000000..f5c101f28d --- /dev/null +++ b/resources/environments/stage/environment.env @@ -0,0 +1 @@ +ENVIRONMENT=stage diff --git a/resources/environments/stage/kustomization.yaml b/resources/environments/stage/kustomization.yaml new file mode 100644 index 0000000000..407303f71f --- /dev/null +++ b/resources/environments/stage/kustomization.yaml @@ -0,0 +1,6 @@ +resources: + - ../../base +configMapGenerator: + - name: environment + envs: + - environment.env diff --git a/resources/istio/kustomization.yaml b/resources/istio/kustomization.yaml index b286bf2b18..ff3b2d8a2b 100644 --- a/resources/istio/kustomization.yaml +++ b/resources/istio/kustomization.yaml @@ -6,7 +6,3 @@ resources: # This will tell the istio sidecar to use TLS to connect to the backend service. # For this to work, you need to enable TLS in the backend. See docs/install-kyma-dashboard-manually.md for more information. # - destinationrule-busola-backend.yaml - -bases: - - ../backend - - ../web diff --git a/resources/istio/virtualservice-busola-template.yaml b/resources/istio/virtualservice-busola.tpl.yaml similarity index 100% rename from resources/istio/virtualservice-busola-template.yaml rename to resources/istio/virtualservice-busola.tpl.yaml