Skip to content

Commit dc92f9a

Browse files
committed
Add git generation
1 parent 6ae99c6 commit dc92f9a

File tree

9 files changed

+139
-28
lines changed

9 files changed

+139
-28
lines changed
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
apiVersion: argoproj.io/v1alpha1
22
kind: ApplicationSet
33
metadata:
4-
name: web-nodejs
4+
name: web
55
namespace: $USER-argocd
6-
finalizers:
7-
- resources-finalizer.argocd.argoproj.io/background
86
spec:
97
goTemplate: true
108
goTemplateOptions: ["missingkey=error"]
@@ -13,12 +11,12 @@ spec:
1311
repoURL: https://github.com/OpenShiftDemos/advanced-gitops-workshop
1412
revision: HEAD
1513
directories:
16-
- path: content/modules/ROOT/examples/coolstore/overlays/*
14+
- path: content/modules/ROOT/examples/coolstore-web/overlays/*
1715
values:
1816
user: $USER
1917
template:
2018
metadata:
21-
name: coolstore-{{.path.basename}}
19+
name: app-{{.path.basename}}
2220
namespace: '{{ .values.user }}-argocd'
2321
spec:
2422
destination:
@@ -29,5 +27,15 @@ spec:
2927
path: '{{.path.path}}'
3028
repoURL: https://github.com/OpenShiftDemos/advanced-gitops-workshop
3129
targetRevision: main
30+
kustomize:
31+
patches:
32+
- target:
33+
kind: Deployment
34+
name: web
35+
patch: |-
36+
- op: replace
37+
path: /spec/template/spec/containers/0/env/0/value
38+
value: 'gateway-vertx-{{ .values.user }}-{{.path.basename}}'
3239
syncPolicy:
33-
automated:
40+
automated:
41+
prune: true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- dep-coolstore.yaml
5+
- web-nodejs-route.yaml
6+
- web-nodejs-svc.yaml
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
kind: Deployment
2+
apiVersion: apps/v1
3+
metadata:
4+
name: web
5+
labels:
6+
app: web
7+
app.kubernetes.io/component: web
8+
app.kubernetes.io/instance: web
9+
app.kubernetes.io/name: web
10+
app.kubernetes.io/part-of: coolstore
11+
spec:
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
app: web
16+
template:
17+
metadata:
18+
labels:
19+
app: web
20+
deployment: web
21+
spec:
22+
containers:
23+
- name: web
24+
image: quay.io/coolstore-demo/web-nodejs:latest
25+
ports:
26+
- containerPort: 8080
27+
protocol: TCP
28+
env:
29+
- name: SECURE_COOLSTORE_GW_ENDPOINT
30+
value: 'https://gateway-vertx-coolstore-dev-user1.apps.cluster-424xp.424xp.sandbox1774.opentlc.com'
31+
resources: {}
32+
terminationMessagePath: /dev/termination-log
33+
terminationMessagePolicy: File
34+
imagePullPolicy: Always
35+
restartPolicy: Always
36+
terminationGracePeriodSeconds: 30
37+
dnsPolicy: ClusterFirst
38+
securityContext: {}
39+
schedulerName: default-scheduler
40+
strategy:
41+
type: RollingUpdate
42+
rollingUpdate:
43+
maxUnavailable: 25%
44+
maxSurge: 25%
45+
revisionHistoryLimit: 10
46+
progressDeadlineSeconds: 600
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: route.openshift.io/v1
2+
kind: Route
3+
metadata:
4+
annotations:
5+
openshift.io/host.generated: "true"
6+
labels:
7+
app: web
8+
app.kubernetes.io/component: web
9+
app.kubernetes.io/instance: web
10+
app.kubernetes.io/name: web
11+
app.kubernetes.io/part-of: coolstore
12+
name: web
13+
spec:
14+
port:
15+
targetPort: 8080
16+
to:
17+
kind: Service
18+
name: web
19+
weight: 100
20+
tls:
21+
termination: edge
22+
insecureEdgeTerminationPolicy: Redirect
23+
wildcardPolicy: None
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: web
6+
app.kubernetes.io/component: web
7+
app.kubernetes.io/instance: web
8+
app.kubernetes.io/name: web
9+
app.kubernetes.io/part-of: coolstore
10+
name: web
11+
spec:
12+
ports:
13+
- port: 8080
14+
protocol: TCP
15+
targetPort: 8080
16+
selector:
17+
app: web
18+
sessionAffinity: None
19+
type: ClusterIP
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../../base
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../../base
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../../base

content/modules/ROOT/pages/04-applicationsets.adoc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,6 @@ oc get app coolstore-dev -o=jsonpath='{.metadata.ownerReferences}' -n {user}-arg
226226
As we can see ApplicationSets provide an easy way to generate Application objects statically but now let's have a look
227227
where they really shine, dynamic generation based on external sources.
228228

229-
Delete the ApplicationSet before continuting to the next section:
230-
231-
[.console-input]
232-
[source,sh,subs="attributes",role=execute]
233-
----
234-
oc delete appset coolstore -n {user}-argocd
235-
----
236-
237-
[NOTE]
238-
It may take a minute or two for it to delete as it deletes the entire chain of applications and resources, be patient.
239-
240229
== Dynamic Generation with git Generator
241230

242231
A common pattern when deploying an application with kustomize with multiple environments is to have a repository that contains the following structure:
@@ -252,7 +241,7 @@ You can view this structure in your cloned repository:
252241
[.console-input]
253242
[source,sh,subs="attributes",role=execute]
254243
----
255-
find ~/workshop/content/modules/ROOT/examples/coolstore -print | sort|sed -e 's;[^/]*/;|--;g;s;--|; |;g'
244+
find ~/workshop/content/modules/ROOT/examples/coolstore-web -print | sort|sed -e 's;[^/]*/;|--;g;s;--|; |;g'
256245
----
257246

258247
[.console-output]
@@ -293,34 +282,41 @@ oc get appset web-nodejs -o yaml -n {user}-argocd | oc neat
293282
apiVersion: argoproj.io/v1alpha1
294283
kind: ApplicationSet
295284
metadata:
296-
name: coolstore
297-
namespace: {user}-argocd
285+
name: coolstore-web
286+
namespace: $USER-argocd
298287
spec:
288+
goTemplate: true
289+
goTemplateOptions: ["missingkey=error"]
299290
generators:
300291
- git: <1>
301292
directories:
302293
- path: content/modules/ROOT/examples/coolstore/overlays/* <2>
303294
repoURL: https://github.com/OpenShiftDemos/advanced-gitops-workshop <3>
304295
revision: HEAD
305296
values:
306-
user: {user} <4>
307-
goTemplate: true
308-
goTemplateOptions:
309-
- missingkey=error
297+
user: $USER <4>
310298
template:
311299
metadata:
312-
name: app-{{.path.basename}} <5>
300+
name: coolstore-web-{{.path.basename}} <5>
313301
namespace: '{{ .values.user }}-argocd'
314302
spec:
315303
destination:
316304
name: in-cluster
317305
namespace: '{{ .values.user }}-{{.path.basename}}'
318306
project: '{{ .values.user }}'
319307
source:
320-
kustomize:
321308
path: '{{.path.path}}' <6>
322-
repoURL: https://gitea-gitea.{subdomain}/{user}/gitops.git
309+
repoURL: https://github.com/OpenShiftDemos/advanced-gitops-workshop
323310
targetRevision: main
311+
kustomize:
312+
patches:
313+
- target:
314+
kind: Deployment
315+
name: web
316+
patch: |-
317+
- op: replace
318+
path: /spec/template/spec/containers/0/env/0/value
319+
value: 'gateway-vertx-{{ .values.user }}-{{.path.basename}}' <7>
324320
syncPolicy:
325321
automated:
326322
prune: true
@@ -330,7 +326,8 @@ spec:
330326
<3> The target repository
331327
<4> Additional values to pass to the template
332328
<5> The basename of the path for which the Application is being generated, either `dev` or `prod` in this case
333-
<6> the full path in the repo for the current directory
329+
<6> The full path in the repo for the current directory
330+
<7> Example of using the passed in value for `{user}`
334331

335332
Check that the Applications have been created:
336333

0 commit comments

Comments
 (0)