Skip to content

Commit

Permalink
fix: kustomize should support components
Browse files Browse the repository at this point in the history
  • Loading branch information
kallangerard committed Jan 8, 2025
1 parent bcd0180 commit 841ab37
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
19 changes: 16 additions & 3 deletions integration/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1438,19 +1438,31 @@ patchesStrategicMerge:
resources:
- ../../base
components:
- ../../components/label
`, "overlays/dev/deployment.yaml": `apiVersion: apps/v1
kind: Deployment
metadata:
name: skaffold-kustomize
labels:
env: dev # from-param: ${env2}
`, "components/label/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
labels:
- includeTemplates: true
includeSelectors: false
pairs:
region: 333a
`}, expectedOut: `
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: 111a
env: 222a
region: 333a
name: skaffold-kustomize-dev
spec:
selector:
Expand All @@ -1460,6 +1472,7 @@ spec:
metadata:
labels:
app: skaffold-kustomize
region: 333a
spec:
containers:
- image: skaffold-kustomize
Expand Down Expand Up @@ -2064,7 +2077,7 @@ metadata:
labels:
app1: after-change-1
app2: before-change-2
spec:
containers:
- image: us-central1-docker.pkg.dev/k8s-skaffold/testing/multi-config-module1:customtag
Expand Down Expand Up @@ -2332,7 +2345,7 @@ spec:
kind: Deployment
metadata:
name: my-nginx
annotations:
annotations:
color: orange
fruit: apple
spec:
Expand All @@ -2342,7 +2355,7 @@ spec:
app: nginx
template:
metadata:
annotations:
annotations:
color: orange
fruit: apple
labels:
Expand Down
24 changes: 24 additions & 0 deletions pkg/skaffold/render/renderer/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func (k Kustomize) mirror(kusDir string, fs TmpFS) error {
if err := k.mirrorConfigMapGenerators(kusDir, fs, kustomization.ConfigMapGenerator); err != nil {
return err
}
if err := k.mirrorComponents(kusDir, fs, kustomization.Components); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -405,6 +408,27 @@ func (k Kustomize) mirrorConfigMapGenerators(kusDir string, fs TmpFS, args []typ
return nil
}

func (k Kustomize) mirrorComponents(kusDir string, fs TmpFS, components []string) error {
for _, r := range components {
// note that r is relative to kustomization file not working dir here
rPath := filepath.Join(kusDir, r)
stat, err := os.Stat(rPath)
if err != nil {
return err
}
if stat.IsDir() {
if err := k.mirror(rPath, fs); err != nil {
return err
}
} else {
if err := k.mirrorFile(kusDir, fs, r); err != nil {
return err
}
}
}
return nil
}

func kustomizeDependencies(workdir string, paths []string) ([]string, error) {
deps := stringset.New()
for _, kustomizePath := range paths {
Expand Down

0 comments on commit 841ab37

Please sign in to comment.