Last active
September 9, 2022 13:59
-
-
Save pivotaljohn/764ba4e43c7f4fab0bfed08175c3e711 to your computer and use it in GitHub Desktop.
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
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: backend | |
namespace: default | |
spec: | |
selector: | |
matchLabels: | |
app: backend | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
app: backend | |
spec: | |
containers: | |
- name: default | |
image: user/backend | |
- name: sidecar | |
image: proxy | |
livenessProbe: | |
httpGet: | |
path: /check | |
port: 8081 | |
initialDelaySeconds: 2 | |
periodSeconds: 10 | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: frontend | |
namespace: default | |
spec: | |
selector: | |
matchLabels: | |
app: frontend | |
replicas: 1 | |
template: | |
metadata: | |
labels: | |
app: frontend | |
spec: | |
containers: | |
- name: default | |
image: user/frontend | |
- name: job-runner | |
image: user/batch |
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") | |
#@overlay/match by=overlay.subset({"kind": "Deployment"}), expects="1+" | |
--- | |
spec: | |
template: | |
spec: | |
containers: | |
#! This matcher determines: of all the containers in this list, | |
#! which will we even look at... In our case, all of them. | |
#@overlay/match by=overlay.all, expects="1+" | |
- | |
#@overlay/match when=0 | |
livenessProbe: | |
httpGet: | |
path: /health | |
port: 8080 | |
initialDelaySeconds: 3 | |
periodSeconds: 3 | |
#! This matcher runs independently of the one above. We're | |
#! combining two edits in one overlay document: | |
#! - one that ensures there's a livenessProbe | |
#! - a separate one that ensures there's a startupProbe | |
#@overlay/match by=overlay.all, expects="1+" | |
- | |
#@overlay/match when=0 | |
startupProbe: | |
failureThreshold: 30 | |
periodSeconds: 10 | |
#! line 12: note the newline before the annotation; this is needed so | |
#! that the `@overlay/match ...` annotation applies to the | |
#! `livenessProbe:` map item and _not_ the array item that contains | |
#! it. | |
#! | |
#! details at https://carvel.dev/ytt/docs/v0.42.0/yaml-primer/#example-annotating-an-array | |
#! line 13: this matcher only runs in the event there _is_ no `livenessProbe:` | |
#! already defined. | |
#@ load("@ytt:yaml", "yaml") | |
#@ def copy_gets(orig, _): | |
#@ edit = yaml.decode(yaml.encode(orig)) | |
#@ if "httpGet" in edit["livenessProbe"]: | |
#@ edit["startupProbe"]["httpGet"] = edit["livenessProbe"]["httpGet"] | |
#@ end | |
#@ if "tcpSocket" in edit["livenessProbe"]: | |
#@ edit["startupProbe"]["tcpSocket"] = edit["livenessProbe"]["tcpSocket"] | |
#@ end | |
#@ return edit | |
#@ end | |
#! line 47: we need to make an editable copy of `orig`. | |
#! - `orig` is of type "YAML Fragment" and is immutable. | |
#! - by encoding into a string, then decoding into Starlark-native (mutable) types | |
#! we can now edit the result. | |
#@overlay/match by=overlay.subset({"kind": "Deployment"}), expects="1+" | |
--- | |
spec: | |
template: | |
spec: | |
containers: | |
#! This matcher checks some preconditions, so that only containers | |
#! that have the requisite configuration will be targeted. | |
#! Specifically: there must be _both_ a liveness and startup probe | |
#! already. | |
#@overlay/match by=lambda _,left,__: ("livenessProbe" in left) and ("startupProbe" in left), expects="1+" | |
#@overlay/replace via=copy_gets | |
- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment