Skip to content

Commit

Permalink
docs(appset): ApplicationSets generators docs to use go templates (ar…
Browse files Browse the repository at this point in the history
…goproj#16109) (argoproj#16127)

* docs: migrating fasttemplate to go-template; Git Generator

Signed-off-by: Kunal Singh <kunalsin9h@gmail.com>

* docs: missing yaml language specifier stopping syntax highlighting

Signed-off-by: Kunal Singh <kunalsin9h@gmail.com>

* docs: migrate List Generators page to go-templates

Signed-off-by: Kunal Singh <kunalsin9h@gmail.com>

* docs: migrate Matrix, Merge & SCM Provider Generators page to go-templates

Signed-off-by: Kunal Singh <kunalsin9h@gmail.com>

* docs: migrating fasttemplate to go-template

Signed-off-by: Kunal Singh <kunalsin9h@gmail.com>

---------

Signed-off-by: Kunal Singh <kunalsin9h@gmail.com>
Signed-off-by: jmilic1 <70441727+jmilic1@users.noreply.github.com>
  • Loading branch information
KunalSin9h authored and jmilic1 committed Nov 13, 2023
1 parent a6f9369 commit bd3ff89
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 97 deletions.
18 changes: 11 additions & 7 deletions docs/operator-manual/applicationset/Appset-Any-Namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ kind: ApplicationSet
metadata:
name: myapps
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- scmProvider:
gitea:
Expand Down Expand Up @@ -137,17 +139,19 @@ metadata:
name: team-one-product-one
namespace: team-one-cd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
list:
- id: infra
- name: infra
project: infra-project
- id: team-two
- name: team-two
project: team-two-project
template:
metadata:
name: '{{name}}-escalation'
spec:
project: "{{project}}"
template:
metadata:
name: '{{.name}}-escalation'
spec:
project: "{{.project}}"
```

### ApplicationSet names
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ metadata:
name: guestbook
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusterDecisionResource:
# ConfigMap with GVK information for the duck type resource
Expand All @@ -26,15 +28,15 @@ spec:
requeueAfterSeconds: 60
template:
metadata:
name: '{{name}}-guestbook'
name: '{{.name}}-guestbook'
spec:
project: "default"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
targetRevision: HEAD
path: guestbook
destination:
server: '{{clusterName}}' # 'server' field of the secret
server: '{{.clusterName}}' # 'server' field of the secret
namespace: guestbook
```
The `quak` resource, referenced by the ApplicationSet `clusterDecisionResource` generator:
Expand Down
32 changes: 21 additions & 11 deletions docs/operator-manual/applicationset/Generators-Cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ metadata:
name: guestbook
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters: {} # Automatically use all clusters defined within Argo CD
template:
metadata:
name: '{{name}}-guestbook' # 'name' field of the Secret
name: '{{.name}}-guestbook' # 'name' field of the Secret
spec:
project: "my-project"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
targetRevision: HEAD
path: guestbook
destination:
server: '{{server}}' # 'server' field of the secret
server: '{{.server}}' # 'server' field of the secret
namespace: guestbook
```
(*The full example can be found [here](https://github.com/argoproj/argo-cd/tree/master/applicationset/examples/cluster).*)
Expand All @@ -67,6 +69,8 @@ metadata:
name: guestbook
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters:
selector:
Expand Down Expand Up @@ -105,6 +109,8 @@ The cluster generator will automatically target both local and non-local cluster
If you wish to target only remote clusters with your Applications (e.g. you want to exclude the local cluster), then use a cluster selector with labels, for example:
```yaml
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters:
selector:
Expand Down Expand Up @@ -137,6 +143,8 @@ You may pass additional, arbitrary string key-value pairs via the `values` field
In this example, a `revision` parameter value is passed, based on matching labels on the cluster secret:
```yaml
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters:
selector:
Expand All @@ -154,16 +162,16 @@ spec:
revision: stable
template:
metadata:
name: '{{name}}-guestbook'
name: '{{.name}}-guestbook'
spec:
project: "my-project"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
# The cluster values field for each generator will be substituted here:
targetRevision: '{{values.revision}}'
targetRevision: '{{.values.revision}}'
path: guestbook
destination:
server: '{{server}}'
server: '{{.server}}'
namespace: guestbook
```

Expand All @@ -184,6 +192,8 @@ Extending the example above, we could do something like this:

```yaml
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters:
selector:
Expand All @@ -192,28 +202,28 @@ spec:
# A key-value map for arbitrary parameters
values:
# If `my-custom-annotation` is in your cluster secret, `revision` will be substituted with it.
revision: '{{metadata.annotations.my-custom-annotation}}'
clusterName: '{{name}}'
revision: '{{index .metadata.annotations "my-custom-annotation"}}'
clusterName: '{{.name}}'
- clusters:
selector:
matchLabels:
type: 'production'
values:
# production uses a different revision value, for 'stable' branch
revision: stable
clusterName: '{{name}}'
clusterName: '{{.name}}'
template:
metadata:
name: '{{name}}-guestbook'
name: '{{.name}}-guestbook'
spec:
project: "my-project"
source:
repoURL: https://github.com/argoproj/argocd-example-apps/
# The cluster values field for each generator will be substituted here:
targetRevision: '{{values.revision}}'
targetRevision: '{{.values.revision}}'
path: guestbook
destination:
# In this case this is equivalent to just using {{name}}
server: '{{values.clusterName}}'
server: '{{.values.clusterName}}'
namespace: guestbook
```
36 changes: 20 additions & 16 deletions docs/operator-manual/applicationset/Generators-Git.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,26 +210,28 @@ metadata:
name: cluster-addons
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- git:
repoURL: https://github.com/example/example-repo.git
revision: HEAD
directories:
- path: '*'
values:
cluster: '{{branch}}-{{path}}'
cluster: '{{.branch}}-{{.path.basename}}'
template:
metadata:
name: '{{path.basename}}'
name: '{{.path.basename}}'
spec:
project: "my-project"
source:
repoURL: https://github.com/example/example-repo.git
targetRevision: HEAD
path: '{{path}}'
path: '{{.path.path}}'
destination:
server: https://kubernetes.default.svc
namespace: '{{values.cluster}}'
namespace: '{{.values.cluster}}'
```

!!! note
Expand Down Expand Up @@ -323,15 +325,15 @@ As with other generators, clusters *must* already be defined within Argo CD, in

In addition to the flattened key/value pairs from the configuration file, the following generator parameters are provided:

- `{{path}}`: The path to the directory containing matching configuration file within the Git repository. Example: `/clusters/clusterA`, if the config file was `/clusters/clusterA/config.json`
- `{{path[n]}}`: The path to the matching configuration file within the Git repository, split into array elements (`n` - array index). Example: `path[0]: clusters`, `path[1]: clusterA`
- `{{path.basename}}`: Basename of the path to the directory containing the configuration file (e.g. `clusterA`, with the above example.)
- `{{path.basenameNormalized}}`: This field is the same as `path.basename` with unsupported characters replaced with `-` (e.g. a `path` of `/directory/directory_2`, and `path.basename` of `directory_2` would produce `directory-2` here).
- `{{path.filename}}`: The matched filename. e.g., `config.json` in the above example.
- `{{path.filenameNormalized}}`: The matched filename with unsupported characters replaced with `-`.
- `{{.path.path}}`: The path to the directory containing matching configuration file within the Git repository. Example: `/clusters/clusterA`, if the config file was `/clusters/clusterA/config.json`
- `{{index .path n}}`: The path to the matching configuration file within the Git repository, split into array elements (`n` - array index). Example: `index .path 0: clusters`, `index .path 1: clusterA`
- `{{.path.basename}}`: Basename of the path to the directory containing the configuration file (e.g. `clusterA`, with the above example.)
- `{{.path.basenameNormalized}}`: This field is the same as `.path.basename` with unsupported characters replaced with `-` (e.g. a `path` of `/directory/directory_2`, and `.path.basename` of `directory_2` would produce `directory-2` here).
- `{{.path.filename}}`: The matched filename. e.g., `config.json` in the above example.
- `{{.path.filenameNormalized}}`: The matched filename with unsupported characters replaced with `-`.

**Note**: The right-most *directory* name always becomes `{{path.basename}}`. For example, from `- path: /one/two/three/four/config.json`, `{{path.basename}}` will be `four`.
The filename can always be accessed using `{{path.filename}}`.
**Note**: The right-most *directory* name always becomes `{{.path.basename}}`. For example, from `- path: /one/two/three/four/config.json`, `{{.path.basename}}` will be `four`.
The filename can always be accessed using `{{.path.filename}}`.

**Note**: If the `pathParamPrefix` option is specified, all `path`-related parameter names above will be prefixed with the specified value and a dot separator. E.g., if `pathParamPrefix` is `myRepo`, then the generated parameter name would be `myRepo.path` instead of `path`. Using this option is necessary in a Matrix generator where both child generators are Git generators (to avoid conflicts when merging the child generators’ items).

Expand All @@ -349,25 +351,27 @@ metadata:
name: guestbook
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- git:
repoURL: https://github.com/argoproj/argo-cd.git
revision: HEAD
files:
- path: "applicationset/examples/git-generator-files-discovery/cluster-config/**/config.json"
values:
base_dir: "{{path[0]}}/{{path[1]}}/{{path[2]}}"
base_dir: "{{index .path 0}}/{{index .path 1}}/{{index .path 2}}"
template:
metadata:
name: '{{cluster.name}}-guestbook'
name: '{{.cluster.name}}-guestbook'
spec:
project: default
source:
repoURL: https://github.com/argoproj/argo-cd.git
targetRevision: HEAD
path: "{{values.base_dir}}/apps/guestbook"
path: "{{.values.base_dir}}/apps/guestbook"
destination:
server: '{{cluster.address}}'
server: '{{.cluster.address}}'
namespace: guestbook
```

Expand Down
13 changes: 7 additions & 6 deletions docs/operator-manual/applicationset/Generators-List.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ metadata:
name: guestbook
namespace: argocd
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- list:
elements:
- cluster: engineering-dev
url: https://kubernetes.default.svc
# - cluster: engineering-prod
# url: https://kubernetes.default.svc
# foo: bar
- cluster: engineering-prod
url: https://kubernetes.default.svc
template:
metadata:
name: '{{cluster}}-guestbook'
name: '{{.cluster}}-guestbook'
spec:
project: "my-project"
source:
repoURL: https://github.com/argoproj/argo-cd.git
targetRevision: HEAD
path: applicationset/examples/list-generator/guestbook/{{cluster}}
path: applicationset/examples/list-generator/guestbook/{{.cluster}}
destination:
server: '{{url}}'
server: '{{.url}}'
namespace: guestbook
```
(*The full example can be found [here](https://github.com/argoproj/argo-cd/tree/master/applicationset/examples/list-generator).*)
Expand Down
Loading

0 comments on commit bd3ff89

Please sign in to comment.