diff --git a/.github/workflows/pr-status-checks-workflow-call.yml b/.github/workflows/pr-status-checks-workflow-call.yml index 0be8ee4..cf8a110 100644 --- a/.github/workflows/pr-status-checks-workflow-call.yml +++ b/.github/workflows/pr-status-checks-workflow-call.yml @@ -1,9 +1,11 @@ name: PR Status Checks on: + workflow_dispatch: {} pull_request_target: branches: - main + - feat/kustomize concurrency: group: ${{ github.event.pull_request.head.repo.full_name }}-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -19,4 +21,4 @@ permissions: jobs: pr-status-check: - uses: "openmcp-project/blueprint-workflows/.github/workflows/git-pr-status-checks.yml@main" + uses: "openmcp-project/blueprint-workflows/.github/workflows/git-pr-status-checks.yml@feat/kustomize" diff --git a/helm/charts/flux-config/Chart.yaml b/helm/charts/flux-config/Chart.yaml index e8bb554..236113a 100644 --- a/helm/charts/flux-config/Chart.yaml +++ b/helm/charts/flux-config/Chart.yaml @@ -17,7 +17,7 @@ icon: "https://avatars.githubusercontent.com/u/52158677?s=200&v=4" # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.0.20 +version: 0.0.22 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. diff --git a/helm/charts/flux-config/README.md b/helm/charts/flux-config/README.md index b0842b3..45c9170 100644 --- a/helm/charts/flux-config/README.md +++ b/helm/charts/flux-config/README.md @@ -2,7 +2,7 @@ # flux-config -![Version: 0.0.20](https://img.shields.io/badge/Version-0.0.20-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.6.0](https://img.shields.io/badge/AppVersion-2.6.0-informational?style=flat-square) +![Version: 0.0.22](https://img.shields.io/badge/Version-0.0.22-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.6.0](https://img.shields.io/badge/AppVersion-2.6.0-informational?style=flat-square) A Helm Chart to template flux manifests to leverage GitOps on a OpenMCP cluster. diff --git a/kustomize/projects/helloWorld/.version b/kustomize/projects/helloWorld/.version new file mode 100644 index 0000000..e2cac26 --- /dev/null +++ b/kustomize/projects/helloWorld/.version @@ -0,0 +1 @@ +1.2.3 \ No newline at end of file diff --git a/kustomize/projects/helloWorld/README.md b/kustomize/projects/helloWorld/README.md new file mode 100644 index 0000000..ac0611e --- /dev/null +++ b/kustomize/projects/helloWorld/README.md @@ -0,0 +1,311 @@ +[base]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#base +[config]: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld +[gitops]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#gitops +[hello]: https://github.com/monopole/hello +[kustomization]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#kustomization +[original]: https://github.com/kubernetes-sigs/kustomize/tree/master/examples/helloWorld +[overlay]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#overlay +[overlays]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#overlay +[patch]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#patch +[variant]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#variant +[variants]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#variant + +# Demo: hello world with variants + +Steps: + + 1. Clone an existing configuration as a [base]. + 1. Customize it. + 1. Create two different [overlays] (_staging_ and _production_) + from the customized base. + 1. Run kustomize and kubectl to deploy staging and production. + +First define a place to work: + + +``` +DEMO_HOME=$(mktemp -d) +``` + +Alternatively, use + +> ``` +> DEMO_HOME=~/hello +> ``` + +## Establish the base + +Let's run the [hello] service. + +To use [overlays] to create [variants], we must +first establish a common [base]. + +To keep this document shorter, the base resources are +off in a supplemental data directory rather than +declared here as HERE documents. Download them: + + +``` +BASE=$DEMO_HOME/base +mkdir -p $BASE + +curl -s -o "$BASE/#1.yaml" "https://raw.githubusercontent.com\ +/kubernetes-sigs/kustomize\ +/master/examples/helloWorld\ +/{configMap,deployment,kustomization,service}.yaml" +``` + +Look at the directory: + + +``` +tree $DEMO_HOME +``` + +Expect something like: + +> ``` +> /tmp/tmp.IyYQQlHaJP +> └── base +> ├── configMap.yaml +> ├── deployment.yaml +> ├── kustomization.yaml +> └── service.yaml +> ``` + + +One could immediately apply these resources to a +cluster: + +> ``` +> kubectl apply -k $DEMO_HOME/base +> ``` + +to instantiate the _hello_ service. `kubectl` +would only recognize the resource files. + +### The Base Kustomization + +The `base` directory has a [kustomization] file: + + +``` +more $BASE/kustomization.yaml +``` + +Optionally, run `kustomize` on the base to emit +customized resources to `stdout`: + + +``` +kustomize build $BASE +``` + +### Customize the base + +A first customization step could be to change the _app +label_ applied to all resources: + + +``` +sed -i.bak 's/app: hello/app: my-hello/' \ + $BASE/kustomization.yaml +``` + +See the effect: + +``` +kustomize build $BASE | grep -C 3 app: +``` + +## Create Overlays + +Create a _staging_ and _production_ [overlay]: + + * _Staging_ enables a risky feature not enabled in production. + * _Production_ has a higher replica count. + * Web server greetings from these cluster + [variants] will differ from each other. + + +``` +OVERLAYS=$DEMO_HOME/overlays +mkdir -p $OVERLAYS/staging +mkdir -p $OVERLAYS/production +``` + +#### Staging Kustomization + +In the `staging` directory, make a kustomization +defining a new name prefix, and some different labels. + + +``` +cat <<'EOF' >$OVERLAYS/staging/kustomization.yaml +namePrefix: staging- +commonLabels: + variant: staging + org: acmeCorporation +commonAnnotations: + note: Hello, I am staging! +resources: +- ../../base +patches: +- path: map.yaml +EOF +``` + +#### Staging Patch + +Add a configMap customization to change the server +greeting from _Good Morning!_ to _Have a pineapple!_ + +Also, enable the _risky_ flag. + + +``` +cat <$OVERLAYS/staging/map.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: the-map +data: + altGreeting: "Have a pineapple!" + enableRisky: "true" +EOF +``` + +#### Production Kustomization + +In the production directory, make a kustomization +with a different name prefix and labels. + + +``` +cat <$OVERLAYS/production/kustomization.yaml +namePrefix: production- +commonLabels: + variant: production + org: acmeCorporation +commonAnnotations: + note: Hello, I am production! +resources: +- ../../base +patches: +- path: deployment.yaml +EOF +``` + + +#### Production Patch + +Make a production patch that increases the replica +count (because production takes more traffic). + + +``` +cat <$OVERLAYS/production/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: the-deployment +spec: + replicas: 10 +EOF +``` + +## Compare overlays + + +`DEMO_HOME` now contains: + + - a _base_ directory - a slightly customized clone + of the original configuration, and + + - an _overlays_ directory, containing the kustomizations + and patches required to create distinct _staging_ + and _production_ [variants] in a cluster. + +Review the directory structure and differences: + + +``` +tree $DEMO_HOME +``` + +Expecting something like: + +> ``` +> /tmp/tmp.IyYQQlHaJP1 +> ├── base +> │   ├── configMap.yaml +> │   ├── deployment.yaml +> │   ├── kustomization.yaml +> │   └── service.yaml +> └── overlays +> ├── production +> │   ├── deployment.yaml +> │   └── kustomization.yaml +> └── staging +> ├── kustomization.yaml +> └── map.yaml +> ``` + +Compare the output directly +to see how _staging_ and _production_ differ: + + +``` +diff \ + <(kustomize build $OVERLAYS/staging) \ + <(kustomize build $OVERLAYS/production) |\ + more +``` + +The first part of the difference output should look +something like + +> ```diff +> < altGreeting: Have a pineapple! +> < enableRisky: "true" +> --- +> > altGreeting: Good Morning! +> > enableRisky: "false" +> 8c8 +> < note: Hello, I am staging! +> --- +> > note: Hello, I am production! +> 11c11 +> < variant: staging +> --- +> > variant: production +> 13c13 +> (...truncated) +> ``` + + +## Deploy + +The individual resource sets are: + + +``` +kustomize build $OVERLAYS/staging +``` + + +``` +kustomize build $OVERLAYS/production +``` + +To deploy, pipe the above commands to kubectl apply: + +> ``` +> kustomize build $OVERLAYS/staging |\ +> kubectl apply -f - +> ``` + +> ``` +> kustomize build $OVERLAYS/production |\ +> kubectl apply -f - +> ``` diff --git a/kustomize/projects/helloWorld/configMap.yaml b/kustomize/projects/helloWorld/configMap.yaml new file mode 100644 index 0000000..e335ab8 --- /dev/null +++ b/kustomize/projects/helloWorld/configMap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: the-map +data: + altGreeting: "Good Morning!" + enableRisky: "false" diff --git a/kustomize/projects/helloWorld/deployment.yaml b/kustomize/projects/helloWorld/deployment.yaml new file mode 100644 index 0000000..00e5eb9 --- /dev/null +++ b/kustomize/projects/helloWorld/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: the-deployment +spec: + replicas: 3 + selector: + matchLabels: + deployment: hello + template: + metadata: + labels: + deployment: hello + spec: + containers: + - name: the-container + image: monopole/hello:1 + command: ["/hello", + "--port=8080", + "--enableRiskyFeature=$(ENABLE_RISKY)"] + ports: + - containerPort: 8080 + env: + - name: ALT_GREETING + valueFrom: + configMapKeyRef: + name: the-map + key: altGreeting + - name: ENABLE_RISKY + valueFrom: + configMapKeyRef: + name: the-map + key: enableRisky diff --git a/kustomize/projects/helloWorld/kustomization.yaml b/kustomize/projects/helloWorld/kustomization.yaml new file mode 100644 index 0000000..297fe43 --- /dev/null +++ b/kustomize/projects/helloWorld/kustomization.yaml @@ -0,0 +1,14 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +metadata: + name: arbitrary + +# Example configuration for the webserver +# at https://github.com/monopole/hello +commonLabels: + app: hello1 + +resources: +- deployment.yaml +- service.yaml +- configMap.yaml diff --git a/kustomize/projects/helloWorld/service.yaml b/kustomize/projects/helloWorld/service.yaml new file mode 100644 index 0000000..e238f70 --- /dev/null +++ b/kustomize/projects/helloWorld/service.yaml @@ -0,0 +1,12 @@ +kind: Service +apiVersion: v1 +metadata: + name: the-service +spec: + selector: + deployment: hello + type: LoadBalancer + ports: + - protocol: TCP + port: 8666 + targetPort: 8080