Skip to content

Commit

Permalink
feat: implement prototype overwrites in the envs tree (#110)
Browse files Browse the repository at this point in the history
Makes configuration at environment group level for multiple apps
installed to the same environment possible. Does so, by using the
directory structure in the "prototypes" folder to look for helm and ytt
configuration at env group level.

closes #109
  • Loading branch information
fritzduchardt authored and Zebradil committed Dec 4, 2023
1 parent 8b44de6 commit c3e550d
Show file tree
Hide file tree
Showing 56 changed files with 455 additions and 15 deletions.
5 changes: 5 additions & 0 deletions examples/charts/render-test-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: v0.0.1
description: Local Helm chart to test rendering.
name: local-renderer
version: 0.0.1
5 changes: 5 additions & 0 deletions examples/charts/render-test-chart/templates/output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: rendering
metadata:
name: render-test
outputYaml:
{{ toYaml .Values.outputYaml | indent 2 }}
2 changes: 2 additions & 0 deletions examples/charts/render-test-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
outputYaml:
fromChartDefaultValues: true
1 change: 1 addition & 0 deletions examples/inheritance-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.myks/tmp/
7 changes: 7 additions & 0 deletions examples/inheritance-test/.myks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# Sets the number of applications to be processed in parallel.
# The default (0) is no limit.
async: 0
# One of the zerolog log levels.
# See: https://github.com/rs/zerolog#leveled-logging
log-level: info
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
envGroupValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@ load("@ytt:data", "data")
---
outputYaml:
fromEnvGroup: true
fromEnvGroupAppData: #@ data.values.application.envGroupValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
envGroupValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#@ load("@ytt:data", "data")
---
kind: rendering
metadata:
name: env-group
outputYaml:
fromEnvGroup: true
fromEnvGroupAppData: #@ data.values.application.envGroupValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
protoOverwriteValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@ load("@ytt:data", "data")
---
outputYaml:
fromPrototypeOverride: true
fromPrototypeOverrideFromAppData: #@ data.values.application.protoOverwriteValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
protoOverwriteValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#@ load("@ytt:data", "data")
---
kind: rendering
metadata:
name: proto
outputYaml:
fromPrototypeOverride: true
fromPrototypeOverrideFromAppData: #@ data.values.application.protoOverwriteValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
outputYaml:
fromPrototype: true
fromPrototypeAppData: true
fromPrototypeOverride: true
fromPrototypeOverrideFromAppData: true
fromEnvGroup: true
fromEnvGroupAppData: true
fromAppConfig: true
fromAppConfigAppData: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: vendir.k14s.io/v1alpha1
directories:
- contents:
- directory: {}
path: .
path: charts/render-test
kind: LockConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
charts/render-test: f6e95b613adfa1959faef2c0d661b198dcfa7b9058d89dd76418ed58d67b5f95
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: charts/render-test
contents:
- path: .
directory:
name: render-test
path: ../../../../../../charts/render-test-chart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
appValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@ load("@ytt:data", "data")
---
outputYaml:
fromAppConfig: true
fromAppConfigAppData: #@ data.values.application.appValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: v0.0.1
description: Local Helm chart to test rendering.
name: local-renderer
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: rendering
metadata:
name: render-test
outputYaml:
{{ toYaml .Values.outputYaml | indent 2 }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
outputYaml:
fromChartDefaultValues: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
appValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#@ load("@ytt:data", "data")
---
kind: rendering
metadata:
name: app
outputYaml:
fromAppConfig: true
fromAppConfigAppData: #@ data.values.application.appValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
protoOverwriteValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@ load("@ytt:data", "data")
---
outputYaml:
fromPrototypeOverride: true
fromPrototypeOverrideFromAppData: #@ data.values.application.protoOverwriteValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
protoOverwriteValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#@ load("@ytt:data", "data")
---
kind: rendering
metadata:
name: proto
outputYaml:
fromPrototypeOverride: true
fromPrototypeOverrideFromAppData: #@ data.values.application.protoOverwriteValue
11 changes: 11 additions & 0 deletions examples/inheritance-test/envs/dev/env-data.ytt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#@data/values
---
environment:
id: mykso-dev
#! applications: # already defined one level above
#! - proto: httpbingo # already defined one level above
applications:
- proto: helm-render-test
name: helm-installation
- proto: ytt-render-test
name: ytt-installation
28 changes: 28 additions & 0 deletions examples/inheritance-test/envs/env-data.ytt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! This is an example of a data values file for the root environment.
#! All nested environments inherit these values. The values can be overridden in nested environments.
#! This file is a good place to define default values for all environments.
#!
#! To change the schema of the data values, use `data/values-schema` annotation instead of `data/values`.
#! Refer to the documentation of ytt overlays and data values for more information.

#@data/values
---
argocd:
namespace: system-argocd
app:
prefix: app-
#! Disable finalizers to preserve resources after deleting the ArgoCD application.
finalizers: []
source:
plugin:
name: argocd-vault-plugin-v1.0.0
#! Fixed config to run tests successfull in pipeline
targetRevision: main
repoURL: [email protected]:mykso/myks.git
project:
prefix: env-

#! Fixed git config to run tests successfull in pipeline.
myks:
gitRepoBranch: "main"
gitRepoUrl: "[email protected]:mykso/myks.git"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
baseValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@ load("@ytt:data", "data")
---
outputYaml:
fromPrototype: true
fromPrototypeAppData: #@ data.values.application.baseValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#@ load("@ytt:data", "data")

#@ app = data.values.application
---
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
- path: #@ "charts/" + app.name
contents:
- path: .
directory:
name: #@ app.name
path: ../../../../../../charts/render-test-chart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#@data/values-schema
---
#@overlay/match-child-defaults missing_ok=True
application:
#! WARNING: The order of the keys (alphabetical) is important for renovate.
#! When changed, renovate won't be able to detect the new version.
#! See renovate.json for more details.
#! renovate: datasource=helm
name: render-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@data/values-schema
#@overlay/match-child-defaults missing_ok=True
---
application:
baseValue: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#@ load("@ytt:data", "data")
---
kind: rendering
metadata:
name: base
outputYaml:
fromPrototype: true
fromPrototypeAppData: #@ data.values.application.baseValue
9 changes: 9 additions & 0 deletions examples/inheritance-test/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-mykso-dev-helm-installation
namespace: system-argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: env-mykso-dev
destination:
name: mykso-dev
namespace: helm-installation
source:
path: examples/inheritance-test/rendered/envs/mykso-dev/helm-installation
plugin:
name: argocd-vault-plugin-v1.0.0
repoURL: [email protected]:mykso/myks.git
targetRevision: main
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ServerSideApply=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-mykso-dev-ytt-installation
namespace: system-argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: env-mykso-dev
destination:
name: mykso-dev
namespace: ytt-installation
source:
path: examples/inheritance-test/rendered/envs/mykso-dev/ytt-installation
plugin:
name: argocd-vault-plugin-v1.0.0
repoURL: [email protected]:mykso/myks.git
targetRevision: main
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
- ServerSideApply=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: env-mykso-dev
namespace: system-argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
description: Project for "mykso-dev" environment
clusterResourceWhitelist:
- group: '*'
kind: '*'
destinations:
- namespace: '*'
name: mykso-dev
namespaceResourceWhitelist:
- group: '*'
kind: '*'
sourceRepos:
- '*'
---
apiVersion: v1
kind: Secret
metadata:
labels:
argocd.argoproj.io/secret-type: cluster
name: mykso-dev
namespace: system-argocd
stringData:
config: ARGOCD_CLUSTER_CONNECT_CONFIG
name: mykso-dev
project: env-mykso-dev
server: ARGOCD_CLUSTER_SERVER_URL
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: rendering
metadata:
name: render-test
outputYaml:
fromAppConfig: true
fromAppConfigAppData: true
fromChartDefaultValues: true
fromEnvGroup: true
fromEnvGroupAppData: true
fromPrototype: true
fromPrototypeAppData: true
fromPrototypeOverride: true
fromPrototypeOverrideFromAppData: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: rendering
metadata:
name: app
outputYaml:
fromAppConfig: true
fromAppConfigAppData: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: rendering
metadata:
name: base
outputYaml:
fromPrototype: true
fromPrototypeAppData: true
Loading

0 comments on commit c3e550d

Please sign in to comment.