Skip to content

Commit 6453e17

Browse files
docs(hooks): document action hooks + hooks-action example
Adds a new 'Action hooks' section to docs-v2/docs/lifecycle-hooks.md describing the action: union member, how it relates to customActions, which deployers support it (kubectl, helm, kpt), and that it shares a runtime with skaffold exec (so a single action definition is runnable standalone or wrapped as a deploy hook). Ships a runnable examples/hooks-action/ fixture (mirrored under integration/examples/) with pre-deploy-check + post-deploy-smoke actions and a minimal busybox Pod manifest so maintainers can smoke test the new schema end-to-end.
1 parent 4a928fb commit 6453e17

6 files changed

Lines changed: 142 additions & 0 deletions

File tree

docs-v2/content/en/docs/lifecycle-hooks.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,42 @@ deploy:
154154
podName: hooks-example-deployment*
155155
```
156156
This config snippet defines a simple `echo` command to run inside the containers that match `podName` and `containerName`, before and after each `kubectl` deploy. The `after` container commands are only run after the [deployment status checks]({{< relref "/docs/status-check" >}}) on the deployment are complete. Also, unlike the `sync` container hooks, skaffold cannot determine the target container from just the config definition, and needs the `podName` and `containerName`.
157+
158+
## Action hooks
159+
160+
Action hooks dispatch an existing [custom action]({{< relref "/docs/custom-actions" >}}) as a deploy hook. They are the recommended way to package containerized deploy steps — schema migrations, smoke tests, out-of-band integrations — because they reuse the same runtime as `skaffold exec`, meaning a single action definition is runnable standalone or as part of a deploy and inherits the action's `executionMode`, `runArgs`, and deploy-parameter env injection.
161+
162+
### `before-deploy` and `after-deploy`
163+
164+
Example: _skaffold.yaml_ snippet
165+
```yaml
166+
customActions:
167+
- name: db-migrate
168+
containers:
169+
- name: migrator
170+
image: myorg/migrator:latest
171+
command: ["migrate", "up"]
172+
173+
deploy:
174+
kubectl:
175+
manifests:
176+
- deployment.yaml
177+
hooks:
178+
before:
179+
- action:
180+
name: db-migrate
181+
after:
182+
- action:
183+
name: smoke-test
184+
customActions:
185+
- name: smoke-test
186+
containers:
187+
- name: curl
188+
image: curlimages/curl
189+
command: ["curl", "-fsS", "http://my-service/healthz"]
190+
```
191+
192+
The referenced action must exist under `customActions`; unknown names are rejected at config-load time. Action hooks honour the declared `failFast` semantics of the action itself: a non-zero container exit aborts the hook, and the wrapping deploy is reported as failed.
193+
194+
Action hooks are currently supported on the kubectl, helm, and kpt deployers. The Cloud Run deployer retains its `host`-only hooks.
195+

examples/hooks-action/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# hooks-action
2+
3+
Demonstrates `deploy.hooks.before` / `after` referencing an existing
4+
custom action via the new `action:` hook form. Running:
5+
6+
```
7+
skaffold deploy --default-repo=gcr.io/my-project
8+
```
9+
10+
executes, in order:
11+
12+
1. `pre-deploy-check` custom action (runs in a busybox container)
13+
2. the kubectl deploy itself
14+
3. `post-deploy-smoke` custom action
15+
16+
Each referenced action must be declared under `customActions`; unknown
17+
names are rejected at config-load time. Action hooks reuse the same
18+
runtime as `skaffold exec`, so `skaffold exec pre-deploy-check` alone
19+
runs the hook standalone.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: hooks-action-demo
5+
spec:
6+
containers:
7+
- name: app
8+
image: busybox
9+
command: ["sh", "-c", "while true; do echo hello; sleep 10; done"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: skaffold/v4beta14
2+
kind: Config
3+
metadata:
4+
name: hooks-action-demo
5+
6+
customActions:
7+
- name: pre-deploy-check
8+
containers:
9+
- name: check
10+
image: busybox
11+
command: ["sh", "-c"]
12+
args: ["echo 'pre-deploy check ok'"]
13+
14+
- name: post-deploy-smoke
15+
containers:
16+
- name: smoke
17+
image: busybox
18+
command: ["sh", "-c"]
19+
args: ["echo 'post-deploy smoke test ok'"]
20+
21+
manifests:
22+
rawYaml:
23+
- k8s/deployment.yaml
24+
25+
deploy:
26+
kubectl:
27+
hooks:
28+
before:
29+
- action:
30+
name: pre-deploy-check
31+
after:
32+
- action:
33+
name: post-deploy-smoke
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: hooks-action-demo
5+
spec:
6+
containers:
7+
- name: app
8+
image: busybox
9+
command: ["sh", "-c", "while true; do echo hello; sleep 10; done"]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: skaffold/v4beta14
2+
kind: Config
3+
metadata:
4+
name: hooks-action-demo
5+
6+
customActions:
7+
- name: pre-deploy-check
8+
containers:
9+
- name: check
10+
image: busybox
11+
command: ["sh", "-c"]
12+
args: ["echo 'pre-deploy check ok'"]
13+
14+
- name: post-deploy-smoke
15+
containers:
16+
- name: smoke
17+
image: busybox
18+
command: ["sh", "-c"]
19+
args: ["echo 'post-deploy smoke test ok'"]
20+
21+
manifests:
22+
rawYaml:
23+
- k8s/deployment.yaml
24+
25+
deploy:
26+
kubectl:
27+
hooks:
28+
before:
29+
- action:
30+
name: pre-deploy-check
31+
after:
32+
- action:
33+
name: post-deploy-smoke

0 commit comments

Comments
 (0)