From 0f7c9dc4854cc2e16d349963282fb11bd941feab Mon Sep 17 00:00:00 2001 From: German Lashevich Date: Tue, 12 Dec 2023 00:09:52 +0100 Subject: [PATCH] feat: new plugin for copying static files (#132) --- examples/inheritance-test/readme.md | 9 -- .../.gitignore | 0 .../.myks.yaml | 0 .../_apps/helm-installation/app-data.ytt.yaml | 0 .../helm-installation/helm/render-test.yaml | 0 .../_apps/ytt-installation/app-data.ytt.yaml | 0 .../envs/_apps/ytt-installation/ytt/app.yaml | 0 .../_proto/helm-render-test/app-data.ytt.yaml | 0 .../helm-render-test/helm/render-test.yaml | 0 .../_proto/ytt-render-test/app-data.ytt.yaml | 0 .../_proto/ytt-render-test/ytt/proto.yaml | 0 .../.myks/helm/render-test.yaml | 0 .../helm-installation/.myks/vendir.lock.yaml | 0 .../helm-installation/.myks/vendir.sync.yaml | 0 .../_apps/helm-installation/.myks/vendir.yaml | 0 .../_apps/helm-installation/app-data.ytt.yaml | 0 .../helm-installation/helm/render-test.yaml | 0 .../vendor/charts/render-test/Chart.yaml | 0 .../charts/render-test/templates/output.yaml | 0 .../vendor/charts/render-test/values.yaml | 0 .../_apps/ytt-installation/app-data.ytt.yaml | 0 .../dev/_apps/ytt-installation/ytt/app.yaml | 0 .../_proto/helm-render-test/app-data.ytt.yaml | 0 .../helm-render-test/helm/render-test.yaml | 0 .../_proto/ytt-render-test/app-data.ytt.yaml | 0 .../dev/_proto/ytt-render-test/ytt/proto.yaml | 0 .../envs/dev/env-data.ytt.yaml | 1 + .../envs/env-data.ytt.yaml | 0 .../helm-render-test/app-data.ytt.yaml | 0 .../helm-render-test/helm/render-test.yaml | 0 .../helm-render-test/vendir/base.ytt.yaml | 0 .../vendir/vendir-data.ytt.yaml | 0 .../static-test/static/literal.yaml | 9 ++ .../ytt-render-test/app-data.ytt.yaml | 0 .../prototypes/ytt-render-test/ytt/base.yaml | 0 examples/integration-tests/readme.md | 19 ++++ .../mykso-dev/app-helm-installation.yaml | 2 +- .../argocd/mykso-dev/app-static-test.yaml | 25 +++++ .../mykso-dev/app-ytt-installation.yaml | 2 +- .../argocd/mykso-dev/env-mykso-dev.yaml | 0 .../rendering-render-test.yaml | 0 .../mykso-dev/static-test/static/literal.yaml | 9 ++ .../ytt-installation/rendering-app.yaml | 0 .../ytt-installation/rendering-base.yaml | 0 .../ytt-installation/rendering-env-group.yaml | 0 .../ytt-installation/rendering-proto.yaml | 0 internal/myks/environment.go | 9 ++ internal/myks/globe.go | 2 + internal/myks/plugin_static_files.go | 46 +++++++++ internal/myks/plugin_static_files_test.go | 95 +++++++++++++++++++ internal/myks/util.go | 64 +++++++++++++ internal/myks/util_test.go | 37 +++++++- .../static-test-app/static/app_override.txt | 0 .../_apps/static-test-app/static/conflict.txt | 1 + .../static-test/envs/_env/static/conflict.txt | 1 + testData/static-test/envs/_env/static/env.txt | 0 .../static-test-proto/static/conflict.txt | 1 + .../static/proto_override.txt | 0 .../_apps/static-test-app/static/app.txt | 0 .../_apps/static-test-app/static/conflict.txt | 1 + .../static-test-env/_env/static/conflict.txt | 1 + .../_env/static/env_override.txt | 0 .../static-test-proto/static/conflict.txt | 1 + .../static-test-proto/static/proto.txt | 0 .../static-test-app/static/.gitignore | 3 + .../static-test-app/static/.keep | 0 66 files changed, 325 insertions(+), 13 deletions(-) delete mode 100644 examples/inheritance-test/readme.md rename examples/{inheritance-test => integration-tests}/.gitignore (100%) rename examples/{inheritance-test => integration-tests}/.myks.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_apps/helm-installation/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_apps/helm-installation/helm/render-test.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_apps/ytt-installation/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_apps/ytt-installation/ytt/app.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_proto/helm-render-test/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_proto/helm-render-test/helm/render-test.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_proto/ytt-render-test/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/_proto/ytt-render-test/ytt/proto.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/.myks/helm/render-test.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/.myks/vendir.lock.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/.myks/vendir.sync.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/.myks/vendir.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/helm/render-test.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/vendor/charts/render-test/Chart.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/vendor/charts/render-test/templates/output.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/helm-installation/vendor/charts/render-test/values.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/ytt-installation/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_apps/ytt-installation/ytt/app.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_proto/helm-render-test/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_proto/helm-render-test/helm/render-test.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_proto/ytt-render-test/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/_proto/ytt-render-test/ytt/proto.yaml (100%) rename examples/{inheritance-test => integration-tests}/envs/dev/env-data.ytt.yaml (92%) rename examples/{inheritance-test => integration-tests}/envs/env-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/prototypes/helm-render-test/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/prototypes/helm-render-test/helm/render-test.yaml (100%) rename examples/{inheritance-test => integration-tests}/prototypes/helm-render-test/vendir/base.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/prototypes/helm-render-test/vendir/vendir-data.ytt.yaml (100%) create mode 100644 examples/integration-tests/prototypes/static-test/static/literal.yaml rename examples/{inheritance-test => integration-tests}/prototypes/ytt-render-test/app-data.ytt.yaml (100%) rename examples/{inheritance-test => integration-tests}/prototypes/ytt-render-test/ytt/base.yaml (100%) create mode 100644 examples/integration-tests/readme.md rename examples/{inheritance-test => integration-tests}/rendered/argocd/mykso-dev/app-helm-installation.yaml (87%) create mode 100644 examples/integration-tests/rendered/argocd/mykso-dev/app-static-test.yaml rename examples/{inheritance-test => integration-tests}/rendered/argocd/mykso-dev/app-ytt-installation.yaml (87%) rename examples/{inheritance-test => integration-tests}/rendered/argocd/mykso-dev/env-mykso-dev.yaml (100%) rename examples/{inheritance-test => integration-tests}/rendered/envs/mykso-dev/helm-installation/rendering-render-test.yaml (100%) create mode 100644 examples/integration-tests/rendered/envs/mykso-dev/static-test/static/literal.yaml rename examples/{inheritance-test => integration-tests}/rendered/envs/mykso-dev/ytt-installation/rendering-app.yaml (100%) rename examples/{inheritance-test => integration-tests}/rendered/envs/mykso-dev/ytt-installation/rendering-base.yaml (100%) rename examples/{inheritance-test => integration-tests}/rendered/envs/mykso-dev/ytt-installation/rendering-env-group.yaml (100%) rename examples/{inheritance-test => integration-tests}/rendered/envs/mykso-dev/ytt-installation/rendering-proto.yaml (100%) create mode 100644 internal/myks/plugin_static_files.go create mode 100644 internal/myks/plugin_static_files_test.go create mode 100644 testData/static-test/envs/_apps/static-test-app/static/app_override.txt create mode 100644 testData/static-test/envs/_apps/static-test-app/static/conflict.txt create mode 100644 testData/static-test/envs/_env/static/conflict.txt create mode 100644 testData/static-test/envs/_env/static/env.txt create mode 100644 testData/static-test/envs/_proto/static-test-proto/static/conflict.txt create mode 100644 testData/static-test/envs/_proto/static-test-proto/static/proto_override.txt create mode 100644 testData/static-test/envs/static-test-env/_apps/static-test-app/static/app.txt create mode 100644 testData/static-test/envs/static-test-env/_apps/static-test-app/static/conflict.txt create mode 100644 testData/static-test/envs/static-test-env/_env/static/conflict.txt create mode 100644 testData/static-test/envs/static-test-env/_env/static/env_override.txt create mode 100644 testData/static-test/prototypes/static-test-proto/static/conflict.txt create mode 100644 testData/static-test/prototypes/static-test-proto/static/proto.txt create mode 100644 testData/static-test/rendered/envs/static-test-env/static-test-app/static/.gitignore create mode 100644 testData/static-test/rendered/envs/static-test-env/static-test-app/static/.keep diff --git a/examples/inheritance-test/readme.md b/examples/inheritance-test/readme.md deleted file mode 100644 index 6821066c..00000000 --- a/examples/inheritance-test/readme.md +++ /dev/null @@ -1,9 +0,0 @@ -# Inheritance test - -This examples tests the full power of myks inheritance for helm and ytt rendering leveraging: - -- config from the base app -- config from environment group level -- config from application level - -Both environment group level and application level are rendering with prototype override config as well as appliction specific config. diff --git a/examples/inheritance-test/.gitignore b/examples/integration-tests/.gitignore similarity index 100% rename from examples/inheritance-test/.gitignore rename to examples/integration-tests/.gitignore diff --git a/examples/inheritance-test/.myks.yaml b/examples/integration-tests/.myks.yaml similarity index 100% rename from examples/inheritance-test/.myks.yaml rename to examples/integration-tests/.myks.yaml diff --git a/examples/inheritance-test/envs/_apps/helm-installation/app-data.ytt.yaml b/examples/integration-tests/envs/_apps/helm-installation/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/_apps/helm-installation/app-data.ytt.yaml rename to examples/integration-tests/envs/_apps/helm-installation/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/_apps/helm-installation/helm/render-test.yaml b/examples/integration-tests/envs/_apps/helm-installation/helm/render-test.yaml similarity index 100% rename from examples/inheritance-test/envs/_apps/helm-installation/helm/render-test.yaml rename to examples/integration-tests/envs/_apps/helm-installation/helm/render-test.yaml diff --git a/examples/inheritance-test/envs/_apps/ytt-installation/app-data.ytt.yaml b/examples/integration-tests/envs/_apps/ytt-installation/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/_apps/ytt-installation/app-data.ytt.yaml rename to examples/integration-tests/envs/_apps/ytt-installation/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/_apps/ytt-installation/ytt/app.yaml b/examples/integration-tests/envs/_apps/ytt-installation/ytt/app.yaml similarity index 100% rename from examples/inheritance-test/envs/_apps/ytt-installation/ytt/app.yaml rename to examples/integration-tests/envs/_apps/ytt-installation/ytt/app.yaml diff --git a/examples/inheritance-test/envs/_proto/helm-render-test/app-data.ytt.yaml b/examples/integration-tests/envs/_proto/helm-render-test/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/_proto/helm-render-test/app-data.ytt.yaml rename to examples/integration-tests/envs/_proto/helm-render-test/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/_proto/helm-render-test/helm/render-test.yaml b/examples/integration-tests/envs/_proto/helm-render-test/helm/render-test.yaml similarity index 100% rename from examples/inheritance-test/envs/_proto/helm-render-test/helm/render-test.yaml rename to examples/integration-tests/envs/_proto/helm-render-test/helm/render-test.yaml diff --git a/examples/inheritance-test/envs/_proto/ytt-render-test/app-data.ytt.yaml b/examples/integration-tests/envs/_proto/ytt-render-test/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/_proto/ytt-render-test/app-data.ytt.yaml rename to examples/integration-tests/envs/_proto/ytt-render-test/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/_proto/ytt-render-test/ytt/proto.yaml b/examples/integration-tests/envs/_proto/ytt-render-test/ytt/proto.yaml similarity index 100% rename from examples/inheritance-test/envs/_proto/ytt-render-test/ytt/proto.yaml rename to examples/integration-tests/envs/_proto/ytt-render-test/ytt/proto.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/helm/render-test.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/.myks/helm/render-test.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/helm/render-test.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/.myks/helm/render-test.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/vendir.lock.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/.myks/vendir.lock.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/vendir.lock.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/.myks/vendir.lock.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/vendir.sync.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/.myks/vendir.sync.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/vendir.sync.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/.myks/vendir.sync.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/vendir.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/.myks/vendir.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/.myks/vendir.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/.myks/vendir.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/app-data.ytt.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/app-data.ytt.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/helm/render-test.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/helm/render-test.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/helm/render-test.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/helm/render-test.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/vendor/charts/render-test/Chart.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/vendor/charts/render-test/Chart.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/vendor/charts/render-test/Chart.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/vendor/charts/render-test/Chart.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/vendor/charts/render-test/templates/output.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/vendor/charts/render-test/templates/output.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/vendor/charts/render-test/templates/output.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/vendor/charts/render-test/templates/output.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/helm-installation/vendor/charts/render-test/values.yaml b/examples/integration-tests/envs/dev/_apps/helm-installation/vendor/charts/render-test/values.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/helm-installation/vendor/charts/render-test/values.yaml rename to examples/integration-tests/envs/dev/_apps/helm-installation/vendor/charts/render-test/values.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/ytt-installation/app-data.ytt.yaml b/examples/integration-tests/envs/dev/_apps/ytt-installation/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/ytt-installation/app-data.ytt.yaml rename to examples/integration-tests/envs/dev/_apps/ytt-installation/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/dev/_apps/ytt-installation/ytt/app.yaml b/examples/integration-tests/envs/dev/_apps/ytt-installation/ytt/app.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_apps/ytt-installation/ytt/app.yaml rename to examples/integration-tests/envs/dev/_apps/ytt-installation/ytt/app.yaml diff --git a/examples/inheritance-test/envs/dev/_proto/helm-render-test/app-data.ytt.yaml b/examples/integration-tests/envs/dev/_proto/helm-render-test/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_proto/helm-render-test/app-data.ytt.yaml rename to examples/integration-tests/envs/dev/_proto/helm-render-test/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/dev/_proto/helm-render-test/helm/render-test.yaml b/examples/integration-tests/envs/dev/_proto/helm-render-test/helm/render-test.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_proto/helm-render-test/helm/render-test.yaml rename to examples/integration-tests/envs/dev/_proto/helm-render-test/helm/render-test.yaml diff --git a/examples/inheritance-test/envs/dev/_proto/ytt-render-test/app-data.ytt.yaml b/examples/integration-tests/envs/dev/_proto/ytt-render-test/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_proto/ytt-render-test/app-data.ytt.yaml rename to examples/integration-tests/envs/dev/_proto/ytt-render-test/app-data.ytt.yaml diff --git a/examples/inheritance-test/envs/dev/_proto/ytt-render-test/ytt/proto.yaml b/examples/integration-tests/envs/dev/_proto/ytt-render-test/ytt/proto.yaml similarity index 100% rename from examples/inheritance-test/envs/dev/_proto/ytt-render-test/ytt/proto.yaml rename to examples/integration-tests/envs/dev/_proto/ytt-render-test/ytt/proto.yaml diff --git a/examples/inheritance-test/envs/dev/env-data.ytt.yaml b/examples/integration-tests/envs/dev/env-data.ytt.yaml similarity index 92% rename from examples/inheritance-test/envs/dev/env-data.ytt.yaml rename to examples/integration-tests/envs/dev/env-data.ytt.yaml index 2d667290..17c0032b 100644 --- a/examples/inheritance-test/envs/dev/env-data.ytt.yaml +++ b/examples/integration-tests/envs/dev/env-data.ytt.yaml @@ -9,3 +9,4 @@ environment: name: helm-installation - proto: ytt-render-test name: ytt-installation + - proto: static-test diff --git a/examples/inheritance-test/envs/env-data.ytt.yaml b/examples/integration-tests/envs/env-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/envs/env-data.ytt.yaml rename to examples/integration-tests/envs/env-data.ytt.yaml diff --git a/examples/inheritance-test/prototypes/helm-render-test/app-data.ytt.yaml b/examples/integration-tests/prototypes/helm-render-test/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/prototypes/helm-render-test/app-data.ytt.yaml rename to examples/integration-tests/prototypes/helm-render-test/app-data.ytt.yaml diff --git a/examples/inheritance-test/prototypes/helm-render-test/helm/render-test.yaml b/examples/integration-tests/prototypes/helm-render-test/helm/render-test.yaml similarity index 100% rename from examples/inheritance-test/prototypes/helm-render-test/helm/render-test.yaml rename to examples/integration-tests/prototypes/helm-render-test/helm/render-test.yaml diff --git a/examples/inheritance-test/prototypes/helm-render-test/vendir/base.ytt.yaml b/examples/integration-tests/prototypes/helm-render-test/vendir/base.ytt.yaml similarity index 100% rename from examples/inheritance-test/prototypes/helm-render-test/vendir/base.ytt.yaml rename to examples/integration-tests/prototypes/helm-render-test/vendir/base.ytt.yaml diff --git a/examples/inheritance-test/prototypes/helm-render-test/vendir/vendir-data.ytt.yaml b/examples/integration-tests/prototypes/helm-render-test/vendir/vendir-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/prototypes/helm-render-test/vendir/vendir-data.ytt.yaml rename to examples/integration-tests/prototypes/helm-render-test/vendir/vendir-data.ytt.yaml diff --git a/examples/integration-tests/prototypes/static-test/static/literal.yaml b/examples/integration-tests/prototypes/static-test/static/literal.yaml new file mode 100644 index 00000000..8b769cc2 --- /dev/null +++ b/examples/integration-tests/prototypes/static-test/static/literal.yaml @@ -0,0 +1,9 @@ +--- +# https://kubernetes.io/docs/concepts/configuration/configmap/ +apiVersion: v1 +kind: ConfigMap +metadata: + name: static-test-cm + namespace: default +data: + key: value diff --git a/examples/inheritance-test/prototypes/ytt-render-test/app-data.ytt.yaml b/examples/integration-tests/prototypes/ytt-render-test/app-data.ytt.yaml similarity index 100% rename from examples/inheritance-test/prototypes/ytt-render-test/app-data.ytt.yaml rename to examples/integration-tests/prototypes/ytt-render-test/app-data.ytt.yaml diff --git a/examples/inheritance-test/prototypes/ytt-render-test/ytt/base.yaml b/examples/integration-tests/prototypes/ytt-render-test/ytt/base.yaml similarity index 100% rename from examples/inheritance-test/prototypes/ytt-render-test/ytt/base.yaml rename to examples/integration-tests/prototypes/ytt-render-test/ytt/base.yaml diff --git a/examples/integration-tests/readme.md b/examples/integration-tests/readme.md new file mode 100644 index 00000000..840b5cc3 --- /dev/null +++ b/examples/integration-tests/readme.md @@ -0,0 +1,19 @@ +# Integration tests + +This directory contains configuration for myks' integration tests. + +## Test areas + +### Inheritance + +This examples tests the full power of myks inheritance for helm and ytt rendering leveraging: + +- config from the base app +- config from environment group level +- config from application level + +Both environment group level and application level are rendering with prototype override config as well as application specific config. + +### Static files + +This example tests the ability to correctly render static files from the `static` directories. diff --git a/examples/inheritance-test/rendered/argocd/mykso-dev/app-helm-installation.yaml b/examples/integration-tests/rendered/argocd/mykso-dev/app-helm-installation.yaml similarity index 87% rename from examples/inheritance-test/rendered/argocd/mykso-dev/app-helm-installation.yaml rename to examples/integration-tests/rendered/argocd/mykso-dev/app-helm-installation.yaml index 408f0b7a..431ac9f3 100644 --- a/examples/inheritance-test/rendered/argocd/mykso-dev/app-helm-installation.yaml +++ b/examples/integration-tests/rendered/argocd/mykso-dev/app-helm-installation.yaml @@ -11,7 +11,7 @@ spec: name: mykso-dev namespace: helm-installation source: - path: examples/inheritance-test/rendered/envs/mykso-dev/helm-installation + path: examples/integration-tests/rendered/envs/mykso-dev/helm-installation plugin: name: argocd-vault-plugin-v1.0.0 repoURL: git@github.com:mykso/myks.git diff --git a/examples/integration-tests/rendered/argocd/mykso-dev/app-static-test.yaml b/examples/integration-tests/rendered/argocd/mykso-dev/app-static-test.yaml new file mode 100644 index 00000000..e1fe7d14 --- /dev/null +++ b/examples/integration-tests/rendered/argocd/mykso-dev/app-static-test.yaml @@ -0,0 +1,25 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: app-mykso-dev-static-test + namespace: system-argocd + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: env-mykso-dev + destination: + name: mykso-dev + namespace: static-test + source: + path: examples/integration-tests/rendered/envs/mykso-dev/static-test + plugin: + name: argocd-vault-plugin-v1.0.0 + repoURL: git@github.com:mykso/myks.git + targetRevision: main + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true + - ServerSideApply=true diff --git a/examples/inheritance-test/rendered/argocd/mykso-dev/app-ytt-installation.yaml b/examples/integration-tests/rendered/argocd/mykso-dev/app-ytt-installation.yaml similarity index 87% rename from examples/inheritance-test/rendered/argocd/mykso-dev/app-ytt-installation.yaml rename to examples/integration-tests/rendered/argocd/mykso-dev/app-ytt-installation.yaml index 230f89a8..e963b802 100644 --- a/examples/inheritance-test/rendered/argocd/mykso-dev/app-ytt-installation.yaml +++ b/examples/integration-tests/rendered/argocd/mykso-dev/app-ytt-installation.yaml @@ -11,7 +11,7 @@ spec: name: mykso-dev namespace: ytt-installation source: - path: examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation + path: examples/integration-tests/rendered/envs/mykso-dev/ytt-installation plugin: name: argocd-vault-plugin-v1.0.0 repoURL: git@github.com:mykso/myks.git diff --git a/examples/inheritance-test/rendered/argocd/mykso-dev/env-mykso-dev.yaml b/examples/integration-tests/rendered/argocd/mykso-dev/env-mykso-dev.yaml similarity index 100% rename from examples/inheritance-test/rendered/argocd/mykso-dev/env-mykso-dev.yaml rename to examples/integration-tests/rendered/argocd/mykso-dev/env-mykso-dev.yaml diff --git a/examples/inheritance-test/rendered/envs/mykso-dev/helm-installation/rendering-render-test.yaml b/examples/integration-tests/rendered/envs/mykso-dev/helm-installation/rendering-render-test.yaml similarity index 100% rename from examples/inheritance-test/rendered/envs/mykso-dev/helm-installation/rendering-render-test.yaml rename to examples/integration-tests/rendered/envs/mykso-dev/helm-installation/rendering-render-test.yaml diff --git a/examples/integration-tests/rendered/envs/mykso-dev/static-test/static/literal.yaml b/examples/integration-tests/rendered/envs/mykso-dev/static-test/static/literal.yaml new file mode 100644 index 00000000..8b769cc2 --- /dev/null +++ b/examples/integration-tests/rendered/envs/mykso-dev/static-test/static/literal.yaml @@ -0,0 +1,9 @@ +--- +# https://kubernetes.io/docs/concepts/configuration/configmap/ +apiVersion: v1 +kind: ConfigMap +metadata: + name: static-test-cm + namespace: default +data: + key: value diff --git a/examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-app.yaml b/examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-app.yaml similarity index 100% rename from examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-app.yaml rename to examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-app.yaml diff --git a/examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-base.yaml b/examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-base.yaml similarity index 100% rename from examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-base.yaml rename to examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-base.yaml diff --git a/examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-env-group.yaml b/examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-env-group.yaml similarity index 100% rename from examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-env-group.yaml rename to examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-env-group.yaml diff --git a/examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-proto.yaml b/examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-proto.yaml similarity index 100% rename from examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation/rendering-proto.yaml rename to examples/integration-tests/rendered/envs/mykso-dev/ytt-installation/rendering-proto.yaml diff --git a/internal/myks/environment.go b/internal/myks/environment.go index 20a006ac..1b641dff 100644 --- a/internal/myks/environment.go +++ b/internal/myks/environment.go @@ -96,6 +96,10 @@ func (e *Environment) Render(asyncLevel int) error { return err } + if err := app.copyStaticFiles(); err != nil { + return err + } + return app.renderArgoCD() }) if err != nil { @@ -127,6 +131,11 @@ func (e *Environment) SyncAndRender(asyncLevel int, vendirSecrets string) error if err := app.RenderAndSlice(yamlTemplatingTools); err != nil { return err } + + if err := app.copyStaticFiles(); err != nil { + return err + } + return app.renderArgoCD() }) if err != nil { diff --git a/internal/myks/globe.go b/internal/myks/globe.go index 9ac84f3e..8d655f19 100644 --- a/internal/myks/globe.go +++ b/internal/myks/globe.go @@ -53,6 +53,8 @@ type Globe struct { MyksDataFileName string `default:"myks-data.ytt.yaml"` // Rendered environment data file name RenderedEnvironmentDataFileName string `default:"env-data.yaml"` + // Static files directory name + StaticFilesDirName string `default:"static"` // Service directory name ServiceDirName string `default:".myks"` // Temporary directory name diff --git a/internal/myks/plugin_static_files.go b/internal/myks/plugin_static_files.go new file mode 100644 index 00000000..470e3a16 --- /dev/null +++ b/internal/myks/plugin_static_files.go @@ -0,0 +1,46 @@ +package myks + +import ( + "path/filepath" + + "github.com/rs/zerolog/log" +) + +const StaticFilesStepName = "static-files" + +func (a *Application) copyStaticFiles() (err error) { + logStaticFiles := func(files []string) { + log.Trace().Strs("staticFiles", files).Msg(a.Msg(StaticFilesStepName, "Static files")) + } + staticFilesDirs := []string{} + + // 1. Static files from the prototype + prototypeStaticFilesDir := filepath.Join(a.Prototype, a.e.g.StaticFilesDirName) + if ok, err := isExist(prototypeStaticFilesDir); err != nil { + return err + } else if ok { + staticFilesDirs = append(staticFilesDirs, prototypeStaticFilesDir) + } + logStaticFiles(staticFilesDirs) + // 2. Static files from prototype overrides + staticFilesDirs = append(staticFilesDirs, a.e.collectBySubpath(filepath.Join("_proto", a.prototypeDirName(), a.e.g.StaticFilesDirName))...) + logStaticFiles(staticFilesDirs) + + // 3. Static files from the environment + staticFilesDirs = append(staticFilesDirs, a.e.collectBySubpath(filepath.Join("_env", a.e.g.StaticFilesDirName))...) + logStaticFiles(staticFilesDirs) + // 4. Static files from the application + staticFilesDirs = append(staticFilesDirs, a.e.collectBySubpath(filepath.Join("_apps", a.Name, a.e.g.StaticFilesDirName))...) + logStaticFiles(staticFilesDirs) + + staticFilesDestination := filepath.Join(a.getDestinationDir(), a.e.g.StaticFilesDirName) + + for _, staticFilesDir := range staticFilesDirs { + if err = copyDir(staticFilesDir, staticFilesDestination, true); err != nil { + log.Error().Err(err).Msg(a.Msg(StaticFilesStepName, "Unable to copy static files")) + return err + } + } + + return nil +} diff --git a/internal/myks/plugin_static_files_test.go b/internal/myks/plugin_static_files_test.go new file mode 100644 index 00000000..c110b55a --- /dev/null +++ b/internal/myks/plugin_static_files_test.go @@ -0,0 +1,95 @@ +package myks + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/creasty/defaults" + "github.com/rs/zerolog/log" +) + +func TestApplication_copyStaticFiles(t *testing.T) { + defer chdir(t, "../../testData/static-test")() + + envName := "static-test-env" + appName := "static-test-app" + protoName := "static-test-proto" + + globe := &Globe{} + if err := defaults.Set(globe); err != nil { + log.Fatal().Err(err).Msg("Unable to set defaults") + } + + env := &Environment{ + Id: envName, + g: globe, + Dir: filepath.Join(globe.EnvironmentBaseDir, envName), + } + + app := &Application{ + Name: appName, + Prototype: fmt.Sprintf("%s/%s", globe.PrototypesDir, protoName), + e: env, + } + + targetDir := app.getDestinationDir() + + isIgnored := func(info os.DirEntry) bool { + return info.IsDir() || info.Name() == ".keep" || info.Name() == ".gitignore" + } + + // Cleanup copied files + defer func() { + if err := filepath.WalkDir(targetDir, func(path string, info os.DirEntry, err error) error { + if err != nil { + return err + } + if isIgnored(info) { + return nil + } + return os.Remove(path) + }); err != nil { + t.Errorf("copyStaticFiles() error = %v", err) + } + }() + + if err := app.copyStaticFiles(); err != nil { + t.Errorf("copyStaticFiles() error = %v", err) + } + + expectedFiles := map[string]string{ + "/static/app.txt": "", + "/static/app_override.txt": "", + "/static/conflict.txt": "application", + "/static/env.txt": "", + "/static/env_override.txt": "", + "/static/proto.txt": "", + "/static/proto_override.txt": "", + } + + generatedFiles := map[string]string{} + if err := filepath.WalkDir(targetDir, func(path string, info os.DirEntry, err error) error { + if err != nil { + return err + } + if isIgnored(info) { + return nil + } + + content, err := os.ReadFile(path) + if err != nil { + return err + } + path = strings.TrimPrefix(path, targetDir) + generatedFiles[path] = strings.Trim(string(content), "\n") + + return nil + }); err != nil { + t.Errorf("copyStaticFiles() error = %v", err) + } + + assertEqual(t, generatedFiles, expectedFiles) +} diff --git a/internal/myks/util.go b/internal/myks/util.go index cc9ea528..1ab21c5d 100644 --- a/internal/myks/util.go +++ b/internal/myks/util.go @@ -335,3 +335,67 @@ func collectBySubpath(rootDir string, targetDir string, subpath string) []string } return items } + +// copyDir copies a directory recursively, overwriting existing files if overwrite is true. +// If overwrite is false, existing files will not be overwritten, an error will be returned instead. +// The destination directory will be created if it does not exist. +func copyDir(src, dst string, overwrite bool) (err error) { + if err = os.MkdirAll(dst, os.ModePerm); err != nil { + return + } + + err = filepath.WalkDir(src, func(path string, d os.DirEntry, err error) error { + if err != nil { + return err + } + + relPath, err := filepath.Rel(src, path) + if err != nil { + return err + } + + dstPath := filepath.Join(dst, relPath) + + if d.IsDir() { + if err = os.MkdirAll(dstPath, os.ModePerm); err != nil { + return err + } + } else { + if !overwrite { + if _, err = os.Stat(dstPath); err == nil { + return nil + } + } + + if err = copyFile(path, dstPath); err != nil { + return err + } + } + + return nil + }) + + return err +} + +// copyFile copies a file from src to dst. +func copyFile(src, dst string) (err error) { + dstFile, err := os.Create(dst) + if err != nil { + return + } + defer dstFile.Close() + + srcFile, err := os.Open(src) + if err != nil { + return + } + defer srcFile.Close() + + _, err = io.Copy(dstFile, srcFile) + if err != nil { + return + } + + return nil +} diff --git a/internal/myks/util_test.go b/internal/myks/util_test.go index a7488f4a..c8315467 100644 --- a/internal/myks/util_test.go +++ b/internal/myks/util_test.go @@ -1,6 +1,7 @@ package myks import ( + "encoding/json" "errors" "fmt" "io" @@ -406,9 +407,17 @@ func assertEqual(t *testing.T, got, want interface{}) { } func diff(expected, actual interface{}) string { + jsonExpected, err := json.MarshalIndent(expected, "", " ") + if err != nil { + return err.Error() + } + jsonActual, err := json.MarshalIndent(actual, "", " ") + if err != nil { + return err.Error() + } diff := difflib.UnifiedDiff{ - A: difflib.SplitLines(fmt.Sprintf("%v", expected)), - B: difflib.SplitLines(fmt.Sprintf("%v", actual)), + A: difflib.SplitLines(string(jsonExpected)), + B: difflib.SplitLines(string(jsonActual)), FromFile: "Expected", ToFile: "Actual", Context: 3, @@ -418,6 +427,30 @@ func diff(expected, actual interface{}) string { return text } +// chdir changes the current working directory to the named directory and +// returns a function that, when called, restores the original working +// directory. +// Usage: +// +// defer chdir(t, "testdata")() +// +// Credit: https://github.com/golang/go/issues/45182#issue-838791504 +func chdir(t *testing.T, dir string) func() { + wd, err := os.Getwd() + if err != nil { + t.Fatalf("chdir %s: %v", dir, err) + } + if err := os.Chdir(dir); err != nil { + t.Fatal(err) + } + + return func() { + if err := os.Chdir(wd); err != nil { + t.Fatalf("restoring working directory: %v", err) + } + } +} + func Test_extract(t *testing.T) { type TestMe struct { Name string diff --git a/testData/static-test/envs/_apps/static-test-app/static/app_override.txt b/testData/static-test/envs/_apps/static-test-app/static/app_override.txt new file mode 100644 index 00000000..e69de29b diff --git a/testData/static-test/envs/_apps/static-test-app/static/conflict.txt b/testData/static-test/envs/_apps/static-test-app/static/conflict.txt new file mode 100644 index 00000000..49821ace --- /dev/null +++ b/testData/static-test/envs/_apps/static-test-app/static/conflict.txt @@ -0,0 +1 @@ +application override diff --git a/testData/static-test/envs/_env/static/conflict.txt b/testData/static-test/envs/_env/static/conflict.txt new file mode 100644 index 00000000..d554f944 --- /dev/null +++ b/testData/static-test/envs/_env/static/conflict.txt @@ -0,0 +1 @@ +environment diff --git a/testData/static-test/envs/_env/static/env.txt b/testData/static-test/envs/_env/static/env.txt new file mode 100644 index 00000000..e69de29b diff --git a/testData/static-test/envs/_proto/static-test-proto/static/conflict.txt b/testData/static-test/envs/_proto/static-test-proto/static/conflict.txt new file mode 100644 index 00000000..7729d011 --- /dev/null +++ b/testData/static-test/envs/_proto/static-test-proto/static/conflict.txt @@ -0,0 +1 @@ +prototype override diff --git a/testData/static-test/envs/_proto/static-test-proto/static/proto_override.txt b/testData/static-test/envs/_proto/static-test-proto/static/proto_override.txt new file mode 100644 index 00000000..e69de29b diff --git a/testData/static-test/envs/static-test-env/_apps/static-test-app/static/app.txt b/testData/static-test/envs/static-test-env/_apps/static-test-app/static/app.txt new file mode 100644 index 00000000..e69de29b diff --git a/testData/static-test/envs/static-test-env/_apps/static-test-app/static/conflict.txt b/testData/static-test/envs/static-test-env/_apps/static-test-app/static/conflict.txt new file mode 100644 index 00000000..b8646a42 --- /dev/null +++ b/testData/static-test/envs/static-test-env/_apps/static-test-app/static/conflict.txt @@ -0,0 +1 @@ +application diff --git a/testData/static-test/envs/static-test-env/_env/static/conflict.txt b/testData/static-test/envs/static-test-env/_env/static/conflict.txt new file mode 100644 index 00000000..2a25a7fa --- /dev/null +++ b/testData/static-test/envs/static-test-env/_env/static/conflict.txt @@ -0,0 +1 @@ +environment override diff --git a/testData/static-test/envs/static-test-env/_env/static/env_override.txt b/testData/static-test/envs/static-test-env/_env/static/env_override.txt new file mode 100644 index 00000000..e69de29b diff --git a/testData/static-test/prototypes/static-test-proto/static/conflict.txt b/testData/static-test/prototypes/static-test-proto/static/conflict.txt new file mode 100644 index 00000000..5f28f5b4 --- /dev/null +++ b/testData/static-test/prototypes/static-test-proto/static/conflict.txt @@ -0,0 +1 @@ +prototype diff --git a/testData/static-test/prototypes/static-test-proto/static/proto.txt b/testData/static-test/prototypes/static-test-proto/static/proto.txt new file mode 100644 index 00000000..e69de29b diff --git a/testData/static-test/rendered/envs/static-test-env/static-test-app/static/.gitignore b/testData/static-test/rendered/envs/static-test-env/static-test-app/static/.gitignore new file mode 100644 index 00000000..1c0813ee --- /dev/null +++ b/testData/static-test/rendered/envs/static-test-env/static-test-app/static/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!.keep diff --git a/testData/static-test/rendered/envs/static-test-env/static-test-app/static/.keep b/testData/static-test/rendered/envs/static-test-env/static-test-app/static/.keep new file mode 100644 index 00000000..e69de29b