generated from crossplane/function-template-go
-
Notifications
You must be signed in to change notification settings - Fork 39
/
composition.yaml
85 lines (83 loc) · 2.59 KB
/
composition.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: example-function-to-yaml
spec:
compositeTypeRef:
apiVersion: example.crossplane.io/v1beta1
kind: XR
mode: Pipeline
pipeline:
- step: render-templates
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
{{- define "labels" -}}
some-text: {{.val1}}
other-text: {{.val2}}
{{- end }}
## weird indentation to make it work
{{- define "labels-metadata" -}}
some-text: {{.val1}}
other-text: {{.val2}}
{{- end }}
{{- define "labels-matchLabels" -}}
some-text: {{.val1}}
other-text: {{.val2}}
{{- end }}
---
#include example
{{$vals:= .observed.composite.resource.spec}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: test1
labels:
{{- include "labels" $vals | nindent 4}}
spec:
replicas: 3
selector:
matchLabels:
{{- include "labels" $vals | nindent 6}}
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
# without include, you must define a template per indentation setting
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: test2
labels:
{{ template "labels-metadata" $vals}}
spec:
replicas: 3
selector:
matchLabels:
{{ template "labels-matchLabels" $vals }}
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80