-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathdefault.go
709 lines (634 loc) · 29 KB
/
default.go
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
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package config
import (
ctlres "github.com/vmware-tanzu/carvel-kapp/pkg/kapp/resources"
)
const defaultConfigYAML = `---
apiVersion: kapp.k14s.io/v1alpha1
kind: Config
rebaseRules:
# Copy over all metadata (with resourceVersion, etc.)
- path: [metadata]
type: copy
sources: [existing]
resourceMatchers:
- allMatcher: {}
# Be specific about labels to be applied
- path: [metadata, labels]
type: remove
resourceMatchers:
- allMatcher: {}
- path: [metadata, labels]
type: copy
sources: [new]
resourceMatchers:
- allMatcher: {}
# Be specific about annotations to be applied
- path: [metadata, annotations]
type: remove
resourceMatchers:
- allMatcher: {}
- path: [metadata, annotations]
type: copy
sources: [new]
resourceMatchers:
- allMatcher: {}
# Prefer user provided, but allow cluster set
- paths:
- [spec, clusterIP]
- [spec, healthCheckNodePort]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Service}
# Prefer user provided, but allow cluster set
- path: [spec, finalizers]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Namespace}
# Openshift adds some annotations and labels to namespaces
- paths:
- [metadata, annotations, openshift.io/sa.scc.mcs]
- [metadata, annotations, openshift.io/sa.scc.supplemental-groups]
- [metadata, annotations, openshift.io/sa.scc.uid-range]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Namespace}
# PVC
- paths:
- [metadata, annotations, pv.kubernetes.io/bind-completed]
- [metadata, annotations, pv.kubernetes.io/bound-by-controller]
- [metadata, annotations, pv.kubernetes.io/migrated-to]
- [metadata, annotations, volume.beta.kubernetes.io/storage-provisioner]
- [spec, storageClassName]
- [spec, volumeMode]
- [spec, volumeName]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: PersistentVolumeClaim}
- path: [metadata, annotations, "deployment.kubernetes.io/revision"]
type: copy
sources: [new, existing]
resourceMatchers: &appsV1DeploymentWithRevAnnKey
- apiVersionKindMatcher: {apiVersion: apps/v1, kind: Deployment}
- apiVersionKindMatcher: {apiVersion: apps/v1beta1, kind: Deployment}
- apiVersionKindMatcher: {apiVersion: apps/v1beta2, kind: Deployment}
- apiVersionKindMatcher: {apiVersion: extensions/v1beta1, kind: Deployment}
- path: [webhooks, {allIndexes: true}, clientConfig, caBundle]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: admissionregistration.k8s.io/v1beta1, kind: MutatingWebhookConfiguration}
- apiVersionKindMatcher: {apiVersion: admissionregistration.k8s.io/v1, kind: MutatingWebhookConfiguration}
- apiVersionKindMatcher: {apiVersion: admissionregistration.k8s.io/v1beta1, kind: ValidatingWebhookConfiguration}
- apiVersionKindMatcher: {apiVersion: admissionregistration.k8s.io/v1, kind: ValidatingWebhookConfiguration}
- path: [spec, caBundle]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: apiregistration.k8s.io/v1beta1, kind: APIService}
- apiVersionKindMatcher: {apiVersion: apiregistration.k8s.io/v1, kind: APIService}
- path: [spec, conversion, webhookClientConfig, caBundle]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: apiextensions.k8s.io/v1beta1, kind: CustomResourceDefinition}
- path: [spec, conversion, webhook, clientConfig, caBundle]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: apiextensions.k8s.io/v1, kind: CustomResourceDefinition}
- path: [spec, nodeName]
type: copy
sources: [new, existing]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Pod}
# ServiceAccount controller appends secret named '${metadata.name}-token-${rand}' after the save
# Openshift adds a secret and an imagePullSecret named '${metadata.name}-dockercfg-${rand}' after the save
- ytt:
overlayContractV1:
overlay.yml: |
#@ load("@ytt:data", "data")
#@ load("@ytt:overlay", "overlay")
#@ res_name = data.values.existing.metadata.name
#! service account may be created with empty secrets
#@ secrets = []
#@ if hasattr(data.values.existing, "secrets"):
#@ secrets = data.values.existing.secrets
#@ end
#@ imagePullSecrets = []
#@ if hasattr(data.values.existing, "imagePullSecrets"):
#@ imagePullSecrets = data.values.existing.imagePullSecrets
#@ end
#@ token_secret_name = None
#@ token_secret_name_docker = None
#@ for k in secrets:
#@ if k.name.startswith(res_name+"-token-"):
#@ token_secret_name = k.name
#@ end
#@ if k.name.startswith(res_name+"-dockercfg-"):
#@ token_secret_name_docker = k.name
#@ end
#@ end
#@ image_pull_secret_name = None
#@ for k in imagePullSecrets:
#@ if k.name.startswith(res_name+"-dockercfg-"):
#@ image_pull_secret_name = k.name
#@ end
#@ end
#! in case token secret name is not included, do not modify anything
#@ if/end image_pull_secret_name:
#@overlay/match by=overlay.all
---
#@overlay/match missing_ok=True
imagePullSecrets:
#@overlay/match by=overlay.subset({"name": image_pull_secret_name}),when=0
- name: #@ image_pull_secret_name
#@ if/end token_secret_name:
#@overlay/match by=overlay.all
---
#@overlay/match missing_ok=True
secrets:
#@overlay/match by=overlay.subset({"name": token_secret_name}),when=0
- name: #@ token_secret_name
#@ if/end token_secret_name_docker:
#@overlay/match by=overlay.all
---
#@overlay/match missing_ok=True
secrets:
#@overlay/match by=overlay.subset({"name": token_secret_name_docker}),when=0
- name: #@ token_secret_name_docker
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: ServiceAccount}
# Secretgen populates secret data for annotated secrets
- paths:
- [data, .dockerconfigjson]
- [metadata, annotations, secretgen.carvel.dev/status]
type: copy
sources: [existing, new]
resourceMatchers:
- andMatcher:
matchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Secret}
- hasAnnotationMatcher:
keys: [secretgen.carvel.dev/image-pull-secret]
- notMatcher:
matcher:
hasAnnotationMatcher:
keys: [kapp.k14s.io/disable-default-secretgen-rebase-rules]
# aggregated ClusterRole rules are filled in by the control plane at runtime
# refs https://kubernetes.io/docs/reference/access-authn-authz/rbac/#aggregated-clusterroles
- paths:
- [rules]
type: copy
sources: [existing]
resourceMatchers:
- andMatcher:
matchers:
- anyMatcher:
matchers:
- apiVersionKindMatcher: {kind: ClusterRole, apiVersion: rbac.authorization.k8s.io/v1}
- apiVersionKindMatcher: {kind: ClusterRole, apiVersion: rbac.authorization.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: ClusterRole, apiVersion: rbac.authorization.k8s.io/v1beta1}
- notMatcher:
matcher:
emptyFieldMatcher:
path: [aggregationRule]
diffAgainstLastAppliedFieldExclusionRules:
- path: [metadata, annotations, "deployment.kubernetes.io/revision"]
resourceMatchers: *appsV1DeploymentWithRevAnnKey
- path: [status]
resourceMatchers:
- allMatcher: {}
diffMaskRules:
- path: [data]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Secret}
- path: [stringData]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Secret}
ownershipLabelRules:
- path: [metadata, labels]
resourceMatchers:
- allMatcher: {}
- path: [spec, template, metadata, labels]
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher: &disableDefaultOwnershipLabelRulesAnnMatcher
hasAnnotationMatcher:
keys: [kapp.k14s.io/disable-default-ownership-label-rules]
- anyMatcher:
matchers: &withPodTemplate
# Deployment
- apiVersionKindMatcher: {apiVersion: apps/v1, kind: Deployment}
- apiVersionKindMatcher: {apiVersion: apps/v1beta2, kind: Deployment}
- apiVersionKindMatcher: {apiVersion: apps/v1beta1, kind: Deployment}
- apiVersionKindMatcher: {apiVersion: extensions/v1beta1, kind: Deployment}
# ReplicaSet
- apiVersionKindMatcher: {apiVersion: apps/v1, kind: ReplicaSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta2, kind: ReplicaSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta1, kind: ReplicaSet}
- apiVersionKindMatcher: {apiVersion: extensions/v1beta1, kind: ReplicaSet}
# StatefulSet
- apiVersionKindMatcher: {apiVersion: apps/v1, kind: StatefulSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta2, kind: StatefulSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta1, kind: StatefulSet}
- apiVersionKindMatcher: {apiVersion: extensions/v1beta1, kind: StatefulSet}
# DaemonSet
- apiVersionKindMatcher: {apiVersion: apps/v1, kind: DaemonSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta2, kind: DaemonSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta1, kind: DaemonSet}
- apiVersionKindMatcher: {apiVersion: extensions/v1beta1, kind: DaemonSet}
# Job
- apiVersionKindMatcher: {apiVersion: batch/v1, kind: Job}
# TODO It seems that these labels are being ignored
# https://github.com/kubernetes/kubernetes/issues/74916
- path: [spec, volumeClaimTemplates, {allIndexes: true}, metadata, labels]
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher: *disableDefaultOwnershipLabelRulesAnnMatcher
- anyMatcher:
matchers:
# StatefulSet
- apiVersionKindMatcher: {apiVersion: apps/v1, kind: StatefulSet}
- apiVersionKindMatcher: {apiVersion: apps/v1beta1, kind: StatefulSet}
- apiVersionKindMatcher: {apiVersion: extensions/v1beta1, kind: StatefulSet}
- path: [spec, template, metadata, labels]
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher: *disableDefaultOwnershipLabelRulesAnnMatcher
- anyMatcher:
matchers:
- apiVersionKindMatcher: {apiVersion: batch/v1, kind: Job}
- apiVersionKindMatcher: {apiVersion: batch/v1beta1, kind: Job}
- apiVersionKindMatcher: {apiVersion: batch/v2alpha1, kind: Job}
- path: [spec, jobTemplate, spec, template, metadata, labels]
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher: *disableDefaultOwnershipLabelRulesAnnMatcher
- anyMatcher:
matchers: &cronJob
- apiVersionKindMatcher: {apiVersion: batch/v1, kind: CronJob}
- apiVersionKindMatcher: {apiVersion: batch/v1beta1, kind: CronJob}
- apiVersionKindMatcher: {apiVersion: batch/v2alpha1, kind: CronJob}
labelScopingRules:
- path: [spec, selector]
isDefault: true
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
# Keep older annotation for backwards compatibility
matcher: &disableLabelScopingAnnMatcher
hasAnnotationMatcher:
keys: [kapp.k14s.io/disable-label-scoping]
- notMatcher:
matcher: &disableDefaultLabelScopingRulesAnnMatcher
hasAnnotationMatcher:
keys: [kapp.k14s.io/disable-default-label-scoping-rules]
- apiVersionKindMatcher: {apiVersion: v1, kind: Service}
- path: [spec, selector, matchLabels]
isDefault: true
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher: *disableLabelScopingAnnMatcher
- notMatcher:
matcher: *disableDefaultLabelScopingRulesAnnMatcher
- anyMatcher:
matchers: *withPodTemplate
- path: [spec, selector, matchLabels]
isDefault: true
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher: *disableLabelScopingAnnMatcher
- notMatcher:
matcher: *disableDefaultLabelScopingRulesAnnMatcher
- apiVersionKindMatcher: {apiVersion: policy/v1beta1, kind: PodDisruptionBudget}
templateRules:
- resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: ConfigMap}
affectedResources:
objectReferences:
- path: [spec, template, spec, containers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, configMapKeyRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, containers, {allIndexes: true}, envFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, initContainers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, configMapKeyRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, initContainers, {allIndexes: true}, envFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, volumes, {allIndexes: true}, projected, sources, {allIndexes: true}, configMap]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, volumes, {allIndexes: true}, configMap]
resourceMatchers: *withPodTemplate
- path: [spec, jobTemplate, spec, template, spec, containers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, configMapKeyRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, containers, {allIndexes: true}, envFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, initContainers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, configMapKeyRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, initContainers, {allIndexes: true}, envFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, volumes, {allIndexes: true}, projected, sources, {allIndexes: true}, configMap]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, volumes, {allIndexes: true}, configMap]
resourceMatchers: *cronJob
- path: [spec, volumes, {allIndexes: true}, configMap]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Pod}
- path: [spec, fetch, {allIndexes: true}, inline, pathsFrom, {allIndexes: true}, configMapRef]
resourceMatchers: &appMatchers
- apiVersionKindMatcher: {apiVersion: kappctrl.k14s.io/v1alpha1, kind: App}
- path: [spec, template, {allIndexes: true}, ytt, inline, pathsFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, ytt, valuesFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, helmTemplate, valuesFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, cue, valuesFrom, {allIndexes: true}, configMapRef]
resourceMatchers: *appMatchers
- path: [spec, fetch, inline, pathsFrom, {allIndexes: true}, configMapRef]
resourceMatchers: &packageRepositoryMatchers
- apiVersionKindMatcher: {apiVersion: packaging.carvel.dev/v1alpha1, kind: PackageRepository}
- resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Secret}
affectedResources:
objectReferences:
- path: [spec, template, spec, containers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, secretKeyRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, containers, {allIndexes: true}, envFrom, {allIndexes: true}, secretRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, initContainers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, secretKeyRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, initContainers, {allIndexes: true}, envFrom, {allIndexes: true}, secretRef]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, imagePullSecrets, {allIndexes: true}]
resourceMatchers: *withPodTemplate
- path: [spec, template, spec, volumes, {allIndexes: true}, secret]
resourceMatchers: *withPodTemplate
nameKey: secretName
- path: [spec, template, spec, volumes, {allIndexes: true}, projected, sources, {allIndexes: true}, secret]
resourceMatchers: *withPodTemplate
- path: [spec, jobTemplate, spec, template, spec, containers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, secretKeyRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, containers, {allIndexes: true}, envFrom, {allIndexes: true}, secretRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, initContainers, {allIndexes: true}, env, {allIndexes: true}, valueFrom, secretKeyRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, initContainers, {allIndexes: true}, envFrom, {allIndexes: true}, secretRef]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, imagePullSecrets, {allIndexes: true}]
resourceMatchers: *cronJob
- path: [spec, jobTemplate, spec, template, spec, volumes, {allIndexes: true}, secret]
resourceMatchers: *cronJob
nameKey: secretName
- path: [spec, jobTemplate, spec, template, spec, volumes, {allIndexes: true}, projected, sources, {allIndexes: true}, secret]
resourceMatchers: *cronJob
- path: [spec, volumes, {allIndexes: true}, secret]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Pod}
nameKey: secretName
- path: [spec, imagePullSecrets, {allIndexes: true}]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: Pod}
- path: [imagePullSecrets, {allIndexes: true}]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: ServiceAccount}
- path: [secrets, {allIndexes: true}]
resourceMatchers:
- apiVersionKindMatcher: {apiVersion: v1, kind: ServiceAccount}
- path: [spec, cluster, kubeconfigSecretRef]
resourceMatchers: *appMatchers
- path: [spec, fetch, {allIndexes: true}, inline, pathsFrom, {allIndexes: true}, secretRef]
resourceMatchers: *appMatchers
- path: [spec, fetch, {allIndexes: true}, imgpkgBundle, secretRef]
resourceMatchers: *appMatchers
- path: [spec, fetch, {allIndexes: true}, http, secretRef]
resourceMatchers: *appMatchers
- path: [spec, fetch, {allIndexes: true}, git, secretRef]
resourceMatchers: *appMatchers
- path: [spec, fetch, {allIndexes: true}, helmChart, repository, secretRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, ytt, inline, pathsFrom, {allIndexes: true}, secretRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, ytt, valuesFrom, {allIndexes: true}, secretRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, helmTemplate, valuesFrom, {allIndexes: true}, secretRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, cue, valuesFrom, {allIndexes: true}, secretRef]
resourceMatchers: *appMatchers
- path: [spec, template, {allIndexes: true}, sops, pgp, privateKeySecretRef]
resourceMatchers: *appMatchers
- path: [spec, values, {allIndexes: true}, secretRef]
resourceMatchers: &packageInstallMatchers
- apiVersionKindMatcher: {apiVersion: packaging.carvel.dev/v1alpha1, kind: PackageInstall}
- path: [spec, cluster, kubeconfigSecretRef]
resourceMatchers: *packageInstallMatchers
- path: [spec, fetch, inline, pathsFrom, {allIndexes: true}, secretRef]
resourceMatchers: *packageRepositoryMatchers
changeGroupBindings:
- name: change-groups.kapp.k14s.io/crds
resourceMatchers: &crdMatchers
- apiGroupKindMatcher: {kind: CustomResourceDefinition, apiGroup: apiextensions.k8s.io}
- name: change-groups.kapp.k14s.io/crds-{crd-group}-{crd-kind}
resourceMatchers: *crdMatchers
- name: change-groups.kapp.k14s.io/namespaces
resourceMatchers: &namespaceMatchers
- apiGroupKindMatcher: {kind: Namespace, apiGroup: ""}
- name: change-groups.kapp.k14s.io/namespaces-{name}
resourceMatchers: *namespaceMatchers
- name: change-groups.kapp.k14s.io/storage-class
resourceMatchers: &storageClassMatchers
- apiVersionKindMatcher: {kind: StorageClass, apiVersion: storage/v1}
- apiVersionKindMatcher: {kind: StorageClass, apiVersion: storage/v1beta1}
- name: change-groups.kapp.k14s.io/storage
resourceMatchers: &storageMatchers
- apiVersionKindMatcher: {kind: PersistentVolume, apiVersion: v1}
- apiVersionKindMatcher: {kind: PersistentVolumeClaim, apiVersion: v1}
- name: change-groups.kapp.k14s.io/rbac-roles
resourceMatchers: &rbacRoleMatchers
- apiVersionKindMatcher: {kind: ClusterRole, apiVersion: rbac.authorization.k8s.io/v1}
- apiVersionKindMatcher: {kind: ClusterRole, apiVersion: rbac.authorization.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: ClusterRole, apiVersion: rbac.authorization.k8s.io/v1beta1}
- apiVersionKindMatcher: {kind: Role, apiVersion: rbac.authorization.k8s.io/v1}
- apiVersionKindMatcher: {kind: Role, apiVersion: rbac.authorization.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: Role, apiVersion: rbac.authorization.k8s.io/v1beta1}
- name: change-groups.kapp.k14s.io/rbac-role-bindings
resourceMatchers: &rbacRoleBindingMatchers
- apiVersionKindMatcher: {kind: ClusterRoleBinding, apiVersion: rbac.authorization.k8s.io/v1}
- apiVersionKindMatcher: {kind: ClusterRoleBinding, apiVersion: rbac.authorization.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: ClusterRoleBinding, apiVersion: rbac.authorization.k8s.io/v1beta1}
- apiVersionKindMatcher: {kind: RoleBinding, apiVersion: rbac.authorization.k8s.io/v1}
- apiVersionKindMatcher: {kind: RoleBinding, apiVersion: rbac.authorization.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: RoleBinding, apiVersion: rbac.authorization.k8s.io/v1beta1}
- name: change-groups.kapp.k14s.io/rbac
resourceMatchers: &rbacMatchers
- anyMatcher:
matchers:
- anyMatcher: {matchers: *rbacRoleMatchers}
- anyMatcher: {matchers: *rbacRoleBindingMatchers}
- name: change-groups.kapp.k14s.io/pod-related
resourceMatchers: &podRelatedMatchers
- apiVersionKindMatcher: {kind: NetworkPolicy, apiVersion: extensions/v1beta1}
- apiVersionKindMatcher: {kind: NetworkPolicy, apiVersion: networking.k8s.io/v1}
- apiVersionKindMatcher: {kind: ResourceQuota, apiVersion: v1}
- apiVersionKindMatcher: {kind: LimitRange, apiVersion: v1}
- apiVersionKindMatcher: {kind: PodSecurityPolicy, apiVersion: extensions/v1beta1}
- apiVersionKindMatcher: {kind: PodSecurityPolicy, apiVersion: policy/v1beta1}
- apiVersionKindMatcher: {kind: PodDisruptionBudget, apiVersion: policy/v1beta1}
- apiVersionKindMatcher: {kind: PriorityClass, apiVersion: scheduling.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: PriorityClass, apiVersion: scheduling.k8s.io/v1beta1}
- apiVersionKindMatcher: {kind: PriorityClass, apiVersion: scheduling.k8s.io/v1}
- apiVersionKindMatcher: {kind: RuntimeClass, apiVersion: node.k8s.io/v1alpha1}
- apiVersionKindMatcher: {kind: RuntimeClass, apiVersion: node.k8s.io/v1beta1}
- apiVersionKindMatcher: {kind: ServiceAccount, apiVersion: v1}
- apiVersionKindMatcher: {kind: Secret, apiVersion: v1}
- apiVersionKindMatcher: {kind: ConfigMap, apiVersion: v1}
# [Note]: Do not add Service into this group as it may
# delay other resources with load balancer provisioning
# - apiVersionKindMatcher: {kind: Service, apiVersion: v1}
- name: change-groups.kapp.k14s.io/serviceaccount
resourceMatchers: &serviceAccountMatchers
- apiVersionKindMatcher: {kind: ServiceAccount, apiVersion: v1}
- name: change-groups.kapp.k14s.io/kapp-controller-app
resourceMatchers: *appMatchers
- name: change-groups.kapp.k14s.io/kapp-controller-packageinstall
resourceMatchers: *packageInstallMatchers
changeRuleBindings:
# Insert CRDs before all CRs
- rules:
- "upsert after upserting change-groups.kapp.k14s.io/crds-{api-group}-{kind}"
resourceMatchers:
- andMatcher:
matchers:
- customResourceMatcher: {}
- notMatcher:
matcher: &disableDefaultChangeGroupAnnMatcher
hasAnnotationMatcher:
keys: [kapp.k14s.io/disable-default-change-group-and-rules]
# Delete CRs before CRDs to retain detailed observability
# instead of having CRD deletion trigger all CR deletion
- rules:
- "delete before deleting change-groups.kapp.k14s.io/crds"
ignoreIfCyclical: true
resourceMatchers:
- andMatcher:
matchers:
- customResourceMatcher: {}
- notMatcher:
matcher: *disableDefaultChangeGroupAnnMatcher
# Delete non-CRs after deleting CRDs so that if CRDs use conversion
# webhooks it's more likely that backing webhook resources are still
# available during deletion of CRs
- rules:
- "delete after deleting change-groups.kapp.k14s.io/crds"
ignoreIfCyclical: true
resourceMatchers:
- andMatcher:
matchers:
- notMatcher:
matcher:
customResourceMatcher: {}
- notMatcher:
matcher:
anyMatcher:
matchers: *crdMatchers
- notMatcher:
matcher: *disableDefaultChangeGroupAnnMatcher
# Insert namespaces before all namespaced resources
- rules:
- "upsert after upserting change-groups.kapp.k14s.io/namespaces-{namespace}"
resourceMatchers:
- andMatcher:
matchers:
- hasNamespaceMatcher: {}
- notMatcher:
matcher: *disableDefaultChangeGroupAnnMatcher
# Delete namespaces after deleting namespaced SAs so that resources like
# kapp-controller PackageInstalls can be deleted gracefully.
- rules:
- "delete before deleting change-groups.kapp.k14s.io/namespaces-{namespace}"
ignoreIfCyclical: true
resourceMatchers:
- andMatcher:
matchers:
- notMatcher: {matcher: *disableDefaultChangeGroupAnnMatcher}
- anyMatcher: {matchers: *serviceAccountMatchers}
# Insert roles/ClusterRoles before inserting any roleBinding/ClusterRoleBinding
# Sometimes Binding Creation fail as corresponding Role is not created.
# https://github.com/vmware-tanzu/carvel-kapp/issues/145
- rules:
- "upsert after upserting change-groups.kapp.k14s.io/rbac-roles"
ignoreIfCyclical: true
resourceMatchers:
- andMatcher:
matchers:
- anyMatcher: {matchers: *rbacRoleBindingMatchers}
- notMatcher:
matcher: *disableDefaultChangeGroupAnnMatcher
- rules:
- "upsert before upserting change-groups.kapp.k14s.io/kapp-controller-packageinstall"
- "upsert before upserting change-groups.kapp.k14s.io/kapp-controller-app"
- "delete after deleting change-groups.kapp.k14s.io/kapp-controller-packageinstall"
- "delete after deleting change-groups.kapp.k14s.io/kapp-controller-app"
ignoreIfCyclical: true
resourceMatchers:
- andMatcher:
matchers:
- notMatcher: {matcher: *disableDefaultChangeGroupAnnMatcher}
- anyMatcher:
matchers:
- anyMatcher: {matchers: *serviceAccountMatchers}
- anyMatcher: {matchers: *rbacMatchers}
- rules:
- "upsert after upserting change-groups.kapp.k14s.io/storage-class"
ignoreIfCyclical: true
resourceMatchers:
- apiVersionKindMatcher: {kind: PersistentVolume, apiVersion: v1}
- apiVersionKindMatcher: {kind: PersistentVolumeClaim, apiVersion: v1}
- rules:
# [Note]: prefer to apply pod related changes first to
# work better with applications that do not reload changes
- "upsert after upserting change-groups.kapp.k14s.io/pod-related"
# [Note]: prefer to apply rbac changes first to potentially
# avoid restarts of Pods that rely on correct permissions
- "upsert after upserting change-groups.kapp.k14s.io/rbac"
- "upsert after upserting change-groups.kapp.k14s.io/storage-class"
- "upsert after upserting change-groups.kapp.k14s.io/storage"
ignoreIfCyclical: true
resourceMatchers:
# [Note]: Apply all resources after pod-related change group as it's
# common for other resources to rely on ConfigMaps, Secrets, etc.
- andMatcher:
matchers:
- notMatcher:
matcher:
anyMatcher:
matchers:
- anyMatcher: {matchers: *storageClassMatchers}
- anyMatcher: {matchers: *storageMatchers}
- anyMatcher: {matchers: *rbacMatchers}
- anyMatcher: {matchers: *podRelatedMatchers}
- hasNamespaceMatcher: {}
`
var defaultConfigRes = ctlres.MustNewResourceFromBytes([]byte(defaultConfigYAML))
func NewDefaultConfigString() string { return defaultConfigYAML }
func NewConfFromResourcesWithDefaults(resources []ctlres.Resource) ([]ctlres.Resource, Conf, error) {
return NewConfFromResources(append([]ctlres.Resource{defaultConfigRes}, resources...))
}