Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parameterization #8365

Merged
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
537112e
chore: rebase and resolve confilicts
ericzzzzzzz Jan 19, 2023
68328fe
..
ericzzzzzzz Jan 19, 2023
897bf4e
..
ericzzzzzzz Jan 19, 2023
f1ebd74
chore: fix flag
ericzzzzzzz Jan 23, 2023
e87a6d3
base impl for mirroring
ericzzzzzzz Jan 25, 2023
533c210
...
ericzzzzzzz Jan 25, 2023
08c189b
...
ericzzzzzzz Jan 25, 2023
b268e6e
get set working
ericzzzzzzz Jan 26, 2023
76699e0
support kubectl parameterization
ericzzzzzzz Jan 26, 2023
b22ba24
parameterization for helm
ericzzzzzzz Jan 26, 2023
e800e1c
chore: initialize kube render when remote manifest is set
ericzzzzzzz Jan 26, 2023
c49eb54
fix directory issue
ericzzzzzzz Jan 26, 2023
1eacc39
fix mirror path issue
ericzzzzzzz Jan 26, 2023
42a564f
..
ericzzzzzzz Jan 27, 2023
750724d
...
ericzzzzzzz Jan 29, 2023
3c27f1e
get kpt working
ericzzzzzzz Jan 29, 2023
1c2bb62
ref
ericzzzzzzz Jan 30, 2023
295c87b
refactor kustomize
ericzzzzzzz Jan 31, 2023
641b0af
...
ericzzzzzzz Jan 31, 2023
e16cca0
refoctor
ericzzzzzzz Feb 1, 2023
19abb6c
use kustomization struct from the lib
ericzzzzzzz Feb 2, 2023
d39f184
..
ericzzzzzzz Feb 2, 2023
4927697
chore: fix linters
ericzzzzzzz Feb 2, 2023
0999854
chore: fix linter issues and one integration tests
ericzzzzzzz Feb 2, 2023
ded3bbb
linters
ericzzzzzzz Feb 3, 2023
4176811
fix tests
ericzzzzzzz Feb 3, 2023
072be1a
fix tests
ericzzzzzzz Feb 3, 2023
a7689b4
boilerplate
ericzzzzzzz Feb 3, 2023
004f54d
add manual for --set
ericzzzzzzz Feb 3, 2023
2721c1b
add kpt-render example in integration
ericzzzzzzz Feb 3, 2023
7491924
delete kpt-render example
ericzzzzzzz Feb 3, 2023
4edd032
chore: add test
ericzzzzzzz Feb 6, 2023
dace22c
chore: nit
ericzzzzzzz Feb 6, 2023
43ac3a7
linters
ericzzzzzzz Feb 6, 2023
5c86c8e
linters
ericzzzzzzz Feb 6, 2023
99524d1
chore: upgrade kpt version
ericzzzzzzz Feb 6, 2023
5abda44
test
ericzzzzzzz Feb 6, 2023
0d80efb
linters
ericzzzzzzz Feb 6, 2023
7d5803e
chore: revert example change
ericzzzzzzz Feb 6, 2023
386fd54
chore: remove unnecessary tests
ericzzzzzzz Feb 8, 2023
ced8397
chore: nit
ericzzzzzzz Feb 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add test
  • Loading branch information
ericzzzzzzz committed Feb 6, 2023
commit 4edd032abd6cf346a7f5a02d9b8b1689878e4801
1 change: 0 additions & 1 deletion examples/getting-started-kustomize/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ metadata:
name: skaffold-kustomize
labels:
app: skaffold-kustomize # kpt-set: ${app1}
namespace: default # kpt-set: ${nameb}
spec:
selector:
matchLabels:
Original file line number Diff line number Diff line change
@@ -3,5 +3,4 @@ kind: Deployment
metadata:
name: skaffold-kustomize
labels:
env: dev
namespace: hello-no # kpt-set: ${nameb}
env: dev # kpt-set: ${env2}
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@ kind: Deployment
metadata:
name: skaffold-kustomize
labels:
env: staging # kpt-set: ${app2}
env: staging
8 changes: 1 addition & 7 deletions examples/kustomize/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -7,10 +7,4 @@ manifests:
transform:
- name: set-annotations
configMap:
- "author:fake-author"
# - name: create-setters
# configMap:
# - "app:guestbook"
# - name: apply-setters
# configMap:
# - "app:guestbook-fake-author"
- "author:fake-author"
291 changes: 291 additions & 0 deletions integration/render_test.go
Original file line number Diff line number Diff line change
@@ -390,6 +390,34 @@ spec:
containers:
- image: skaffold-helm:latest
name: skaffold-helm
`,
}, {
description: "Template replicaCount with --set flag",
dir: "testdata/helm-render-simple",
args: []string{"--set", "replicaCount=3"},
withoutBuildJSON: true,
expectedOut: `apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: skaffold-helm
skaffold.dev/run-id: phony-run-id
name: skaffold-helm
namespace: helm-namespace
spec:
replicas: 3
selector:
matchLabels:
app: skaffold-helm
template:
metadata:
labels:
app: skaffold-helm
skaffold.dev/run-id: phony-run-id
spec:
containers:
- image: skaffold-helm:latest
name: skaffold-helm
`,
},
}
@@ -873,6 +901,269 @@ spec:
}
}

func TestRenderWithTransformer(t *testing.T) {
tests := []struct {
description string
args []string
config string
input map[string]string // file path => content
expectedOut string
}{
{
description: "kubectl set manifest label with apply-setters",
args: []string{"--offline=true"},
config: `apiVersion: skaffold/v4beta2
kind: Config
manifests:
rawYaml:
- k8s-pod.yaml
transform:
- name: apply-setters
configMap:
- "app1:from-apply-setters-1"
`,
input: map[string]string{
"k8s-pod.yaml": `apiVersion: v1
kind: Pod
metadata:
name: getting-started
labels:
a: hhhh # kpt-set: ${app1}
spec:
containers:
- name: getting-started
image: skaffold-example`,
}, expectedOut: `apiVersion: v1
kind: Pod
metadata:
name: getting-started
labels:
a: from-apply-setters-1
spec:
containers:
- name: getting-started
image: skaffold-example
`,
},
{
description: "kubectl set manifest label with --set flag overrides transform in manifest",
args: []string{"--offline=true", "--set", "app1=from-command-line"},
config: `apiVersion: skaffold/v4beta2
kind: Config
manifests:
rawYaml:
- k8s-pod.yaml
transform:
- name: apply-setters
configMap:
- "app1:from-apply-setters-1"
`,
input: map[string]string{
"k8s-pod.yaml": `apiVersion: v1
kind: Pod
metadata:
name: getting-started
labels:
a: hhhh # kpt-set: ${app1}
spec:
containers:
- name: getting-started
image: skaffold-example`,
}, expectedOut: `apiVersion: v1
kind: Pod
metadata:
name: getting-started
labels:
a: from-command-line
spec:
containers:
- name: getting-started
image: skaffold-example
`,
},
{description: "kustomize set annotation with set-annotations transformer",
args: []string{"--offline=true"},
config: `apiVersion: skaffold/v4beta2
kind: Config
manifests:
kustomize:
paths:
- .
transform:
- name: set-annotations
configMap:
- "author:fake-author"`,
input: map[string]string{"kustomization.yaml": `resources:
- deployment.yaml
patchesStrategicMerge:
- patch.yaml
`, "deployment.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: kustomize-test
labels:
app: kustomize-test
spec:
replicas: 1
selector:
matchLabels:
app: kustomize-test
template:
metadata:
labels:
app: kustomize-test
spec:
containers:
- name: kustomize-test
image: not/a/valid/image
`, "patch.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: kustomize-test
spec:
template:
spec:
containers:
- name: kustomize-test
image: index.docker.io/library/busybox
command:
- sleep
- "3600"
`},
expectedOut: `apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
author: fake-author
labels:
app: kustomize-test
name: kustomize-test
spec:
replicas: 1
selector:
matchLabels:
app: kustomize-test
template:
metadata:
annotations:
author: fake-author
labels:
app: kustomize-test
spec:
containers:
- command:
- sleep
- "3600"
image: index.docker.io/library/busybox
name: kustomize-test
`},
{
description: "kustomize/overlay parameterization with --set flag",
args: []string{"--offline", "--set", "env2=222", "--set", "app1=111"},
config: `apiVersion: skaffold/v4beta2
kind: Config
metadata:
name: getting-started-kustomize
manifests:
kustomize:
paths:
- overlays/dev
`, input: map[string]string{
"base/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yaml
`, "base/deployment.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: skaffold-kustomize
labels:
app: skaffold-kustomize # kpt-set: ${app1}
spec:
selector:
matchLabels:
app: skaffold-kustomize
template:
metadata:
labels:
app: skaffold-kustomize
spec:
containers:
- name: skaffold-kustomize
image: skaffold-kustomize
`, "overlays/dev/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

# namespace: dev
nameSuffix: -dev

patchesStrategicMerge:
- deployment.yaml

resources:
- ../../base
`, "overlays/dev/deployment.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: skaffold-kustomize
labels:
env: dev # kpt-set: ${env2}
`}, expectedOut: `
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: 111
env: "222"
name: skaffold-kustomize-dev
spec:
selector:
matchLabels:
app: skaffold-kustomize
template:
metadata:
labels:
app: skaffold-kustomize
spec:
containers:
- image: skaffold-kustomize
name: skaffold-kustomize
`,
},
}

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
MarkIntegrationTest(t.T, CanRunWithoutGcp)
tmpDir := t.NewTempDir()
tmpDir.Write("skaffold.yaml", test.config)

for filePath, content := range test.input {
fmt.Println(filePath)

tmpDir.Write(filePath, content)
}

tmpDir.Chdir()
output := skaffold.Render(test.args...).RunOrFailOutput(t.T)
var out map[string]any
var ex map[string]any
err := yaml.Unmarshal(output, &out)
if err != nil {
return
}
err = yaml.Unmarshal([]byte(test.expectedOut), &ex)
if err != nil {
return
}

t.CheckDeepEqual(ex, out)
})
}

}

func TestRenderWithTagFlag(t *testing.T) {
MarkIntegrationTest(t, CanRunWithoutGcp)

4 changes: 4 additions & 0 deletions integration/testdata/helm-render-simple/charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: Skaffold example with Helm
name: skaffold-helm
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Chart.Name }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ .Chart.Name }}
spec:
selector:
matchLabels:
app: {{ .Chart.Name }}
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: {{ .Chart.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.image }}
5 changes: 5 additions & 0 deletions integration/testdata/helm-render-simple/charts/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default values for skaffold-helm.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 2
image: skaffold-helm:latest
8 changes: 8 additions & 0 deletions integration/testdata/helm-render-simple/skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: skaffold/v4beta2
kind: Config
manifests:
helm:
releases:
- name: skaffold-helm
chartPath: charts
namespace: helm-namespace
14 changes: 14 additions & 0 deletions integration/testdata/transform/kubectl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.18 as builder
WORKDIR /code
COPY main.go .
COPY go.mod .
# `skaffold debug` sets SKAFFOLD_GO_GCFLAGS to disable compiler optimizations
ARG SKAFFOLD_GO_GCFLAGS
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -trimpath -o /app main.go

FROM alpine:3
# Define GOTRACEBACK to mark this container as using the Go language runtime
# for `skaffold debug` (https://skaffold.dev/docs/workflows/debug/).
ENV GOTRACEBACK=single
CMD ["./app"]
COPY --from=builder /app .
Loading