Created
June 30, 2025 21:11
-
-
Save x95castle1/368b4f57c98c2092c1f888fe31a733c1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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") | |
| #@ load("@ytt:data", "data") | |
| #@ load("@ytt:yaml", "yaml") | |
| #@ def kpack_template(): | |
| kind: ClusterImageTemplate | |
| metadata: | |
| name: kpack-template | |
| #@ end | |
| #@overlay/match by=overlay.subset (kpack_template()) | |
| --- | |
| spec: | |
| #@overlay/replace via=lambda left, right: left.replace("services: #@ data.values.params.buildServiceBindings", right) | |
| ytt: | | |
| services: | |
| - apiVersion: v1 | |
| kind: Secret | |
| name: ca-cert-binding |
This file contains hidden or 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
| apiVersion: carto.run/v1alpha1 | |
| kind: ClusterImageTemplate | |
| metadata: | |
| name: kpack-template | |
| spec: | |
| params: | |
| - name: serviceAccount | |
| default: default | |
| - name: clusterBuilder | |
| default: default | |
| - name: registry | |
| default: {} | |
| - name: buildServiceBindings | |
| default: [] | |
| - name: additionalTags | |
| default: [] | |
| - name: creationTime | |
| default: "" | |
| imagePath: .status.latestImage | |
| healthRule: | |
| multiMatch: | |
| healthy: | |
| matchConditions: | |
| - status: "True" | |
| type: BuilderReady | |
| - status: "True" | |
| type: Ready | |
| unhealthy: | |
| matchConditions: | |
| - status: "False" | |
| type: BuilderReady | |
| - status: "False" | |
| type: Ready | |
| #@ label_exclusions = "[\"" + "\", \"".join(["kapp.k14s.io/app", "kapp.k14s.io/association"]) + "\"]" | |
| #@yaml/text-templated-strings | |
| ytt: | | |
| #@ load("@ytt:data", "data") | |
| #@ load("@ytt:regexp", "regexp") | |
| #@ def merge_labels(fixed_values): | |
| #@ labels = {} | |
| #@ if hasattr(data.values.workload.metadata, "labels"): | |
| #@ exclusions = (@= label_exclusions @) | |
| #@ for k,v in dict(data.values.workload.metadata.labels).items(): | |
| #@ if k not in exclusions: | |
| #@ labels[k] = v | |
| #@ end | |
| #@ end | |
| #@ end | |
| #@ labels.update(fixed_values) | |
| #@ return labels | |
| #@ end | |
| #@ def param(key): | |
| #@ if not key in data.values.params: | |
| #@ return None | |
| #@ end | |
| #@ return data.values.params[key] | |
| #@ end | |
| #@ def maven_param(key): | |
| #@ if not key in data.values.params["maven"]: | |
| #@ return None | |
| #@ end | |
| #@ return data.values.params["maven"][key] | |
| #@ end | |
| #@ def maven_repository_url(): | |
| #@ if maven_param("repository") and "url" in maven_param("repository"): | |
| #@ return maven_param("repository")["url"] | |
| #@ elif param("maven_repository_url"): | |
| #@ return param("maven_repository_url") | |
| #@ else: | |
| #@ return None | |
| #@ end | |
| #@ end | |
| #@ def image(): | |
| #@ return "/".join([ | |
| #@ data.values.params.registry.server, | |
| #@ data.values.params.registry.repository, | |
| #@ "-".join([ | |
| #@ data.values.workload.metadata.name, | |
| #@ data.values.workload.metadata.namespace, | |
| #@ ]) | |
| #@ ]) | |
| #@ end | |
| #@ def correlationId(): | |
| #@ if hasattr(data.values.workload, "annotations") and hasattr(data.values.workload.annotations, "apps.tanzu.vmware.com/correlationid"): | |
| #@ return data.values.workload.annotations["apps.tanzu.vmware.com/correlationid"] | |
| #@ end | |
| #@ url = "" | |
| #@ if hasattr(data.values.workload.spec, "source"): | |
| #@ if hasattr(data.values.workload.spec.source, "git"): | |
| #@ url = data.values.workload.spec.source.git.url | |
| #@ elif hasattr(data.values.workload.spec.source, "image"): | |
| #@ url = data.values.workload.spec.source.image.split("@")[0] | |
| #@ end | |
| #@ url = url + "?sub_path=" + getattr(data.values.workload.spec.source, "subPath", "/") | |
| #@ end | |
| #@ if param("maven"): | |
| #@ url = maven_repository_url() + "/" + maven_param("groupId").replace(".", "/") + "/" + maven_param("artifactId") | |
| #@ end | |
| #@ return url | |
| #@ end | |
| apiVersion: kpack.io/v1alpha2 | |
| kind: Image | |
| metadata: | |
| name: #@ data.values.workload.metadata.name | |
| labels: #@ merge_labels({ "app.kubernetes.io/component": "build" }) | |
| annotations: | |
| apps.tanzu.vmware.com/correlationid: #@ correlationId() | |
| spec: | |
| tag: #@ image() | |
| additionalTags: #@ data.values.params.additionalTags | |
| serviceAccountName: #@ data.values.params.serviceAccount | |
| builder: | |
| kind: ClusterBuilder | |
| name: #@ data.values.params.clusterBuilder | |
| source: | |
| blob: | |
| url: #@ data.values.source.url | |
| #@ if hasattr(data.values.workload.spec, "source"): | |
| #@ if/end hasattr(data.values.workload.spec.source, "subPath"): | |
| subPath: #@ data.values.workload.spec.source.subPath | |
| #@ end | |
| build: | |
| env: | |
| - name: BP_OCI_SOURCE | |
| value: #@ data.values.source.revision | |
| #@ if regexp.match("^([a-zA-Z0-9\/_-]+)(\@sha1:)?[0-9a-f]{40}$", data.values.source.revision): | |
| - name: BP_OCI_REVISION | |
| value: #@ data.values.source.revision | |
| #@ end | |
| #@ if/end param("live-update"): | |
| - name: BP_LIVE_RELOAD_ENABLED | |
| value: 'true' | |
| #@ if hasattr(data.values.workload.spec.build, "env"): | |
| #@ for var in data.values.workload.spec.build.env: | |
| - name: #@ var.name | |
| #@ if/end hasattr(var, "value"): | |
| value: #@ var.value | |
| #@ if/end hasattr(var, "valueFrom"): | |
| valueFrom: #@ var.valueFrom | |
| #@ end | |
| #@ end | |
| services: #@ data.values.params.buildServiceBindings | |
| creationTime: #@ data.values.params.creationTime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment