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

fix: remove global helm flags from flags sent to skaffold filter #9212

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions integration/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ spec:
testutil.CheckError(t, false, err)
testutil.CheckDeepEqual(t, expectedOutput, string(fileContent))
}

func TestHelmDeployWithGlobalFlags(t *testing.T) {
MarkIntegrationTest(t, CanRunWithoutGcp)
ns, _ := SetupNamespace(t)
// To fix #1823, we make use of env variable templating for release name
env := []string{fmt.Sprintf("TEST_NS=%s", ns.Name)}
skaffold.Deploy("--images", "us-central1-docker.pkg.dev/k8s-skaffold/testing/skaffold-helm", "-p", "helm-with-global-flags").InDir("testdata/helm").InNs(ns.Name).WithEnv(env).RunOrFail(t)
skaffold.Delete().InDir("testdata/helm").InNs(ns.Name).WithEnv(env).RunOrFail(t)
}
79 changes: 79 additions & 0 deletions integration/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,85 @@ spec:
containers:
- image: skaffold-helm:latest
name: skaffold-helm
`,
}, {
description: "With Helm global flags",
dir: "testdata/helm-render",
args: []string{"-p", "helm-render-with-global-flags"},
withoutBuildJSON: true,
expectedOut: `apiVersion: v1
kind: Service
metadata:
labels:
app: skaffold-helm
chart: skaffold-helm-0.1.0
heritage: Helm
release: skaffold-helm
skaffold.dev/run-id: phony-run-id
name: skaffold-helm-skaffold-helm
spec:
ports:
- name: nginx
port: 80
protocol: TCP
targetPort: 80
selector:
app: skaffold-helm
release: skaffold-helm
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: skaffold-helm
chart: skaffold-helm-0.1.0
heritage: Helm
release: skaffold-helm
skaffold.dev/run-id: phony-run-id
name: skaffold-helm
spec:
replicas: 1
selector:
matchLabels:
app: skaffold-helm
release: skaffold-helm
template:
metadata:
labels:
app: skaffold-helm
release: skaffold-helm
skaffold.dev/run-id: phony-run-id
spec:
containers:
- image: us-central1-docker.pkg.dev/k8s-skaffold/testing/skaffold-helm:sha256-nonsenselettersandnumbers
imagePullPolicy: always
name: skaffold-helm
ports:
- containerPort: 80
resources: {}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations: null
labels:
app: skaffold-helm
chart: skaffold-helm-0.1.0
heritage: Helm
release: skaffold-helm
name: skaffold-helm-skaffold-helm
spec:
rules:
- http:
paths:
- backend:
service:
name: skaffold-helm-skaffold-helm
port:
number: 80
path: /
pathType: ImplementationSpecific
`,
},
}
Expand Down
11 changes: 11 additions & 0 deletions integration/testdata/helm-render/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ profiles:
manifests:
helm:
releases:
- name: skaffold-helm
chartPath: skaffold-helm
setValues:
pullPolicy: always
- name: helm-render-with-global-flags
manifests:
helm:
flags:
global:
- "--debug"
releases:
- name: skaffold-helm
chartPath: skaffold-helm
setValues:
Expand Down
12 changes: 11 additions & 1 deletion integration/testdata/helm/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ profiles:
chartPath: skaffold-helm
flags:
install:
- "--post-renderer=./change_replicas.py"
- "--post-renderer=./change_replicas.py"
- name: helm-with-global-flags
deploy:
helm:
flags:
global:
- "--debug"
releases:
# seed test namespace in the release name.
- name: skaffold-helm-{{.TEST_NS}}
chartPath: skaffold-helm
1 change: 0 additions & 1 deletion pkg/skaffold/helm/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func generateSkaffoldFilter(h Client, buildsFile string, flags []string) []strin
if len(buildsFile) > 0 {
args = append(args, "--build-artifacts", buildsFile)
}
args = append(args, h.GlobalFlags()...)

if h.KubeConfig() != "" {
args = append(args, "--kubeconfig", h.KubeConfig())
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/helm/bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestGenerateSkaffoldFilter(t *testing.T) {
enableDebug bool
buildFile string
result []string
globalFlags []string
}{
{
description: "empty buildfile is skipped",
Expand All @@ -105,6 +106,11 @@ func TestGenerateSkaffoldFilter(t *testing.T) {
enableDebug: true,
result: []string{"filter", "--kube-context", "kubecontext", "--debugging", "--kubeconfig", "kubeconfig"},
},
{
description: "helm global flags are not included in filter flags",
result: []string{"filter", "--kube-context", "kubecontext", "--kubeconfig", "kubeconfig"},
globalFlags: []string{"--debug"},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
Expand All @@ -115,6 +121,7 @@ func TestGenerateSkaffoldFilter(t *testing.T) {
kubeContext: "kubecontext",
kubeConfig: "kubeconfig",
manifestsOverrides: map[string]string{},
globalFlags: test.globalFlags,
}

result := generateSkaffoldFilter(h, test.buildFile, []string{})
Expand Down
Loading