Skip to content

Commit

Permalink
Switch namespace and patch transformers to kyaml.
Browse files Browse the repository at this point in the history
  • Loading branch information
monopole committed Jul 4, 2020
1 parent 42d1f7b commit d3a7335
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 81 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -15,7 +15,7 @@ verify-kustomize: \
lint-kustomize \
test-unit-kustomize-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-3.6.1
test-examples-kustomize-against-3.7.0

# The following target referenced by a file in
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
Expand All @@ -24,7 +24,7 @@ prow-presubmit-check: \
lint-kustomize \
test-unit-kustomize-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-3.6.1 \
test-examples-kustomize-against-3.7.0 \
test-unit-cmd-all \
test-go-mod

Expand Down Expand Up @@ -233,10 +233,10 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh HEAD

.PHONY:
test-examples-kustomize-against-3.6.1: $(MYGOBIN)/mdrip
test-examples-kustomize-against-3.7.0: $(MYGOBIN)/mdrip
( \
set -e; \
tag=v3.6.1; \
tag=v3.7.0; \
/bin/rm -f $(MYGOBIN)/kustomize; \
echo "Installing kustomize $$tag."; \
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
Expand Down
6 changes: 6 additions & 0 deletions api/builtins/NamespaceTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/builtins/PatchJson6902Transformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions api/builtins/PatchStrategicMergeTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/builtins/PatchTransformer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions api/filters/patchstrategicmerge/patchstrategicmerge.go
@@ -1,3 +1,6 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package patchstrategicmerge

import (
Expand All @@ -13,9 +16,13 @@ type Filter struct {
var _ kio.Filter = Filter{}

func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(pf.run)).Filter(nodes)
}

func (pf Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
return merge2.Merge(pf.Patch, node)
var result []*yaml.RNode
for i := range nodes {
r, err := merge2.Merge(pf.Patch, nodes[i])
if err != nil {
return nil, err
}
result = append(result, r)
}
return result, nil
}
4 changes: 2 additions & 2 deletions api/krusty/baseandoverlaymedium_test.go
Expand Up @@ -225,13 +225,13 @@ spec:
spec:
containers:
- env:
- name: foo
value: bar
- name: FOO
valueFrom:
configMapKeyRef:
key: somekey
name: test-infra-app-env-ffmd9b969m
- name: foo
value: bar
image: nginx:1.8.0
name: nginx
ports:
Expand Down
12 changes: 10 additions & 2 deletions api/krusty/customconfig_test.go
Expand Up @@ -59,6 +59,7 @@ spec:
location: SW
`)
th.WriteF("/app/base/animalPark.yaml", `
apiVersion: foo
kind: AnimalPark
metadata:
name: sandiego
Expand Down Expand Up @@ -93,6 +94,7 @@ varReference:
`)
m := th.Run("/app/base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
kind: AnimalPark
metadata:
labels:
Expand Down Expand Up @@ -161,6 +163,7 @@ varReference:
`)
m := th.Run("/app/base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
kind: AnimalPark
metadata:
labels:
Expand Down Expand Up @@ -212,14 +215,17 @@ func TestFixedBug605_BaseCustomizationAvailableInOverlay(t *testing.T) {
nameReference:
- kind: Gorilla
fieldSpecs:
- kind: AnimalPark
- apiVersion: foo
kind: AnimalPark
path: spec/gorillaRef/name
- kind: Giraffe
fieldSpecs:
- kind: AnimalPark
- apiVersion: foo
kind: AnimalPark
path: spec/giraffeRef/name
varReference:
- path: spec/food
apiVersion: foo
kind: AnimalPark
`)
th.WriteK("/app/overlay", `
Expand All @@ -242,6 +248,7 @@ spec:
`)
// The following replaces the gorillaRef in the AnimalPark.
th.WriteF("/app/overlay/animalPark.yaml", `
apiVersion: foo
kind: AnimalPark
metadata:
name: sandiego
Expand All @@ -251,6 +258,7 @@ spec:
`)
m := th.Run("/app/overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
kind: AnimalPark
metadata:
labels:
Expand Down
30 changes: 10 additions & 20 deletions api/krusty/extendedpatch_test.go
Expand Up @@ -156,8 +156,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -233,8 +232,7 @@ spec:
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
- emptyDir: {}
name: nginx-persistent-storage
- name: nginx-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand All @@ -260,8 +258,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -335,8 +332,7 @@ spec:
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
- emptyDir: {}
name: nginx-persistent-storage
- name: nginx-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -463,8 +459,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -564,8 +559,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -667,8 +661,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -769,8 +762,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -965,8 +957,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -1180,8 +1171,7 @@ spec:
- mountPath: /tmp/ps
name: busybox-persistent-storage
volumes:
- emptyDir: {}
name: busybox-persistent-storage
- name: busybox-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down
10 changes: 3 additions & 7 deletions api/krusty/generatormergeandreplace_test.go
Expand Up @@ -150,8 +150,6 @@ spec:

func makeBaseWithGenerators(th kusttest_test.Harness) {
th.WriteK("/app", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: team-foo-
commonLabels:
app: mynginx
Expand Down Expand Up @@ -325,8 +323,6 @@ spec:
name: configmap-in-overlay
`)
th.WriteK("/overlay", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: staging-
commonLabels:
env: staging
Expand Down Expand Up @@ -389,12 +385,12 @@ spec:
- gcePersistentDisk:
pdName: nginx-persistent-storage
name: nginx-persistent-storage
- configMap:
name: staging-configmap-in-overlay-k7cbc75tg8
name: configmap-in-overlay
- configMap:
name: staging-team-foo-configmap-in-base-gh9d7t85gb
name: configmap-in-base
- configMap:
name: staging-configmap-in-overlay-k7cbc75tg8
name: configmap-in-overlay
---
apiVersion: v1
kind: Service
Expand Down
6 changes: 2 additions & 4 deletions api/krusty/inlinepatch_test.go
Expand Up @@ -79,8 +79,7 @@ spec:
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
- emptyDir: {}
name: nginx-persistent-storage
- name: nginx-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down Expand Up @@ -223,8 +222,7 @@ spec:
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
- emptyDir: {}
name: nginx-persistent-storage
- name: nginx-persistent-storage
- configMap:
name: configmap-in-base
name: configmap-in-base
Expand Down

0 comments on commit d3a7335

Please sign in to comment.