nicc777 / py-animus

A python based plugable and extensible manifest processing system
GNU General Public License v3.0
0 stars 0 forks source link

Add support for environments #61

Closed nicc777 closed 1 year ago

nicc777 commented 1 year ago

Brief Description of the Enhancement

Add support for a values file that contain the environment specific values for spec fields in manifests.

Describe the benefit of this proposed enhancement

Re-use the exact same manifest suite in different environments and externalize environment specific values.

Code examples, pseudo code or any other technical description of the proposal

Enhance the metadata field to include environments:

metadata:
  environments: # Optional. If non supplied, allocate to default environment called "default"
  - string

Add support for a values file. Example file layout:

values:
- name: string # Required: a unique name that can be used as reference in "{{ .Values.<<name>> }}" field values
  environments:
  - environmentName: string # Required - a name that will be matched against the metadata environment name for this value
    source: string # Optional, default None/null (use the literal value supplied), or alternatively if supplied a string value, use the string as a variable name
    value: string # Optional, required if "source" is null. 

Add the command line parameter -e or --environment to specify the environment. If none is supplied, set the default value to default.

Hello World Adapted Example

Manifest:

---
kind: HelloWorld
version: v1
metadata:
  name: hello-world
  environments: 
  - env1
  - env2
  - env3
spec:
  file: /tmp/hello-world-result/output.txt
  content: {{ .Values.greeting }}

Values file: (must be called values.yaml):

values:
- name: greeting 
  environments:
  - environmentName: env1 
    value: This is environment 1
  - environmentName: env2
    value: This is environment 2
  - environmentName: env3
    value: This is environment 3
  - environmentName: default
    value: This is the default environment

Running the example:

docker run --rm -e "DEBUG=1" \
  -v $PWD/examples/hello-world/src:/tmp/src \
  -v $PWD/examples/hello-world/manifest:/tmp/data \
  -v /tmp/results:/tmp/hello-world-result \
  ghcr.io/nicc777/py-animus:latest apply -m /tmp/data/hello-v1.yaml -s /tmp/src -e env2