Skip to content

Commit

Permalink
docs: fix kustomize patches example
Browse files Browse the repository at this point in the history
Related to: argoproj#16352 Also, add an ApplicationSet example. 

Signed-off-by: Nicholas Morey <nicholas@morey.tech>
  • Loading branch information
morey-tech authored Nov 15, 2023
1 parent ae07eb6 commit bc0e2bb
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions docs/user-guide/kustomize.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ To use Kustomize with an overlay, point your path to the overlay.
If you're generating resources, you should read up how to ignore those generated resources using the [`IgnoreExtraneous` compare option](compare-options.md).

## Patches
Patches are a way to kustomize resources using inline configurations in Argo CD applications. This allows for kustomizing without kustomization file. `patches` follow the same logic as the corresponding Kustomization. Any patches that target existing Kustomization file will be merged.
Patches are a way to kustomize resources using inline configurations in Argo CD applications. `patches` follow the same logic as the corresponding Kustomization. Any patches that target existing Kustomization file will be merged.

The following Kustomization can be done similarly in an Argo CD application.
This Kustomizate example sources manifests from the `/kustomize-guestbook` folder of the `argoproj/argocd-example-apps` repository and patches the `Deployment` to use port `443` on the container.
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
metadata:
name: kustomize-inline-example
namespace: test1
resources:
- https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-deployment.yaml
- https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-svc.yaml
- https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/kustomize-guestbook/
patches:
- target:
kind: Deployment
Expand All @@ -42,7 +41,8 @@ patches:
path: /spec/template/spec/containers/0/ports/0/containerPort
value: 443
```
Application will clone the repository, use the specified path, then kustomize using inline patches configuration.
This `Application` does the equivalent using the inline `kustomize.patches` configuration.
```yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
Expand All @@ -57,7 +57,7 @@ spec:
server: https://kubernetes.default.svc
project: default
source:
path: guestbook
path: kustomize-guestbook
repoURL: https://github.com/argoproj/argocd-example-apps.git
targetRevision: master
kustomize:
Expand All @@ -71,6 +71,45 @@ spec:
value: 443
```

The inline kustomize patches work well with `ApplicationSets`, too. Instead of maintaining a patch or overlay for each cluster, patches can now be done in the `Application` template and utilize attributes from the generators. For example, with [`external-dns`](https://github.com/kubernetes-sigs/external-dns/) to set the [`txt-owner-id`](https://github.com/kubernetes-sigs/external-dns/blob/e1adc9079b12774cccac051966b2c6a3f18f7872/docs/registry/registry.md?plain=1#L6) to the cluster name.

```yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: external-dns
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- clusters: {}
template:
metadata:
name: 'external-dns'
spec:
project: default
source:
repoURL: https://github.com/kubernetes-sigs/external-dns/
targetRevision: v0.14.0
path: kustomize
kustomize:
patches:
- target:
kind: Deployment
name: external-dns
patch: |-
- op: add
path: /spec/template/spec/containers/0/args/3
value: --txt-owner-id={{.name}} # patch using attribute from generator
destination:
name: 'in-cluster'
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true
```

## Private Remote Bases

If you have remote bases that are either (a) HTTPS and need username/password (b) SSH and need SSH private key, then they'll inherit that from the app's repo.
Expand Down

0 comments on commit bc0e2bb

Please sign in to comment.