Skip to content

Commit

Permalink
fix: apply-setter and transformer should ignore non-k8s-resource for …
Browse files Browse the repository at this point in the history
…kustomize paramterization (#9240)

* fix: apply-setter and tranformer should ignore non-k8s-resource for kustomize paramterization

* fix: upgrade kustomize version in ci
  • Loading branch information
ericzzzzzzz authored Jan 8, 2024
1 parent eb61abb commit ccb8c6e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
kustomize_version: [3.5.4]
kustomize_version: [5.0.3]
ko_version: [0.4.0]
kompose_version: [1.21.0]
kpt_version: [1.0.0-beta.24]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/performance-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
kustomize_version: [3.5.4]
kustomize_version: [5.0.3]
ko_version: [0.4.0]
kompose_version: [1.21.0]
gcloud_sdk_version: [410.0.0]
Expand Down
68 changes: 68 additions & 0 deletions integration/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,74 @@ spec:
containers:
- image: skaffold-kustomize
name: skaffold-kustomize
`,
},
{
description: "kustomize parameterization success with patches",
args: []string{"--offline", "--set", "app1=111a"},
config: `apiVersion: skaffold/v4beta2
kind: Config
metadata:
name: getting-started-kustomize
manifests:
kustomize:
paths:
- base
`, input: map[string]string{"base/kustomization.yaml": `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- path: patch.yaml
target:
group: apps
version: v1
kind: Deployment
name: skaffold-kustomize
resources:
- deployment.yaml
`, "base/deployment.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: skaffold-kustomize
labels:
app: skaffold-kustomize # from-param: ${app1}
spec:
selector:
matchLabels:
app: skaffold-kustomize
template:
metadata:
labels:
app: skaffold-kustomize
spec:
containers:
- name: skaffold-kustomize
image: skaffold-kustomize
`, "base/patch.yaml": `
- op: add
path: /metadata/annotations/example.com
value: dummy
`}, expectedOut: `
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: 111a
name: skaffold-kustomize
annotations:
example.com: dummy
spec:
selector:
matchLabels:
app: skaffold-kustomize
template:
metadata:
labels:
app: skaffold-kustomize
spec:
containers:
- image: skaffold-kustomize
name: skaffold-kustomize
`,
},
{description: "test set transformer values with value file",
Expand Down
17 changes: 10 additions & 7 deletions pkg/skaffold/render/renderer/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
sErrors "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/errors"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubectl"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes/manifest"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/render"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/render/applysetters"
Expand Down Expand Up @@ -312,14 +313,16 @@ func (k Kustomize) mirrorFile(kusDir string, fs TmpFS, path string) error {
return err
}

err = k.transformer.TransformPath(fsPath)
if err != nil {
return err
}
if kubernetes.IsKubernetesManifest(fsPath) {
err = k.transformer.TransformPath(fsPath)
if err != nil {
return err
}

err = k.applySetters.ApplyPath(fsPath)
if err != nil {
return fmt.Errorf("failed to apply setter to file %s, err: %v", pFile, err)
err = k.applySetters.ApplyPath(fsPath)
if err != nil {
return fmt.Errorf("failed to apply setter to file %s, err: %v", pFile, err)
}
}
return nil
}
Expand Down

0 comments on commit ccb8c6e

Please sign in to comment.