Compare commits

...

8 Commits

Author SHA1 Message Date
Morten Torkildsen
0b756877e1 Merge pull request #2698 from mortent/PrepCmdConfigForRelease
Prep cmd/config for release
2020-07-06 21:03:40 -07:00
Morten Torkildsen
0f4b5e6787 Prep cmd/config for release 2020-07-06 20:50:18 -07:00
Kubernetes Prow Robot
855ce1a8db Merge pull request #2693 from t0rr3sp3dr0/master
Update function annotation on docs
2020-07-05 18:06:50 -07:00
Jeff Regan
6a50372dd5 Merge pull request #2694 from monopole/switchToApiV0_5_0
Switch to kustomize/api v0.5.0
2020-07-04 21:22:19 -07:00
jregan
5a0228629f Switch kustomize to api/v0.5.0 2020-07-04 19:45:45 -07:00
Jeff Regan
def00220ce Merge pull request #2668 from monopole/doesItWork
Switch namespace and patch transformers to kyaml.
2020-07-04 17:11:56 -07:00
jregan
d3a7335bbc Switch namespace and patch transformers to kyaml. 2020-07-04 16:21:01 -07:00
Pedro Tôrres
94095a63ff Update function annotation on docs
Signed-off-by: Pedro Tôrres <t0rr3sp3dr0@gmail.com>
2020-07-04 18:19:28 -03:00
51 changed files with 309 additions and 172 deletions

View File

@@ -14,8 +14,8 @@ all: verify-kustomize
verify-kustomize: \
lint-kustomize \
test-unit-kustomize-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-3.6.1
test-examples-kustomize-against-HEAD
# 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
@@ -24,9 +24,9 @@ prow-presubmit-check: \
lint-kustomize \
test-unit-kustomize-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-3.6.1 \
test-unit-cmd-all \
test-go-mod
# test-examples-kustomize-against-3.7.0 \
.PHONY: verify-kustomize-e2e
verify-kustomize-e2e: test-examples-e2e-kustomize
@@ -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}; \

View File

@@ -5,6 +5,7 @@ package builtins
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/filters/namespace"
"sigs.k8s.io/kustomize/api/resid"
@@ -31,6 +32,11 @@ func (p *NamespaceTransformerPlugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {
p.Namespace = ""
p.FieldSpecs = nil
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
return yaml.Unmarshal(c, p)
}

View File

@@ -5,6 +5,7 @@ package builtins
import (
"fmt"
"strings"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
@@ -34,6 +35,11 @@ func (p *PatchJson6902TransformerPlugin) Config(
if err != nil {
return err
}
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
if p.Target.Name == "" {
return fmt.Errorf("must specify the target name")
}

View File

@@ -5,6 +5,7 @@ package builtins
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
"sigs.k8s.io/kustomize/api/resmap"
@@ -30,6 +31,11 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
if err != nil {
return err
}
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
if len(p.Paths) == 0 && p.Patches == "" {
return fmt.Errorf("empty file path and empty patch content")
}
@@ -75,17 +81,6 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
}
if !p.YAMLSupport {
err = target.Patch(patch.Copy())
if err != nil {
return err
}
// remove the resource from resmap
// when the patch is to $patch: delete that target
if len(target.Map()) == 0 {
err = m.Remove(target.CurId())
if err != nil {
return err
}
}
} else {
patchCopy := patch.DeepCopy()
patchCopy.SetName(target.GetName())
@@ -99,6 +94,19 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
Patch: node,
}, target)
}
if err != nil {
return err
}
if len(target.Map()) == 0 {
// This means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means
// the overall resmap must shrink by one.
err = m.Remove(target.CurId())
if err != nil {
return err
}
}
}
return nil
}

View File

@@ -34,6 +34,11 @@ func (p *PatchTransformerPlugin) Config(
if err != nil {
return err
}
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
p.Patch = strings.TrimSpace(p.Patch)
if p.Patch == "" && p.Path == "" {
return fmt.Errorf(

View File

@@ -1,3 +1,6 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package patchstrategicmerge
import (
@@ -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
}

View File

@@ -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:

View File

@@ -59,6 +59,7 @@ spec:
location: SW
`)
th.WriteF("/app/base/animalPark.yaml", `
apiVersion: foo
kind: AnimalPark
metadata:
name: sandiego
@@ -93,6 +94,7 @@ varReference:
`)
m := th.Run("/app/base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
kind: AnimalPark
metadata:
labels:
@@ -161,6 +163,7 @@ varReference:
`)
m := th.Run("/app/base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
kind: AnimalPark
metadata:
labels:
@@ -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", `
@@ -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
@@ -251,6 +258,7 @@ spec:
`)
m := th.Run("/app/overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
kind: AnimalPark
metadata:
labels:

View File

@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

View File

@@ -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
@@ -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
@@ -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

View File

@@ -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
@@ -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

View File

@@ -146,12 +146,12 @@ spec:
- gcePersistentDisk:
pdName: nginx-persistent-storage
name: nginx-persistent-storage
- configMap:
name: a-configmap-in-overlay-ffm9hf78mc
name: configmap-in-overlay
- configMap:
name: a-b-configmap-in-base-fm96mhk4dt
name: configmap-in-base
- configMap:
name: a-configmap-in-overlay-ffm9hf78mc
name: configmap-in-overlay
---
apiVersion: v1
kind: Service
@@ -190,8 +190,6 @@ metadata:
func makeCommonFileForMultiplePatchTest(th kusttest_test.Harness) {
th.WriteK("/app/base", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: team-foo-
commonLabels:
app: mynginx
@@ -249,8 +247,6 @@ spec:
app: nginx
`)
th.WriteK("/app/overlay/staging", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: staging-
commonLabels:
env: staging
@@ -355,12 +351,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-g7k6gt2889
name: configmap-in-base
- configMap:
name: staging-configmap-in-overlay-k7cbc75tg8
name: configmap-in-overlay
---
apiVersion: v1
kind: Service
@@ -544,8 +540,7 @@ spec:
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
- emptyDir: {}
name: nginx-persistent-storage
- name: nginx-persistent-storage
- configMap:
name: staging-team-foo-configmap-in-base-g7k6gt2889
name: configmap-in-base

View File

@@ -116,14 +116,14 @@ metadata:
name: my-instance
annotations:
config.kubernetes.io/local-config: "true"
config.k8s.io/function: |
config.kubernetes.io/function: |
container:
image: gcr.io/example-functions/nginx-template:v1.0.0
spec:
replicas: 5
```
- `annotations[config.k8s.io/function].container.image`: the image to use for this API
- `annotations[config.kubernetes.io/function].container.image`: the image to use for this API
- `annotations[config.kubernetes.io/local-config]`: mark this as not a Resource that should
be applied

View File

@@ -114,7 +114,7 @@ functionConfig:
name: staging
metadata:
annotations:
config.k8s.io/function: |
config.kubernetes.io/function: |
container:
image: gcr.io/example/foo:v1.0.0
spec:

View File

@@ -14,23 +14,6 @@ require (
k8s.io/cli-runtime v0.17.3
k8s.io/client-go v0.17.3
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd
sigs.k8s.io/cli-utils v0.12.0
// TODO: Fix this -- this should depend on v0.0.0 and be replaced (below),
// however the cli-runtime dependency causes `go mod` to set this as the
// dependency.
sigs.k8s.io/kustomize/kyaml v0.1.13 // Don't change this!
)
// TODO: Fix this -- we sould only depend on v0.0.0 and replace that one.
//
// This line is managed by the release script -- releasing/releasemodule.sh
// Pinning to a released version of kyaml will invalidate the e2e tests used to
// test kyaml changes as the e2e tests will run against the pinned version, not
// the HEAD.
//
// releasing/releasemodule.sh will remove this line and set the require version
// to the kyaml version specified in releasing/VERSIONS
replace (
sigs.k8s.io/kustomize/kyaml v0.0.0 => ../../kyaml
sigs.k8s.io/kustomize/kyaml v0.1.13 => ../../kyaml
sigs.k8s.io/cli-utils v0.16.0
sigs.k8s.io/kustomize/kyaml v0.4.0
)

View File

@@ -550,7 +550,6 @@ gopkg.in/yaml.v2 v2.0.0/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
@@ -617,14 +616,14 @@ modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I=
sigs.k8s.io/cli-utils v0.12.0 h1:+CvYwQAEtKvcx/NaUVF9rDKvY91VwJj+i7D2lWBMYc0=
sigs.k8s.io/cli-utils v0.12.0/go.mod h1:H35YA5iJIM7EVNgqDTjX2dgt4wE23zmnXOTSTlyD+PE=
sigs.k8s.io/cli-utils v0.16.0 h1:Wr32m1oxjIqc9G9l+igr13PeIM9LCyq8jQ8KjXKelvg=
sigs.k8s.io/cli-utils v0.16.0/go.mod h1:9Jqm9K2W6ShhCxsEuaz6HSRKKOXigPUx3ZfypGgxBLY=
sigs.k8s.io/controller-runtime v0.4.0 h1:wATM6/m+3w8lj8FXNaO6Fs/rq/vqoOjO1Q116Z9NPsg=
sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/kustomize/kyaml v0.1.4 h1:cDG2u7v6CTAZmWKzCjk0hKG7AIN+2mCHx2ifwPbvKrs=
sigs.k8s.io/kustomize/kyaml v0.1.4/go.mod h1:461i94nj0h0ylJ6w83jLkR4SqqVhn1iY6fjD0JSTQeE=
sigs.k8s.io/kustomize/kyaml v0.4.0 h1:jMQrJOJmiUz5Y018ki0mXWpEreEXjvad1NRfXTdi9vU=
sigs.k8s.io/kustomize/kyaml v0.4.0/go.mod h1:XJL84E6sOFeNrQ7CADiemc1B0EjIxHo3OhW4o1aJYNw=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/structured-merge-diff v0.0.0-20190817042607-6149e4549fca/go.mod h1:IIgPezJWb76P0hotTxzDbWsMYB8APh18qZnxkomBpxA=
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06 h1:zD2IemQ4LmOcAumeiyDWXKUI2SO0NYDe3H6QGvPOVgU=
@@ -633,4 +632,6 @@ sigs.k8s.io/testing_frameworks v0.1.2 h1:vK0+tvjF0BZ/RYFeZ1E6BYBwHJJXhjuZ3TdsEKH
sigs.k8s.io/testing_frameworks v0.1.2/go.mod h1:ToQrwSC3s8Xf/lADdZp3Mktcql9CG0UAmdJG9th5i0w=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
vbom.ml/util v0.0.0-20160121211510-db5cfe13f5cc/go.mod h1:so/NYdZXCz+E3ZpW0uAoCj6uzU2+8OWDFv/HxUSs7kI=

View File

@@ -175,13 +175,13 @@ are passed to the Function through the ` + "`" + `ResourceList.functionConfig` +
name: my-instance
annotations:
config.kubernetes.io/local-config: "true"
config.k8s.io/function: |
config.kubernetes.io/function: |
container:
image: gcr.io/example-functions/nginx-template:v1.0.0
spec:
replicas: 5
- ` + "`" + `annotations[config.k8s.io/function].container.image` + "`" + `: the image to use for this API
- ` + "`" + `annotations[config.kubernetes.io/function].container.image` + "`" + `: the image to use for this API
- ` + "`" + `annotations[config.kubernetes.io/local-config]` + "`" + `: mark this as not a Resource that should
be applied
@@ -343,7 +343,7 @@ An example using ` + "`" + `config.kubernetes.io/v1beta1/ResourceList` + "`" + `
name: staging
metadata:
annotations:
config.k8s.io/function: |
config.kubernetes.io/function: |
container:
image: gcr.io/example/foo:v1.0.0
spec:

View File

@@ -162,16 +162,16 @@ spec:
old-label: old-value
spec:
containers:
- args:
- proxy
- sidecar
image: docker.io/istio/proxyv2
name: istio-proxy
- args:
- one
- two
image: nginx
name: nginx
- args:
- proxy
- sidecar
image: docker.io/istio/proxyv2
name: istio-proxy
---
apiVersion: apps/v1
kind: Deployment
@@ -184,13 +184,13 @@ spec:
key: value
spec:
containers:
- image: busybox
name: busybox
- args:
- proxy
- sidecar
image: docker.io/istio/proxyv2
name: istio-proxy
- image: busybox
name: busybox
EOF
```

View File

@@ -7,7 +7,7 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
k8s.io/client-go v0.17.3
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/cmd/config v0.2.0
sigs.k8s.io/yaml v1.2.0
)

View File

@@ -750,8 +750,8 @@ sigs.k8s.io/controller-runtime v0.4.0 h1:wATM6/m+3w8lj8FXNaO6Fs/rq/vqoOjO1Q116Z9
sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/kustomize/api v0.4.2 h1:ETPJPgfpWYXxXZw8n4EzuoIzmb8vSEwNx4Lr4/E6hGs=
sigs.k8s.io/kustomize/api v0.4.2/go.mod h1:OND6MoJxF5BoS3IiAqDjPKdI7c+oTSaxuXKbljPbwNU=
sigs.k8s.io/kustomize/api v0.5.0 h1:LT/Yxm6J8M9BJoLxfYIwGWamvuGSPQl7ELQXdlOR/fY=
sigs.k8s.io/kustomize/api v0.5.0/go.mod h1:OND6MoJxF5BoS3IiAqDjPKdI7c+oTSaxuXKbljPbwNU=
sigs.k8s.io/kustomize/cmd/config v0.2.0 h1:VNAWKb1JLl7dFjMAD5MwdZpGjreN3qL63C8DKtsUYck=
sigs.k8s.io/kustomize/cmd/config v0.2.0/go.mod h1:oXzY7QJS6JlmWgusEjra2O3cW7GSIICXa59/3DvjBfE=
sigs.k8s.io/kustomize/kyaml v0.1.4/go.mod h1:461i94nj0h0ylJ6w83jLkR4SqqVhn1iY6fjD0JSTQeE=

View File

@@ -63,6 +63,34 @@ spec:
`,
},
{description: `strategic merge patch delete 4`,
source: `
apiVersion: apps/v1
metadata:
name: myDeploy
kind: Deployment
$patch: delete
`,
dest: `
apiVersion: apps/v1
metadata:
name: myDeploy
kind: Deployment
spec:
replica: 2
template:
metadata:
labels:
old-label: old-value
spec:
containers:
- name: nginx
image: nginx
`,
expected: `
`,
},
{description: `strategic merge patch replace 1`,
source: `
kind: Deployment

View File

@@ -3,9 +3,9 @@ module sigs.k8s.io/kustomize/plugin/builtin/annotationstransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/builtin/configmapgenerator
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/builtin/hashtransformer
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/builtin/imagetagtransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,9 +3,9 @@ module sigs.k8s.io/kustomize/plugin/builtin/labeltransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -4,7 +4,7 @@ go 1.14
require (
github.com/pkg/errors v0.8.1
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -6,6 +6,7 @@ package main
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/filters/namespace"
"sigs.k8s.io/kustomize/api/resid"
@@ -35,6 +36,11 @@ func (p *plugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {
p.Namespace = ""
p.FieldSpecs = nil
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
return yaml.Unmarshal(c, p)
}

View File

@@ -3,9 +3,9 @@ module sigs.k8s.io/kustomize/plugin/builtin/namespacetransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -6,6 +6,7 @@ package main
import (
"fmt"
"strings"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
@@ -38,6 +39,11 @@ func (p *plugin) Config(
if err != nil {
return err
}
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
if p.Target.Name == "" {
return fmt.Errorf("must specify the target name")
}

View File

@@ -5,9 +5,9 @@ go 1.14
require (
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/pkg/errors v0.8.1
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -6,6 +6,7 @@ package main
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
"sigs.k8s.io/kustomize/api/resmap"
@@ -34,6 +35,11 @@ func (p *plugin) Config(
if err != nil {
return err
}
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
if len(p.Paths) == 0 && p.Patches == "" {
return fmt.Errorf("empty file path and empty patch content")
}
@@ -79,17 +85,6 @@ func (p *plugin) Transform(m resmap.ResMap) error {
}
if !p.YAMLSupport {
err = target.Patch(patch.Copy())
if err != nil {
return err
}
// remove the resource from resmap
// when the patch is to $patch: delete that target
if len(target.Map()) == 0 {
err = m.Remove(target.CurId())
if err != nil {
return err
}
}
} else {
patchCopy := patch.DeepCopy()
patchCopy.SetName(target.GetName())
@@ -103,6 +98,19 @@ func (p *plugin) Transform(m resmap.ResMap) error {
Patch: node,
}, target)
}
if err != nil {
return err
}
if len(target.Map()) == 0 {
// This means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means
// the overall resmap must shrink by one.
err = m.Remove(target.CurId())
if err != nil {
return err
}
}
}
return nil
}

View File

@@ -1208,9 +1208,89 @@ func TestMultipleNamespaces(t *testing.T) {
}
}
// We don't run this for the kyaml implementation since we don't support
// the strategic merge patch directives (yet).
func TestPatchStrategicMergeTransformerPatchDelete(t *testing.T) {
func TestPatchStrategicMergeTransformerPatchDelete1(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchStrategicMergeTransformer")
defer th.Reset()
th.WriteF("patch.yaml", `
apiVersion: apps/v1
metadata:
name: myDeploy
kind: Deployment
spec:
replica: 2
template:
$patch: delete
metadata:
labels:
old-label: old-value
spec:
containers:
- name: nginx
image: nginx
`)
rm := th.LoadAndRunTransformer(`
apiVersion: builtin
kind: PatchStrategicMergeTransformer
metadata:
name: notImportantHere
paths:
- patch.yaml
`, target)
th.AssertActualEqualsExpected(rm, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeploy
spec:
replica: 2
`)
}
func TestPatchStrategicMergeTransformerPatchDelete2(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchStrategicMergeTransformer")
defer th.Reset()
th.WriteF("patch.yaml", `
apiVersion: apps/v1
metadata:
name: myDeploy
kind: Deployment
spec:
$patch: delete
replica: 2
template:
metadata:
labels:
old-label: old-value
spec:
containers:
- name: nginx
image: nginx
`)
rm := th.LoadAndRunTransformer(`
apiVersion: builtin
kind: PatchStrategicMergeTransformer
metadata:
name: notImportantHere
paths:
- patch.yaml
`, target)
th.AssertActualEqualsExpected(rm, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myDeploy
`)
}
func TestPatchStrategicMergeTransformerPatchDelete3(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepBuiltin("PatchStrategicMergeTransformer")
defer th.Reset()
@@ -1234,3 +1314,4 @@ paths:
th.AssertActualEqualsExpected(rm, ``)
}

View File

@@ -3,9 +3,9 @@ module sigs.k8s.io/kustomize/plugin/builtin/patchstrategicmergetransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -38,6 +38,11 @@ func (p *plugin) Config(
if err != nil {
return err
}
if !strings.Contains(string(c), "yamlSupport") {
// If not explicitly denied,
// activate kyaml-based transformation.
p.YAMLSupport = true
}
p.Patch = strings.TrimSpace(p.Patch)
if p.Patch == "" && p.Path == "" {
return fmt.Errorf(

View File

@@ -5,9 +5,9 @@ go 1.14
require (
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/pkg/errors v0.8.1
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/builtin/prefixsuffixtransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/builtin/replicacounttransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/builtin/secretgenerator
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -3,9 +3,9 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/valueaddtransformer
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/kustomize/kyaml v0.3.4
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/bashedconfigmap
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/chartinflator
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -4,8 +4,8 @@ go 1.14
require (
github.com/pkg/errors v0.8.1
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/gogetter
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/printworkdir
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/replacementtransform
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/secretsfromdatabase
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/sedtransformer
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -3,8 +3,8 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/someservicegenerator
go 1.14
require (
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -4,8 +4,8 @@ go 1.14
require (
github.com/pkg/errors v0.8.1
sigs.k8s.io/kustomize/api v0.4.2
sigs.k8s.io/kustomize/api v0.5.0
sigs.k8s.io/yaml v1.2.0
)
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api

View File

@@ -2,6 +2,6 @@ module sigs.k8s.io/kustomize/plugin/someteam.example.com/v1/validator
go 1.14
require sigs.k8s.io/kustomize/api v0.4.2
require sigs.k8s.io/kustomize/api v0.5.0
replace sigs.k8s.io/kustomize/api v0.4.2 => ../../../../api
replace sigs.k8s.io/kustomize/api v0.5.0 => ../../../../api