Skip to content

Commit

Permalink
docs: Document setVar in README
Browse files Browse the repository at this point in the history
  • Loading branch information
achetronic committed Nov 13, 2024
1 parent cdabedd commit 69a8bac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,43 @@ spec:
```

As you probably noticed in the previous example, conditions are made using vitamin Golang template
(better known as Helm template), so **all the functions available in Helm are available here too.**
This way you start creating wonderful policies from first minute.

**Sometimes you need to store information** during conditions' evaluation that will be useful in later messages shown to the team.
This will help your mates having meaningful messages that save time during debug.

Because of that, there is a special function available in templates called `setVar`. It can be used as follows:

```yaml
apiVersion: admitik.freepik.com/v1alpha1
kind: ClusterAdmissionPolicy
spec:
...
conditions:
- name: store-vars-for-later-usage
key: |
{{- $someDataForLater := dict "name" "example-name" "namespace" "example-namespace" -}}
{{/* Store your data under your desired key. You can use as many keys as needed */}}
{{- setVar "some_key" $someDataForLater -}}
{{- printf "force-condition-not-being-met" -}}
value: "condition-key-result"
message:
template: |
{{- $myVars := .vars -}}
{{- $someKeyInside := $myVars.some_key-}}
{{- printf "let's show some stored data: %s/%s" $someKeyInside.name $someKeyInside.namespace -}}
```


## How to develop
Expand Down
6 changes: 3 additions & 3 deletions charts/admitik/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ apiVersion: v2
name: admitik
type: application
description: >-
A Helm chart for admitik, an admission controller for Kubernetes
A Helm chart for Admitik, an admission controller for Kubernetes
that allow resources entrance if conditions are met (realtime)
version: 0.1.0 # chart version
appVersion: "0.1.0" # admitik version
version: 0.2.0 # chart version
appVersion: "0.2.0" # admitik version
kubeVersion: ">=1.22.0-0" # kubernetes version
home: https://github.com/freepik-company/admitik
sources:
Expand Down

0 comments on commit 69a8bac

Please sign in to comment.