Created
September 11, 2024 13:43
-
-
Save x95castle1/a8dc0a32efca44f8968c848e135a5ff2 to your computer and use it in GitHub Desktop.
Add Dangerous Flags to Carvel to only focus on the Namespace the App is running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:overlay", "overlay") | |
#@ def deploy_template(): | |
kind: ClusterDeploymentTemplate | |
metadata: | |
name: app-deploy | |
#@ end | |
#@overlay/match by=overlay.subset(deploy_template()) | |
--- | |
spec: | |
#@overlay/replace via=lambda left, right: left.replace("- kapp: {}", right.strip()) | |
ytt: |- | |
- kapp: | |
rawOptions: | |
- --dangerous-scope-to-fallback-allowed-namespaces=true | |
inspect: | |
rawOptions: | |
- --dangerous-scope-to-fallback-allowed-namespaces=true | |
delete: | |
rawOptions: | |
- --dangerous-scope-to-fallback-allowed-namespaces=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@ load("@ytt:data", "data") | |
#@ load("@ytt:yaml", "yaml") | |
--- | |
apiVersion: carto.run/v1alpha1 | |
kind: ClusterDeploymentTemplate | |
metadata: | |
name: app-deploy | |
spec: | |
params: | |
- name: serviceAccount | |
default: default | |
healthRule: | |
multiMatch: | |
healthy: | |
matchConditions: | |
- type: ReconcileSucceeded | |
status: 'True' | |
unhealthy: | |
matchFields: | |
- key: 'status.conditions[?(@.type=="ReconcileFailed")].status' | |
operator: 'In' | |
values: ['True'] | |
messagePath: '.status.usefulErrorMessage' | |
observedCompletion: | |
succeeded: | |
key: '.status.conditions[?(@.type=="ReconcileSucceeded")].status' | |
value: 'True' | |
failed: | |
key: '.status.conditions[?(@.type=="ReconcileSucceeded")].status' | |
value: 'False' | |
#@ label_propagation_exclusions = ["kapp.k14s.io/app", "kapp.k14s.io/association"] | |
#@ label_exclusions = "[\"" + "\", \"".join(label_propagation_exclusions) + "\"]" | |
#@yaml/text-templated-strings | |
ytt: | | |
#@ load("@ytt:data", "data") | |
#@ load("@ytt:yaml", "yaml") | |
#@ load("@ytt:assert", "assert") | |
#@ def merge_labels(fixed_values): | |
#@ labels = {} | |
#@ if hasattr(data.values.deliverable.metadata, "labels"): | |
#@ exclusions = (@= label_exclusions @) | |
#@ for k,v in dict(data.values.deliverable.metadata.labels).items(): | |
#@ if k not in exclusions: | |
#@ labels[k] = v | |
#@ end | |
#@ end | |
#@ end | |
#@ labels.update(fixed_values) | |
#@ return labels | |
#@ end | |
#@ def kapp_config(): | |
apiVersion: kapp.k14s.io/v1alpha1 | |
kind: Config | |
rebaseRules: | |
- path: [metadata, annotations, serving.knative.dev/creator] | |
type: copy | |
sources: [new, existing] | |
resourceMatchers: &matchers | |
- apiVersionKindMatcher: {apiVersion: serving.knative.dev/v1, kind: Service} | |
- path: [metadata, annotations, serving.knative.dev/lastModifier] | |
type: copy | |
sources: [new, existing] | |
resourceMatchers: *matchers | |
waitRules: | |
- resourceMatchers: | |
- apiVersionKindMatcher: | |
apiVersion: serving.knative.dev/v1 | |
kind: Service | |
conditionMatchers: | |
- type: Ready | |
status: "True" | |
success: true | |
- type: Ready | |
status: "False" | |
failure: true | |
ownershipLabelRules: | |
- path: [ spec, template, metadata, labels ] | |
resourceMatchers: | |
- apiVersio | |
#@ end | |
--- | |
apiVersion: kappctrl.k14s.io/v1alpha1 | |
kind: App | |
metadata: | |
name: #@ data.values.deliverable.metadata.name | |
labels: #@ merge_labels({ "app.kubernetes.io/component": "deploy" }) | |
spec: | |
syncPeriod: 10m0s | |
serviceAccountName: #@ data.values.params.serviceAccount | |
fetch: | |
- http: | |
url: #@ data.values.deployment.url or assert.fail("missing required deployment config url") | |
#@ if hasattr(data.values.deliverable.spec.source, "subPath"): | |
subPath: #@ data.values.deliverable.spec.source.subPath | |
#@ elif hasattr(data.values.params, "gitops_sub_path"): | |
subPath: #@ data.values.params.gitops_sub_path | |
#@ end | |
- inline: | |
paths: | |
config.yml: #@ yaml.encode(kapp_config()) | |
template: | |
- ytt: {} | |
- kbld: {} | |
deploy: | |
- kapp: {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment