-
Notifications
You must be signed in to change notification settings - Fork 13
/
zz-default.provisioners.yaml
1080 lines (1068 loc) · 40.2 KB
/
zz-default.provisioners.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This example provisioner is a fake resource type used to demonstrate the template provisioner mechanism. The URI should
# be a unique indicator of the provisioner. The scheme indicates how it is executed.
- uri: template://example-provisioners/example-provisioner
# (Required) Which resource type to match
type: example-provisioner-resource
# (Optional) Which 'class' of the resource. Null will match any class, a non-empty value like 'default' will match
# only resources of that class.
class: null
# (Optional) The exact resource id to match. Null will match any resource, a non-empty value will only match
# the resource with exact same id.
id: null
# (Optional) The init template sets the initial context values on each provision request. This is a text template
# that must evaluate to a YAML/JSON key-value map.
init: |
key: value
# sprig functions are also supported
key2: {{ print "value" | upper }}
# other attributes are available such as Type, Class, Id, Uid, Guid.
my-uid: "{{ .Uid }}#{{ .Guid }}"
# (Optional) The state template gets evaluated next and sets the internal state of this resource based on the previous
# state and the init context. Like init, this evaluates to a YAML/JSON object. This is the template that allows
# state to be stored between each generate call.
state: |
stateKey: {{ .Init.key }} # will copy the value from init
stateKey2: {{ default 0 .State.stateKey2 | add 1 }} # will increment on each provision attempt
# (Optional) The shared state template is like state, but is a key-value structure shared between all resources.
# This can be used to coordinate shared resources and state between resources of the same or related types.
shared: |
section:
key: {{ .Shared.foo }}
# (Optional) The outputs template gets evaluated last and translates into the outputs available as placeholder
# references like ${resources.my-resource.key}.
outputs: |
plaintext: my-value
nested:
example: thing
# Instead of returning secret outputs as plaintext. They can be embedded as reference to Kubernetes Secrets. When
# these are detected, they can be used in environment variables or file contents securely.
secret-reference: {{ encodeSecretRef "my-secret" "my-key" }}
# (Optional) The manifests template gets evaluated as a list of Kubernetes object manifests to be added to the output.
manifests: |
- apiVersion: v1
kind: ConfigMap
metadata:
name: cfg-{{ .Guid }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
data:
key: {{ .Init.key }}
# The 'cmd' scheme has a "host" + path component that indicates the path to the binary to execute. If the host starts
# with "." it is interpreted as a relative path, if it starts with "~" it resolves to the home directory.
- uri: cmd://bash#example-provisioner
type: example-provisioner-resource
class: default
id: specific
# (Optional) additional args that the binary gets run with
# If any of the args are '<mode>' it will be replaced with "provision"
args: ["-c", "echo '{\"resource_outputs\":{\"key\":\"value\"},\"manifests\":[]}'"]
# The default provisioner for service resources, this expects a workload and port name and will return the hostname and
# port required to contact it. This will validate that the workload and port exist, but won't enforce a dependency
# relationship yet.
- uri: template://default-provisioners/service-port
type: service-port
outputs: |
{{ if not .Params.workload }}{{ fail "expected 'workload' param for the target workload name" }}{{ end }}
{{ if not .Params.port }}{{ fail "expected 'port' param for the name of the target workload service port" }}{{ end }}
{{ $w := (index .WorkloadServices .Params.workload) }}
{{ if not $w }}{{ fail "unknown workload" }}{{ end }}
{{ $p := (index $w.Ports .Params.port) }}
{{ if not $p }}{{ fail "unknown service port" }}{{ end }}
hostname: {{ $w.ServiceName | quote }}
port: {{ $p.TargetPort }}
# As an example we have a 'volume' type which returns an emptyDir volume.
# In production or for real applications you may want to replace this with a provisioner for a tmpfs, host path, or
# persistent volume and claims.
- uri: template://default-provisioners/volume
type: volume
outputs: |
source:
emptyDir: {}
# The default dns provisioner just outputs a random localhost domain because we don't know whether external-dns is
# available. You should replace this with your own dns name generation that matches your external-dns controller.
- uri: template://default-provisioners/dns
type: dns
init: |
randomHostname: dns{{ randAlphaNum 6 | lower }}.localhost
state: |
instanceHostname: {{ dig "instanceHostname" .Init.randomHostname .State | quote }}
outputs: |
host: {{ .State.instanceHostname }}
# Routes could be implemented as either traditional ingress resources or using the newer gateway API.
# In this default provisioner we use the gateway API with some sensible defaults. But you may wish to replace this.
- uri: template://default-provisioners/route
type: route
init: |
{{ if not (regexMatch "^/|(/([^/]+))+$" .Params.path) }}{{ fail "params.path start with a / but cannot end with /" }}{{ end }}
{{ if not (regexMatch "^[a-z0-9_.-]{1,253}$" .Params.host) }}{{ fail (cat "params.host must be a valid hostname but was" .Params.host) }}{{ end }}
{{ $ports := (index .WorkloadServices .SourceWorkload).Ports }}
{{ if not $ports }}{{ fail "no service ports exist" }}{{ end }}
{{ $port := index $ports (print .Params.port) }}
{{ if not $port.TargetPort }}{{ fail "params.port is not a named service port" }}{{ end }}
state: |
routeName: route-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
manifests: |
- apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ .State.routeName }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.routeName }}
app.kubernetes.io/instance: {{ .State.routeName }}
spec:
parentRefs:
- name: default
hostnames:
- {{ .Params.host | quote }}
rules:
- matches:
- path:
type: PathPrefix
value: {{ .Params.path | quote }}
backendRefs:
- name: {{ (index .WorkloadServices .SourceWorkload).ServiceName }}
port: {{ .Params.port }}
- uri: template://default-provisioners/postgres
type: postgres
init: |
randomDatabase: db-{{ randAlpha 8 }}
randomUsername: user-{{ randAlpha 8 }}
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: pg-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
database: {{ dig "database" .Init.randomDatabase .State | quote }}
username: {{ dig "username" .Init.randomUsername .State | quote }}
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
host: {{ .State.service }}
port: 5432
name: {{ .State.database }}
database: {{ .State.database }}
username: {{ .State.username }}
password: {{ encodeSecretRef .State.service "password" }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
data:
password: {{ .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
replicas: 1
serviceName: {{ .State.service }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
spec:
automountServiceAccountToken: false
containers:
- name: postgres-db
image: postgres:17-alpine
ports:
- name: postgres
containerPort: 5432
env:
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: POSTGRES_USER
value: {{ .State.username | quote }}
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .State.service }}
key: password
- name: POSTGRES_DB
value: {{ .State.database | quote }}
volumeMounts:
- name: pv-data
mountPath: /var/lib/postgresql/data
securityContext:
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
privileged: false
capabilities:
drop:
- ALL
readinessProbe:
exec:
command:
- pg_isready
- -U
- {{ .State.username | quote }}
- -d
- {{ .State.database | quote }}
periodSeconds: 3
securityContext:
runAsNonRoot: true
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
volumeClaimTemplates:
- metadata:
name: pv-data
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
ports:
- port: 5432
targetPort: 5432
- uri: template://default-provisioners/redis
type: redis
init: |
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: redis-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
username: default
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
host: {{ .State.service }}
port: 6379
username: {{ .State.username }}
password: {{ encodeSecretRef .State.service "password" }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
data:
password: {{ .State.password | b64enc }}
redis.conf: {{ printf "requirepass %s\nport 6379\nsave 60 1\nloglevel warning\n" .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
replicas: 1
serviceName: {{ .State.service }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
spec:
automountServiceAccountToken: false
containers:
- name: redis
image: redis:7-alpine
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
ports:
- name: redis
containerPort: 6379
volumeMounts:
- name: redis-data
mountPath: /data
- name: config
mountPath: /usr/local/etc/redis
readinessProbe:
exec:
command:
- redis-cli
- ping
periodSeconds: 3
securityContext:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
volumes:
- name: config
secret:
secretName: {{ .State.service }}
items:
- key: redis.conf
path: redis.conf
volumeClaimTemplates:
- metadata:
name: redis-data
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
ports:
- port: 6379
targetPort: 6379
- uri: template://default-provisioners/mysql
type: mysql
init: |
randomDatabase: db-{{ randAlpha 8 }}
randomUsername: user-{{ randAlpha 8 }}
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: mysql-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
database: {{ dig "database" .Init.randomDatabase .State | quote }}
username: {{ dig "username" .Init.randomUsername .State | quote }}
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
host: {{ .State.service }}
port: 3306
name: {{ .State.database }}
database: {{ .State.database }}
username: {{ .State.username }}
password: {{ encodeSecretRef .State.service "MYSQL_PASSWORD" }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
data:
MYSQL_PASSWORD: {{ .State.password | b64enc }}
MYSQL_ROOT_PASSWORD: {{ .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
replicas: 1
serviceName: {{ .State.service }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
spec:
containers:
- name: mysql-db
image: mysql:8
ports:
- name: mysql
containerPort: 3306
env:
- name: MYSQL_USER
value: {{ .State.username | quote }}
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .State.service }}
key: MYSQL_PASSWORD
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .State.service }}
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_DATABASE
value: {{ .State.database | quote }}
volumeMounts:
- name: data
mountPath: /var/lib/mysql
readinessProbe:
exec:
command:
- mysqladmin
- ping
- -h
- localhost
periodSeconds: 3
volumeClaimTemplates:
- metadata:
name: data
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
ports:
- port: 3306
targetPort: 3306
- uri: template://default-provisioners/mongo
type: mongodb
init: |
randomDatabase: db-{{ randAlpha 8 }}
randomUsername: user-{{ randAlpha 8 }}
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: mongo-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
database: {{ dig "database" .Init.randomDatabase .State | quote }}
username: {{ dig "username" .Init.randomUsername .State | quote }}
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
host: {{ .State.service }}
port: 27017
name: {{ .State.database }}
connection: "mongodb://{{ .State.username }}:{{ .State.password }}@{{ .State.service }}:27017/"
username: {{ .State.username }}
password: {{ encodeSecretRef .State.service "MONGO_INITDB_ROOT_PASSWORD" }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
data:
MONGO_INITDB_ROOT_PASSWORD: {{ .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
replicas: 1
serviceName: {{ .State.service }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
spec:
automountServiceAccountToken: false
containers:
- name: mongo-db
image: mongo:latest
ports:
- name: mongo
containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
value: {{ .State.username | quote }}
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .State.service }}
key: MONGO_INITDB_ROOT_PASSWORD
livenessProbe:
exec:
command:
- /bin/sh
- -c
- echo 'db.runCommand("ping").ok' | mongosh -u $$MONGO_INITDB_ROOT_USERNAME -p $$MONGO_INITDB_ROOT_PASSWORD
initialDelaySeconds: 30
timeoutSeconds: 5
periodSeconds: 20
securityContext:
runAsUser: 1001
runAsGroup: 1001
allowPrivilegeEscalation: false
privileged: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
volumeMounts:
- name: data
mountPath: /data/db
- name: tmp
mountPath: /tmp
securityContext:
runAsNonRoot: true
fsGroup: 1001
seccompProfile:
type: RuntimeDefault
volumes:
- name: tmp
emptyDir: {}
volumeClaimTemplates:
- metadata:
name: data
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
ports:
- port: 27017
targetPort: 27017
- uri: template://default-provisioners/rabbitmq
type: amqp
init: |
randomVHost: vhost-{{ randAlpha 8 }}
randomUsername: user-{{ randAlpha 8 }}
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: rabbitmq-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
vhost: {{ dig "vhost" .Init.randomVHost .State | quote }}
username: {{ dig "username" .Init.randomUsername .State | quote }}
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
host: {{ .State.service }}
port: 5672
vhost: {{ .State.vhost }}
username: {{ .State.username }}
password: {{ .State.password }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}-secret
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}-secret
app.kubernetes.io/instance: {{ .State.service }}
data:
RABBITMQ_DEFAULT_VHOST: {{ .State.vhost | b64enc }}
RABBITMQ_DEFAULT_USER: {{ .State.username | b64enc }}
RABBITMQ_DEFAULT_PASS: {{ .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
serviceName: {{ .State.service }}
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
containers:
- name: rabbitmq
image: rabbitmq:3-management
ports:
- name: amqp
containerPort: 5672
- name: management
containerPort: 15672
envFrom:
- secretRef:
name: {{ .State.service }}-secret
volumeMounts:
- name: data
mountPath: /var/lib/rabbitmq
readinessProbe:
exec:
command:
- rabbitmq-diagnostics
- -q
- check_port_connectivity
periodSeconds: 3
initialDelaySeconds: 30
timeoutSeconds: 5
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 3Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
ports:
- port: 5672
targetPort: 5672
name: amqp
- port: 15672
targetPort: 15672
name: management
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
- uri: template://default-provisioners/mssql
type: mssql
init: |
randomPassword: {{ randAlphaNum 16 | quote }}
state: |
service: mssql-{{ .SourceWorkload }}-{{ substr 0 8 .Guid | lower }}
database: master
username: sa
password: {{ dig "password" .Init.randomPassword .State | quote }}
outputs: |
server: {{ .State.service }}
port: 1433
connection: "Server=tcp:{{ .State.service }},1433;Initial Catalog={{ .State.database }};User ID={{ .State.username }};Password={{ encodeSecretRef .State.service "MSSQL_SA_PASSWORD" }}"
database: {{ .State.database }}
username: {{ .State.username }}
password: {{ encodeSecretRef .State.service "MSSQL_SA_PASSWORD" }}
manifests: |
- apiVersion: v1
kind: Secret
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
data:
MSSQL_SA_PASSWORD: {{ .State.password | b64enc }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
replicas: 1
serviceName: {{ .State.service }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ .State.service }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
spec:
containers:
- name: mssql-db
image: mcr.microsoft.com/mssql/server:latest
ports:
- name: mssql
containerPort: 1433
env:
- name: ACCEPT_EULA
value: "Y"
- name: MSSQL_ENABLE_HADR
value: "1"
- name: MSSQL_AGENT_ENABLED
value: "1"
- name: MSSQL_SA_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .State.service }}
key: MSSQL_SA_PASSWORD
volumeMounts:
- name: mssql
mountPath: "/var/opt/mssql"
volumeClaimTemplates:
- metadata:
name: mssql
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: {{ .State.service }}
annotations:
k8s.score.dev/source-workload: {{ .SourceWorkload }}
k8s.score.dev/resource-uid: {{ .Uid }}
k8s.score.dev/resource-guid: {{ .Guid }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ .State.service }}
app.kubernetes.io/instance: {{ .State.service }}
spec:
selector:
app.kubernetes.io/instance: {{ .State.service }}
type: ClusterIP
ports:
- port: 1433
targetPort: 1433
# This resource provides an in-cluster minio based S3 bucket with AWS-style credentials.
# This provides some common and well known outputs that can be used with any generic AWS s3 client.
# The outputs of the provisioner are a stateful set, a service, a secret, and a job per bucket.
- uri: template://default-provisioners/s3
type: s3
# The init template contains some initial seed data that can be used t needed.
init: |
sk: default-provisioners-minio-instance
state: |
bucket: {{ dig "bucket" (printf "bucket-%s" .Guid) .State | quote }}
shared: |
{{ .Init.sk }}:
instanceServiceName: {{ dig .Init.sk "instanceServiceName" (randAlpha 7 | lower | printf "minio-%s") .Shared | quote }}
instanceUsername: {{ dig .Init.sk "instanceUsername" (randAlpha 7 | printf "user-%s") .Shared | quote }}
instancePassword: {{ dig .Init.sk "instancePassword" (randAlphaNum 16) .Shared | quote }}
instanceAccessKeyId: {{ dig .Init.sk "instanceAccessKeyId" (randAlphaNum 20) .Shared | quote }}
instanceSecretKey: {{ dig .Init.sk "instanceSecretKey" (randAlphaNum 40) .Shared | quote }}
outputs: |
{{ $shared := dig .Init.sk (dict) .Shared }}
{{ $service := $shared.instanceServiceName }}
bucket: {{ .State.bucket }}
access_key_id: {{ $shared.instanceAccessKeyId | quote }}
secret_key: {{ encodeSecretRef $service "secret_key" }}
endpoint: http://{{ $service }}:9000
region: "us-east-1"
# for compatibility with Humanitec's existing s3 resource
aws_access_key_id: {{ $shared.instanceAccessKeyId | quote }}
aws_secret_key: {{ encodeSecretRef $service "secret_key" }}
manifests: |
{{ $shared := dig .Init.sk (dict) .Shared }}
{{ $service := $shared.instanceServiceName }}
- apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ $service | quote }}
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ $service | quote }}
app.kubernetes.io/instance: {{ $service | quote }}
spec:
replicas: 1
serviceName: {{ $service | quote }}
selector:
matchLabels:
app.kubernetes.io/instance: {{ $service | quote }}
template:
metadata:
labels:
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: {{ $service | quote }}
app.kubernetes.io/instance: {{ $service | quote }}
spec:
automountServiceAccountToken: false
containers:
- name: minio
image: quay.io/minio/minio
args: ["server", "/data", "--console-address", ":9001"]
ports:
- name: service
containerPort: 9000
- name: console
containerPort: 9001
env:
- name: MINIO_ROOT_USER
value: {{ $shared.instanceUsername | quote }}
- name: MINIO_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ $service | quote }}
key: password
securityContext:
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
privileged: false
capabilities:
drop:
- ALL
volumeMounts:
- name: data
mountPath: /data
securityContext: