Skip to content

Commit 00ae5e6

Browse files
authored
fix: cleanup not called when using helm deployer alone (#8040)
* fix: cleanup not called when using helm deployer alone * chore: example schema version check
1 parent dfd6015 commit 00ae5e6

File tree

20 files changed

+224
-10
lines changed

20 files changed

+224
-10
lines changed

cmd/skaffold/app/cmd/dev.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ func runDev(ctx context.Context, out io.Writer) error {
7171
err := r.Dev(ctx, out, artifacts)
7272
manifestListByConfig := r.DeployManifests()
7373

74-
if manifestListByConfig.String() != "" {
75-
cleanup = func() {
76-
if err := r.Cleanup(context.Background(), out, false, manifestListByConfig); err != nil {
77-
log.Entry(ctx).Warn("deployer cleanup:", err)
78-
}
74+
cleanup = func() {
75+
if err := r.Cleanup(context.Background(), out, false, manifestListByConfig); err != nil {
76+
log.Entry(ctx).Warn("deployer cleanup:", err)
7977
}
8078
}
8179

cmd/skaffold/app/cmd/dev_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ func TestDoDev(t *testing.T) {
8383
expectedCalls: []string{"Dev", "DeployManifests", "HasBuilt", "Cleanup", "Prune"},
8484
},
8585
{
86-
description: "hasn't deployed",
86+
description: "cleanup always gets called even without deployments",
8787
hasBuilt: true,
8888
deployedManifests: manifest.ManifestList{},
89-
expectedCalls: []string{"Dev", "DeployManifests", "HasBuilt", "Prune"},
89+
expectedCalls: []string{"Dev", "DeployManifests", "HasBuilt", "Cleanup", "Prune"},
9090
},
9191
{
9292
description: "hasn't built",
9393
hasBuilt: false,
9494
deployedManifests: manifest.ManifestList{},
95-
expectedCalls: []string{"Dev", "DeployManifests", "HasBuilt"},
95+
expectedCalls: []string{"Dev", "DeployManifests", "HasBuilt", "Cleanup"},
9696
},
9797
}
9898

examples/helm-deployment/skaffold.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Config
33
build:
44
artifacts:
55
- image: skaffold-helm
6-
manifests:
6+
deploy:
77
helm:
88
releases:
99
- name: skaffold-helm

examples/helm-render/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.18 as builder
2+
WORKDIR /code
3+
COPY main.go .
4+
COPY go.mod .
5+
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
6+
ARG SKAFFOLD_GO_GCFLAGS
7+
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -trimpath -o /app main.go
8+
9+
FROM alpine:3.10
10+
# Define GOTRACEBACK to mark this container as using the Go language runtime
11+
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
12+
ENV GOTRACEBACK=single
13+
CMD ["./app"]
14+
COPY --from=builder /app .

examples/helm-render/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### Example: deploy multiple releases with Helm
2+
3+
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://github.com/GoogleContainerTools/skaffold&cloudshell_open_in_editor=README.md&cloudshell_workspace=examples/helm-deployment)
4+
5+
You can deploy multiple releases with skaffold, each will need a chartPath, a values file, and namespace.
6+
Skaffold can inject intermediate build tags in the the values map in the skaffold.yaml.
7+
8+
Let's walk through the skaffold yaml:
9+
10+
We'll be building an image called `skaffold-helm`, and it's a dockerfile, so we'll add it to the artifacts.
11+
12+
```yaml
13+
build:
14+
artifacts:
15+
- image: skaffold-helm
16+
```
17+
18+
Now, we want to deploy this image with helm.
19+
We add a new release in the helm part of the deploy stanza.
20+
21+
```yaml
22+
deploy:
23+
helm:
24+
releases:
25+
- name: skaffold-helm
26+
chartPath: charts
27+
# namespace: skaffold
28+
setValues:
29+
image: skaffold-helm
30+
valuesFiles:
31+
- values.yaml
32+
```
33+
34+
This part tells Skaffold to set the `image` parameter of the values file to the built `skaffold-helm` image and tag.
35+
36+
```yaml
37+
setValues:
38+
image: skaffold-helm
39+
```
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
description: Skaffold example with Helm
3+
name: skaffold-helm
4+
version: 0.1.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Chart.Name }}
5+
labels:
6+
app: {{ .Chart.Name }}
7+
spec:
8+
selector:
9+
matchLabels:
10+
app: {{ .Chart.Name }}
11+
replicas: {{ .Values.replicaCount }}
12+
template:
13+
metadata:
14+
labels:
15+
app: {{ .Chart.Name }}
16+
spec:
17+
containers:
18+
- name: {{ .Chart.Name }}
19+
image: {{ .Values.image }}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Default values for skaffold-helm.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
replicaCount: 2
5+
image: skaffold-helm:latest

examples/helm-render/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/GoogleContainerTools/skaffold/examples/helm-deployment
2+
3+
go 1.18

examples/helm-render/main.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func main() {
9+
for counter := 0; ; counter++ {
10+
fmt.Println("Hello world!", counter)
11+
12+
time.Sleep(time.Second * 1)
13+
}
14+
}

examples/helm-render/skaffold.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: skaffold/v3
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: skaffold-helm
6+
manifests:
7+
helm:
8+
releases:
9+
- name: skaffold-helm
10+
chartPath: charts

integration/examples/helm-deployment/skaffold.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Config
33
build:
44
artifacts:
55
- image: skaffold-helm
6-
manifests:
6+
deploy:
77
helm:
88
releases:
99
- name: skaffold-helm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.18 as builder
2+
WORKDIR /code
3+
COPY main.go .
4+
COPY go.mod .
5+
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
6+
ARG SKAFFOLD_GO_GCFLAGS
7+
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -trimpath -o /app main.go
8+
9+
FROM alpine:3.10
10+
# Define GOTRACEBACK to mark this container as using the Go language runtime
11+
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
12+
ENV GOTRACEBACK=single
13+
CMD ["./app"]
14+
COPY --from=builder /app .
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### Example: deploy multiple releases with Helm
2+
3+
[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://github.com/GoogleContainerTools/skaffold&cloudshell_open_in_editor=README.md&cloudshell_workspace=examples/helm-deployment)
4+
5+
You can deploy multiple releases with skaffold, each will need a chartPath, a values file, and namespace.
6+
Skaffold can inject intermediate build tags in the the values map in the skaffold.yaml.
7+
8+
Let's walk through the skaffold yaml:
9+
10+
We'll be building an image called `skaffold-helm`, and it's a dockerfile, so we'll add it to the artifacts.
11+
12+
```yaml
13+
build:
14+
artifacts:
15+
- image: skaffold-helm
16+
```
17+
18+
Now, we want to deploy this image with helm.
19+
We add a new release in the helm part of the deploy stanza.
20+
21+
```yaml
22+
deploy:
23+
helm:
24+
releases:
25+
- name: skaffold-helm
26+
chartPath: charts
27+
# namespace: skaffold
28+
setValues:
29+
image: skaffold-helm
30+
valuesFiles:
31+
- values.yaml
32+
```
33+
34+
This part tells Skaffold to set the `image` parameter of the values file to the built `skaffold-helm` image and tag.
35+
36+
```yaml
37+
setValues:
38+
image: skaffold-helm
39+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
description: Skaffold example with Helm
3+
name: skaffold-helm
4+
version: 0.1.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Chart.Name }}
5+
labels:
6+
app: {{ .Chart.Name }}
7+
spec:
8+
selector:
9+
matchLabels:
10+
app: {{ .Chart.Name }}
11+
replicas: {{ .Values.replicaCount }}
12+
template:
13+
metadata:
14+
labels:
15+
app: {{ .Chart.Name }}
16+
spec:
17+
containers:
18+
- name: {{ .Chart.Name }}
19+
image: {{ .Values.image }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Default values for skaffold-helm.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
replicaCount: 2
5+
image: skaffold-helm:latest
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/GoogleContainerTools/skaffold/examples/helm-deployment
2+
3+
go 1.18
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func main() {
9+
for counter := 0; ; counter++ {
10+
fmt.Println("Hello world!", counter)
11+
12+
time.Sleep(time.Second * 1)
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: skaffold/v4beta1
2+
kind: Config
3+
build:
4+
artifacts:
5+
- image: skaffold-helm
6+
manifests:
7+
helm:
8+
releases:
9+
- name: skaffold-helm
10+
chartPath: charts

0 commit comments

Comments
 (0)