mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-29 01:30:51 +00:00
Compare commits
183 Commits
api/v0.6.7
...
api/v0.7.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cdc3b0bad | ||
|
|
40bf89abcd | ||
|
|
7f548eddd0 | ||
|
|
86e9983bb7 | ||
|
|
cbbcfde99d | ||
|
|
304a9e57ee | ||
|
|
f23f26aa05 | ||
|
|
720857623f | ||
|
|
065c2b861a | ||
|
|
2a16af80bf | ||
|
|
81d324c68c | ||
|
|
b8702561ef | ||
|
|
ea039b36bc | ||
|
|
561cef1d5c | ||
|
|
62c5e424a6 | ||
|
|
45b1bf17d3 | ||
|
|
11dce34407 | ||
|
|
550a89295a | ||
|
|
8083b3607f | ||
|
|
cb42142161 | ||
|
|
cb59e0ef5f | ||
|
|
1a4a9fcdaf | ||
|
|
eb8dc5e20a | ||
|
|
0fb30a1010 | ||
|
|
fdfdfa9e4d | ||
|
|
6042aca7a4 | ||
|
|
94962c8bac | ||
|
|
f6ddea435c | ||
|
|
a9d4b7615f | ||
|
|
822cac26f9 | ||
|
|
97eedc8a43 | ||
|
|
2cb972de3b | ||
|
|
79d0d6b5e1 | ||
|
|
fabaf35c72 | ||
|
|
e13f8803eb | ||
|
|
64ffbcb15d | ||
|
|
b41df2293b | ||
|
|
e3fcec122a | ||
|
|
1edf9b630c | ||
|
|
7c6bf2e21d | ||
|
|
b3fc306f6a | ||
|
|
e92d048af2 | ||
|
|
f76059b824 | ||
|
|
bb41d018b5 | ||
|
|
cf8815b0a0 | ||
|
|
64beee22e9 | ||
|
|
79afd219a5 | ||
|
|
c68cf40d75 | ||
|
|
c7337a7d87 | ||
|
|
875e265e5d | ||
|
|
bdbfb28139 | ||
|
|
d54bc674f2 | ||
|
|
bd4580d73a | ||
|
|
ea5d08bac5 | ||
|
|
14a1a0e4a8 | ||
|
|
497e8038a3 | ||
|
|
44b5acad51 | ||
|
|
e5e19f7c09 | ||
|
|
a03843dfc7 | ||
|
|
b7cce27d40 | ||
|
|
126f5481f3 | ||
|
|
30dcf38609 | ||
|
|
1a2779b2c3 | ||
|
|
658b62c6f1 | ||
|
|
cf0bb49610 | ||
|
|
c2fbb709da | ||
|
|
1a002005c1 | ||
|
|
4f468fcc90 | ||
|
|
769f65d6c4 | ||
|
|
378eaedc82 | ||
|
|
6f2f401f6b | ||
|
|
614e853db3 | ||
|
|
33be04db45 | ||
|
|
8c6a9f6495 | ||
|
|
03b2fff0ee | ||
|
|
69cade143f | ||
|
|
90f45651d1 | ||
|
|
1b740034f7 | ||
|
|
a2d8e686de | ||
|
|
ce2ab487a5 | ||
|
|
7439f1809e | ||
|
|
6977c83a83 | ||
|
|
7b9eb05058 | ||
|
|
e2806a09fd | ||
|
|
f30fea4c07 | ||
|
|
8732671919 | ||
|
|
07cada36fa | ||
|
|
0d6b232b49 | ||
|
|
61455fe489 | ||
|
|
c63ed033ad | ||
|
|
455bd0c563 | ||
|
|
9ad4b1ddca | ||
|
|
d529eb8777 | ||
|
|
f7b2f0c067 | ||
|
|
ff6b337ebe | ||
|
|
76f05f3a40 | ||
|
|
d181a73f56 | ||
|
|
979fe3b457 | ||
|
|
bec45093e2 | ||
|
|
c113c41c9c | ||
|
|
99c9edfc3d | ||
|
|
cde6a5741e | ||
|
|
a315eb56ec | ||
|
|
90654b39bf | ||
|
|
24c4c66403 | ||
|
|
2b5029952c | ||
|
|
6a3bb5df44 | ||
|
|
d9623ab307 | ||
|
|
dd1df5a30e | ||
|
|
0e13a9c02b | ||
|
|
eb26d79fa0 | ||
|
|
7f8da385c0 | ||
|
|
1426137883 | ||
|
|
d90d77cdaf | ||
|
|
1ffd790cfb | ||
|
|
454906d093 | ||
|
|
8b97274af3 | ||
|
|
b1056b43cb | ||
|
|
e411942a74 | ||
|
|
6b30b72ebc | ||
|
|
9ddf0fe304 | ||
|
|
8a952a1b26 | ||
|
|
fff484e98b | ||
|
|
e819a2ba9d | ||
|
|
4908654c09 | ||
|
|
586515ebc4 | ||
|
|
735befef19 | ||
|
|
35087ed0cc | ||
|
|
f84f8f28fd | ||
|
|
45e118458c | ||
|
|
1102153ae3 | ||
|
|
338910d36c | ||
|
|
38e9770f40 | ||
|
|
20a4153893 | ||
|
|
51fba009b3 | ||
|
|
002215d719 | ||
|
|
f9d1e800e4 | ||
|
|
82db6cd73d | ||
|
|
3c25584658 | ||
|
|
c32a809dbd | ||
|
|
02be687778 | ||
|
|
c0a754e7b0 | ||
|
|
63e441a673 | ||
|
|
bd27d5f8bb | ||
|
|
0aa250c6e2 | ||
|
|
e269ad4a80 | ||
|
|
9db6b37b88 | ||
|
|
2361b70967 | ||
|
|
d016326877 | ||
|
|
67e445c10b | ||
|
|
76970a6b05 | ||
|
|
66db1df79a | ||
|
|
6442047e52 | ||
|
|
8ac6954de1 | ||
|
|
494977b9d0 | ||
|
|
0a0a6e1018 | ||
|
|
fa69d4ba9d | ||
|
|
36bdcca735 | ||
|
|
c71a4534a0 | ||
|
|
97402f1136 | ||
|
|
1329afa3ca | ||
|
|
60c8f4c594 | ||
|
|
428e25b856 | ||
|
|
8dd6f2b185 | ||
|
|
a3bf3ba608 | ||
|
|
b97e59c57e | ||
|
|
bae3228557 | ||
|
|
cc43a2d732 | ||
|
|
d25e1effb7 | ||
|
|
485b8121d3 | ||
|
|
401118728a | ||
|
|
0f45bd9583 | ||
|
|
97e4353755 | ||
|
|
826b5d9792 | ||
|
|
8c9da15156 | ||
|
|
e18d619c9e | ||
|
|
f8a3c04286 | ||
|
|
1a4c82241a | ||
|
|
81ca271e62 | ||
|
|
72262c5e71 | ||
|
|
125762d94d | ||
|
|
0ecbd5905b | ||
|
|
cb2b376065 |
23
Makefile
23
Makefile
@@ -26,7 +26,8 @@ verify-kustomize: \
|
|||||||
lint-kustomize \
|
lint-kustomize \
|
||||||
test-unit-kustomize-all \
|
test-unit-kustomize-all \
|
||||||
test-examples-kustomize-against-HEAD \
|
test-examples-kustomize-against-HEAD \
|
||||||
test-examples-kustomize-against-3.8.6
|
test-examples-kustomize-against-3.9.0 \
|
||||||
|
test-examples-kustomize-against-3.8.8
|
||||||
|
|
||||||
# The following target referenced by a file in
|
# The following target referenced by a file in
|
||||||
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
|
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
|
||||||
@@ -38,7 +39,8 @@ prow-presubmit-check: \
|
|||||||
test-unit-cmd-all \
|
test-unit-cmd-all \
|
||||||
test-go-mod \
|
test-go-mod \
|
||||||
test-examples-kustomize-against-HEAD \
|
test-examples-kustomize-against-HEAD \
|
||||||
test-examples-kustomize-against-3.8.6
|
test-examples-kustomize-against-3.9.0 \
|
||||||
|
test-examples-kustomize-against-3.8.8
|
||||||
|
|
||||||
.PHONY: verify-kustomize-e2e
|
.PHONY: verify-kustomize-e2e
|
||||||
verify-kustomize-e2e: test-examples-e2e-kustomize
|
verify-kustomize-e2e: test-examples-e2e-kustomize
|
||||||
@@ -274,17 +276,12 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
|
|||||||
./hack/testExamplesAgainstKustomize.sh HEAD
|
./hack/testExamplesAgainstKustomize.sh HEAD
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
test-examples-kustomize-against-3.8.6: $(MYGOBIN)/mdrip
|
test-examples-kustomize-against-3.9.0: $(MYGOBIN)/mdrip
|
||||||
( \
|
./hack/testExamplesAgainstKustomize.sh v3.9.0
|
||||||
set -e; \
|
|
||||||
tag=v3.8.6; \
|
.PHONY:
|
||||||
/bin/rm -f $(MYGOBIN)/kustomize; \
|
test-examples-kustomize-against-3.8.8: $(MYGOBIN)/mdrip
|
||||||
echo "Installing kustomize $$tag."; \
|
./hack/testExamplesAgainstKustomize.sh v3.8.8
|
||||||
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
|
|
||||||
./hack/testExamplesAgainstKustomize.sh $$tag; \
|
|
||||||
echo "Reinstalling kustomize from HEAD."; \
|
|
||||||
cd kustomize; go install .; \
|
|
||||||
)
|
|
||||||
|
|
||||||
# linux only.
|
# linux only.
|
||||||
# This is for testing an example plugin that
|
# This is for testing an example plugin that
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/filters/annotations"
|
"sigs.k8s.io/kustomize/api/filters/annotations"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,11 +24,14 @@ func (p *AnnotationsTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
|
if len(p.Annotations) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
err := filtersutil.ApplyToJSON(annotations.Filter{
|
err := r.ApplyFilter(annotations.Filter{
|
||||||
Annotations: p.Annotations,
|
Annotations: p.Annotations,
|
||||||
FsSlice: p.FieldSpecs,
|
FsSlice: p.FieldSpecs,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ func (p *HashTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
res.SetOriginalName(res.GetName(), false)
|
||||||
res.SetName(fmt.Sprintf("%s-%s", res.GetName(), h))
|
res.SetName(fmt.Sprintf("%s-%s", res.GetName(), h))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ package builtins
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/imdario/mergo"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
@@ -62,6 +65,9 @@ func (p *HelmChartInflationGeneratorPlugin) Config(h *resmap.PluginHelpers, conf
|
|||||||
if p.Values == "" {
|
if p.Values == "" {
|
||||||
p.Values = path.Join(p.ChartHome, p.ChartName, "values.yaml")
|
p.Values = path.Join(p.ChartHome, p.ChartName, "values.yaml")
|
||||||
}
|
}
|
||||||
|
if p.ValuesMerge == "" {
|
||||||
|
p.ValuesMerge = "override"
|
||||||
|
}
|
||||||
// runHelmCommand will run `helm` command with args provided. Return stdout
|
// runHelmCommand will run `helm` command with args provided. Return stdout
|
||||||
// and error if there is any.
|
// and error if there is any.
|
||||||
p.runHelmCommand = func(args []string) ([]byte, error) {
|
p.runHelmCommand = func(args []string) ([]byte, error) {
|
||||||
@@ -88,6 +94,63 @@ func (p *HelmChartInflationGeneratorPlugin) Config(h *resmap.PluginHelpers, conf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncodeValues for writing
|
||||||
|
func (p *HelmChartInflationGeneratorPlugin) EncodeValues(w io.Writer) error {
|
||||||
|
d, err := yaml.Marshal(p.ValuesLocal)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = w.Write(d)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// useValuesLocal process (merge) inflator config provided values with chart default values.yaml
|
||||||
|
func (p *HelmChartInflationGeneratorPlugin) useValuesLocal() error {
|
||||||
|
fn := path.Join(p.ChartHome, p.ChartName, "kustomize-values.yaml")
|
||||||
|
vf, err := os.Create(fn)
|
||||||
|
defer vf.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// override, merge, none
|
||||||
|
if p.ValuesMerge == "none" || p.ValuesMerge == "no" || p.ValuesMerge == "false" {
|
||||||
|
p.Values = fn
|
||||||
|
} else {
|
||||||
|
pValues, err := ioutil.ReadFile(p.Values)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
chValues := make(map[string]interface{})
|
||||||
|
err = yaml.Unmarshal(pValues, &chValues)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if p.ValuesMerge == "override" {
|
||||||
|
err = mergo.Merge(&chValues, p.ValuesLocal, mergo.WithOverride)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p.ValuesMerge == "merge" {
|
||||||
|
err = mergo.Merge(&chValues, p.ValuesLocal)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.ValuesLocal = chValues
|
||||||
|
p.Values = fn
|
||||||
|
}
|
||||||
|
err = p.EncodeValues(vf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
vf.Sync()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Generate implements generator
|
// Generate implements generator
|
||||||
func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
||||||
// cleanup
|
// cleanup
|
||||||
@@ -104,6 +167,15 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (resmap.ResMap, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inflator config valuesLocal
|
||||||
|
if len(p.ValuesLocal) > 0 {
|
||||||
|
err := p.useValuesLocal()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// render the charts
|
// render the charts
|
||||||
stdout, err := p.runHelmCommand(p.getTemplateCommandArgs())
|
stdout, err := p.runHelmCommand(p.getTemplateCommandArgs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/filters/imagetag"
|
"sigs.k8s.io/kustomize/api/filters/imagetag"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,17 +31,17 @@ func (p *ImageTagTransformerPlugin) Config(
|
|||||||
func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
// traverse all fields at first
|
// traverse all fields at first
|
||||||
err := filtersutil.ApplyToJSON(imagetag.LegacyFilter{
|
err := r.ApplyFilter(imagetag.LegacyFilter{
|
||||||
ImageTag: p.ImageTag,
|
ImageTag: p.ImageTag,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// then use user specified field specs
|
// then use user specified field specs
|
||||||
err = filtersutil.ApplyToJSON(imagetag.Filter{
|
err = r.ApplyFilter(imagetag.Filter{
|
||||||
ImageTag: p.ImageTag,
|
ImageTag: p.ImageTag,
|
||||||
FsSlice: p.FieldSpecs,
|
FsSlice: p.FieldSpecs,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/filters/labels"
|
"sigs.k8s.io/kustomize/api/filters/labels"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,11 +24,14 @@ func (p *LabelTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
|
if len(p.Labels) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
for _, r := range m.Resources() {
|
for _, r := range m.Resources() {
|
||||||
err := filtersutil.ApplyToJSON(labels.Filter{
|
err := r.ApplyFilter(labels.Filter{
|
||||||
Labels: p.Labels,
|
Labels: p.Labels,
|
||||||
FsSlice: p.FieldSpecs,
|
FsSlice: p.FieldSpecs,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/filters/namespace"
|
"sigs.k8s.io/kustomize/api/filters/namespace"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,10 +34,11 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
// Don't mutate empty objects?
|
// Don't mutate empty objects?
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err := filtersutil.ApplyToJSON(namespace.Filter{
|
r.SetOriginalNs(r.GetNamespace(), false)
|
||||||
|
err := r.ApplyFilter(namespace.Filter{
|
||||||
Namespace: p.Namespace,
|
Namespace: p.Namespace,
|
||||||
FsSlice: p.FieldSpecs,
|
FsSlice: p.FieldSpecs,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -79,9 +78,9 @@ func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
err = filtersutil.ApplyToJSON(patchjson6902.Filter{
|
err = res.ApplyFilter(patchjson6902.Filter{
|
||||||
Patch: p.JsonOp,
|
Patch: p.JsonOp,
|
||||||
}, res)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PatchStrategicMergeTransformerPlugin struct {
|
type PatchStrategicMergeTransformerPlugin struct {
|
||||||
h *resmap.PluginHelpers
|
|
||||||
loadedPatches []*resource.Resource
|
loadedPatches []*resource.Resource
|
||||||
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
|
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
|
||||||
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
|
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
|
||||||
@@ -21,7 +20,6 @@ type PatchStrategicMergeTransformerPlugin struct {
|
|||||||
|
|
||||||
func (p *PatchStrategicMergeTransformerPlugin) Config(
|
func (p *PatchStrategicMergeTransformerPlugin) Config(
|
||||||
h *resmap.PluginHelpers, c []byte) (err error) {
|
h *resmap.PluginHelpers, c []byte) (err error) {
|
||||||
p.h = h
|
|
||||||
err = yaml.Unmarshal(c, p)
|
err = yaml.Unmarshal(c, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -36,13 +34,13 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
|
|||||||
// All tests pass if this code is commented out. This code should
|
// All tests pass if this code is commented out. This code should
|
||||||
// be deleted; the user should use the Patches field which
|
// be deleted; the user should use the Patches field which
|
||||||
// exists for this purpose (inline patch declaration).
|
// exists for this purpose (inline patch declaration).
|
||||||
res, err := p.h.ResmapFactory().RF().SliceFromBytes([]byte(onePath))
|
res, err := h.ResmapFactory().RF().SliceFromBytes([]byte(onePath))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
p.loadedPatches = append(p.loadedPatches, res...)
|
p.loadedPatches = append(p.loadedPatches, res...)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res, err = p.h.ResmapFactory().RF().SliceFromPatches(
|
res, err = h.ResmapFactory().RF().SliceFromPatches(
|
||||||
p.h.Loader(), []types.PatchStrategicMerge{onePath})
|
h.Loader(), []types.PatchStrategicMerge{onePath})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -50,7 +48,7 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p.Patches != "" {
|
if p.Patches != "" {
|
||||||
res, err := p.h.ResmapFactory().RF().SliceFromBytes([]byte(p.Patches))
|
res, err := h.ResmapFactory().RF().SliceFromBytes([]byte(p.Patches))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -61,15 +59,17 @@ func (p *PatchStrategicMergeTransformerPlugin) Config(
|
|||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
|
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
|
||||||
}
|
}
|
||||||
return err
|
// Merge the patches, looking for conflicts.
|
||||||
}
|
m, err := h.ResmapFactory().ConflatePatches(p.loadedPatches)
|
||||||
|
|
||||||
func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error {
|
|
||||||
patches, err := p.h.ResmapFactory().Merge(p.loadedPatches)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, patch := range patches.Resources() {
|
p.loadedPatches = m.Resources()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
|
for _, patch := range p.loadedPatches {
|
||||||
target, err := m.GetById(patch.OrgId())
|
target, err := m.GetById(patch.OrgId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -105,9 +104,10 @@ func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpa
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
err = filtersutil.ApplyToJSON(patchjson6902.Filter{
|
res.SetOriginalName(res.GetName(), false)
|
||||||
|
err = res.ApplyFilter(patchjson6902.Filter{
|
||||||
Patch: p.Patch,
|
Patch: p.Patch,
|
||||||
}, res)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -67,14 +66,18 @@ func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
// this will add a prefix and a suffix
|
// this will add a prefix and a suffix
|
||||||
// to the resource even if those are
|
// to the resource even if those are
|
||||||
// empty
|
// empty
|
||||||
|
|
||||||
r.AddNamePrefix(p.Prefix)
|
r.AddNamePrefix(p.Prefix)
|
||||||
r.AddNameSuffix(p.Suffix)
|
r.AddNameSuffix(p.Suffix)
|
||||||
|
if p.Prefix != "" || p.Suffix != "" {
|
||||||
|
r.SetOriginalName(r.GetName(), false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err := filtersutil.ApplyToJSON(prefixsuffix.Filter{
|
err := r.ApplyFilter(prefixsuffix.Filter{
|
||||||
Prefix: p.Prefix,
|
Prefix: p.Prefix,
|
||||||
Suffix: p.Suffix,
|
Suffix: p.Suffix,
|
||||||
FieldSpec: fs,
|
FieldSpec: fs,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/replicacount"
|
"sigs.k8s.io/kustomize/api/filters/replicacount"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
@@ -42,10 +40,10 @@ func (p *ReplicaCountTransformerPlugin) Transform(m resmap.ResMap) error {
|
|||||||
// There are redundant checks in the filter
|
// There are redundant checks in the filter
|
||||||
// that we'll live with until resolution of
|
// that we'll live with until resolution of
|
||||||
// https://github.com/kubernetes-sigs/kustomize/issues/2506
|
// https://github.com/kubernetes-sigs/kustomize/issues/2506
|
||||||
err := filtersutil.ApplyToJSON(replicacount.Filter{
|
err := r.ApplyFilter(replicacount.Filter{
|
||||||
Replica: p.Replica,
|
Replica: p.Replica,
|
||||||
FieldSpec: fs,
|
FieldSpec: fs,
|
||||||
}, r)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -119,15 +118,15 @@ func (p *ValueAddTransformerPlugin) Transform(m resmap.ResMap) (err error) {
|
|||||||
// TODO: consider t.NotSelector if implemented
|
// TODO: consider t.NotSelector if implemented
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
if t.FieldPath == types.MetadataNamespacePath {
|
if t.FieldPath == types.MetadataNamespacePath {
|
||||||
err = filtersutil.ApplyToJSON(namespace.Filter{
|
err = res.ApplyFilter(namespace.Filter{
|
||||||
Namespace: p.Value,
|
Namespace: p.Value,
|
||||||
}, res)
|
})
|
||||||
} else {
|
} else {
|
||||||
err = filtersutil.ApplyToJSON(valueadd.Filter{
|
err = res.ApplyFilter(valueadd.Filter{
|
||||||
Value: p.Value,
|
Value: p.Value,
|
||||||
FieldPath: t.FieldPath,
|
FieldPath: t.FieldPath,
|
||||||
FilePathPosition: t.FilePathPosition,
|
FilePathPosition: t.FilePathPosition,
|
||||||
}, res)
|
})
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type Filter struct {
|
|||||||
var _ kio.Filter = Filter{}
|
var _ kio.Filter = Filter{}
|
||||||
|
|
||||||
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
keys := filtersutil.SortedMapKeys(f.Annotations)
|
keys := yaml.SortedMapKeys(f.Annotations)
|
||||||
_, err := kio.FilterAll(yaml.FilterFunc(
|
_, err := kio.FilterAll(yaml.FilterFunc(
|
||||||
func(node *yaml.RNode) (*yaml.RNode, error) {
|
func(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ metadata:
|
|||||||
`)}},
|
`)}},
|
||||||
Filters: []kio.Filter{Filter{
|
Filters: []kio.Filter{Filter{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
|
"booleanValue": "true",
|
||||||
|
"numberValue": "42",
|
||||||
},
|
},
|
||||||
FsSlice: fss,
|
FsSlice: fss,
|
||||||
}},
|
}},
|
||||||
@@ -44,12 +46,16 @@ metadata:
|
|||||||
// metadata:
|
// metadata:
|
||||||
// name: instance
|
// name: instance
|
||||||
// annotations:
|
// annotations:
|
||||||
|
// booleanValue: "true"
|
||||||
// foo: bar
|
// foo: bar
|
||||||
|
// numberValue: "42"
|
||||||
// ---
|
// ---
|
||||||
// apiVersion: example.com/v1
|
// apiVersion: example.com/v1
|
||||||
// kind: Bar
|
// kind: Bar
|
||||||
// metadata:
|
// metadata:
|
||||||
// name: instance
|
// name: instance
|
||||||
// annotations:
|
// annotations:
|
||||||
|
// booleanValue: "true"
|
||||||
// foo: bar
|
// foo: bar
|
||||||
|
// numberValue: "42"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package filtersutil
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SortedMapKeys returns a sorted slice of keys to the given map.
|
|
||||||
// Writing this function never gets old.
|
|
||||||
func SortedMapKeys(m map[string]string) []string {
|
|
||||||
keys := make([]string, len(m))
|
|
||||||
i := 0
|
|
||||||
for k := range m {
|
|
||||||
keys[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
return keys
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,7 @@ func TestImageTagUpdater_Filter(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
"ignore CustomResourceDefinition": {
|
"ignore CustomResourceDefinition": {
|
||||||
input: `
|
input: `
|
||||||
apiVersion: apiextensions.k8s.io/v1beta1
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
name: whatever
|
name: whatever
|
||||||
@@ -30,7 +30,7 @@ spec:
|
|||||||
- image: whatever
|
- image: whatever
|
||||||
`,
|
`,
|
||||||
expectedOutput: `
|
expectedOutput: `
|
||||||
apiVersion: apiextensions.k8s.io/v1beta1
|
apiVersion: apiextensions.k8s.io/v1
|
||||||
kind: CustomResourceDefinition
|
kind: CustomResourceDefinition
|
||||||
metadata:
|
metadata:
|
||||||
name: whatever
|
name: whatever
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type Filter struct {
|
|||||||
var _ kio.Filter = Filter{}
|
var _ kio.Filter = Filter{}
|
||||||
|
|
||||||
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
keys := filtersutil.SortedMapKeys(f.Labels)
|
keys := yaml.SortedMapKeys(f.Labels)
|
||||||
_, err := kio.FilterAll(yaml.FilterFunc(
|
_, err := kio.FilterAll(yaml.FilterFunc(
|
||||||
func(node *yaml.RNode) (*yaml.RNode, error) {
|
func(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
"sigs.k8s.io/kustomize/api/filters/fieldspec"
|
||||||
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/resource"
|
"sigs.k8s.io/kustomize/api/resource"
|
||||||
@@ -16,22 +15,36 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Filter will update the name reference
|
// Filter updates a name references.
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
// Referrer is the object that refers to something else by a name,
|
||||||
Referrer *resource.Resource
|
// a name that this filter seeks to update.
|
||||||
Target resid.Gvk
|
Referrer *resource.Resource
|
||||||
|
|
||||||
|
// NameFieldToUpdate is the field in the Referrer that holds the
|
||||||
|
// name requiring an update.
|
||||||
|
NameFieldToUpdate types.FieldSpec `json:"nameFieldToUpdate,omitempty" yaml:"nameFieldToUpdate,omitempty"`
|
||||||
|
|
||||||
|
// Source of the new value for the name (in its name field).
|
||||||
|
ReferralTarget resid.Gvk
|
||||||
|
|
||||||
|
// Set of resources to hunt through to find the ReferralTarget.
|
||||||
ReferralCandidates resmap.ResMap
|
ReferralCandidates resmap.ResMap
|
||||||
isRoleRef bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At time of writing, in practice this is called with a slice with only
|
||||||
|
// one entry, the node also referred to be the resource in the Referrer field.
|
||||||
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
|
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The node passed in here is the same node as held in Referrer, and
|
||||||
|
// that's how the referrer's name field is updated.
|
||||||
|
// However, this filter still needs the extra methods on Referrer
|
||||||
|
// to consult things like the resource Id, its namespace, etc.
|
||||||
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
err := node.PipeE(fieldspec.Filter{
|
err := node.PipeE(fieldspec.Filter{
|
||||||
FieldSpec: f.FieldSpec,
|
FieldSpec: f.NameFieldToUpdate,
|
||||||
SetValue: f.set,
|
SetValue: f.set,
|
||||||
})
|
})
|
||||||
return node, err
|
return node, err
|
||||||
@@ -41,58 +54,102 @@ func (f Filter) set(node *yaml.RNode) error {
|
|||||||
if yaml.IsMissingOrNull(node) {
|
if yaml.IsMissingOrNull(node) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(f.FieldSpec.Path, "roleRef/name") {
|
|
||||||
f.isRoleRef = true
|
|
||||||
}
|
|
||||||
switch node.YNode().Kind {
|
switch node.YNode().Kind {
|
||||||
case yaml.ScalarNode:
|
case yaml.ScalarNode:
|
||||||
return f.setScalar(node)
|
return f.setScalar(node)
|
||||||
case yaml.MappingNode:
|
case yaml.MappingNode:
|
||||||
// Kind: ValidatingWebhookConfiguration
|
|
||||||
// FieldSpec is webhooks/clientConfig/service
|
|
||||||
return f.setMapping(node)
|
return f.setMapping(node)
|
||||||
case yaml.SequenceNode:
|
case yaml.SequenceNode:
|
||||||
return f.setSequence(node)
|
return applyFilterToSeq(seqFilter{
|
||||||
|
setScalarFn: f.setScalar,
|
||||||
|
setMappingFn: f.setMapping,
|
||||||
|
}, node)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"node is expected to be either a string or a slice of string or a map of string")
|
"node is expected to be either a string or a slice of string or a map of string")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Filter) setSequence(node *yaml.RNode) error {
|
// Replace name field within a map RNode and leverage the namespace field.
|
||||||
return applyFilterToSeq(seqFilter{
|
|
||||||
setScalarFn: f.setScalar,
|
|
||||||
setMappingFn: f.setMapping,
|
|
||||||
}, node)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f Filter) setMapping(node *yaml.RNode) error {
|
func (f Filter) setMapping(node *yaml.RNode) error {
|
||||||
return setNameAndNs(
|
if node.YNode().Kind != yaml.MappingNode {
|
||||||
node,
|
return fmt.Errorf("expect a mapping node")
|
||||||
f.Referrer,
|
}
|
||||||
f.Target,
|
nameNode, err := node.Pipe(yaml.FieldMatcher{Name: "name"})
|
||||||
f.ReferralCandidates,
|
if err != nil || nameNode == nil {
|
||||||
f.isRoleRef,
|
return fmt.Errorf("cannot find field 'name' in node")
|
||||||
)
|
}
|
||||||
|
namespaceNode, err := node.Pipe(yaml.FieldMatcher{Name: "namespace"})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error when find field 'namespace'")
|
||||||
|
}
|
||||||
|
|
||||||
|
// name will not be updated if the namespace doesn't match
|
||||||
|
subset := f.ReferralCandidates.Resources()
|
||||||
|
if namespaceNode != nil {
|
||||||
|
namespace := namespaceNode.YNode().Value
|
||||||
|
bynamespace := f.ReferralCandidates.GroupedByOriginalNamespace()
|
||||||
|
if _, ok := bynamespace[namespace]; !ok {
|
||||||
|
bynamespace = f.ReferralCandidates.GroupedByCurrentNamespace()
|
||||||
|
if _, ok := bynamespace[namespace]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subset = bynamespace[namespace]
|
||||||
|
}
|
||||||
|
|
||||||
|
oldName := nameNode.YNode().Value
|
||||||
|
res, err := f.selectReferral(oldName, subset)
|
||||||
|
if err != nil || res == nil {
|
||||||
|
// Nil res means nothing to do.
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.recordTheReferral(res)
|
||||||
|
if res.GetName() == oldName && res.GetNamespace() == "" {
|
||||||
|
// The name has not changed, nothing to do.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err = node.PipeE(yaml.FieldSetter{
|
||||||
|
Name: "name",
|
||||||
|
StringValue: res.GetName(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if res.GetNamespace() != "" {
|
||||||
|
// We don't want value "" to replace value "default" since
|
||||||
|
// the empty string is handled as a wild card here not default namespace
|
||||||
|
// by kubernetes.
|
||||||
|
err = node.PipeE(yaml.FieldSetter{
|
||||||
|
Name: "namespace",
|
||||||
|
StringValue: res.GetNamespace(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Filter) setScalar(node *yaml.RNode) error {
|
func (f Filter) setScalar(node *yaml.RNode) error {
|
||||||
newValue, err := getSimpleNameField(
|
res, err := f.selectReferral(
|
||||||
node.YNode().Value,
|
node.YNode().Value, f.ReferralCandidates.Resources())
|
||||||
f.Referrer,
|
if err != nil || res == nil {
|
||||||
f.Target,
|
// Nil res means nothing to do.
|
||||||
f.ReferralCandidates,
|
|
||||||
f.ReferralCandidates.Resources(),
|
|
||||||
f.isRoleRef,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = filtersutil.SetScalar(newValue)(node)
|
f.recordTheReferral(res)
|
||||||
if err != nil {
|
if res.GetName() == node.YNode().Value {
|
||||||
return err
|
// The name has not changed, nothing to do.
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return node.PipeE(yaml.FieldSetter{StringValue: res.GetName()})
|
||||||
|
}
|
||||||
|
|
||||||
|
// In the resource, make a note that it is referred to by the referrer.
|
||||||
|
func (f Filter) recordTheReferral(res *resource.Resource) {
|
||||||
|
res.AppendRefBy(f.Referrer.CurId())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f Filter) isRoleRef() bool {
|
||||||
|
return strings.HasSuffix(f.NameFieldToUpdate.Path, "roleRef/name")
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRoleRefGvk returns a Gvk in the roleRef field. Return error
|
// getRoleRefGvk returns a Gvk in the roleRef field. Return error
|
||||||
@@ -114,14 +171,16 @@ func getRoleRefGvk(res json.Marshaler) (*resid.Gvk, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if apiGroup.IsNil() {
|
if apiGroup.IsNil() {
|
||||||
return nil, fmt.Errorf("apiGroup cannot be found in roleRef %s", roleRef.MustString())
|
return nil, fmt.Errorf(
|
||||||
|
"apiGroup cannot be found in roleRef %s", roleRef.MustString())
|
||||||
}
|
}
|
||||||
kind, err := roleRef.Pipe(yaml.Lookup("kind"))
|
kind, err := roleRef.Pipe(yaml.Lookup("kind"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if kind.IsNil() {
|
if kind.IsNil() {
|
||||||
return nil, fmt.Errorf("kind cannot be found in roleRef %s", roleRef.MustString())
|
return nil, fmt.Errorf(
|
||||||
|
"kind cannot be found in roleRef %s", roleRef.MustString())
|
||||||
}
|
}
|
||||||
return &resid.Gvk{
|
return &resid.Gvk{
|
||||||
Group: apiGroup.YNode().Value,
|
Group: apiGroup.YNode().Value,
|
||||||
@@ -129,19 +188,17 @@ func getRoleRefGvk(res json.Marshaler) (*resid.Gvk, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterReferralCandidates(
|
func (f Filter) filterReferralCandidates(
|
||||||
referrer *resource.Resource,
|
matches []*resource.Resource) []*resource.Resource {
|
||||||
matches []*resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
) []*resource.Resource {
|
|
||||||
var ret []*resource.Resource
|
var ret []*resource.Resource
|
||||||
for _, m := range matches {
|
for _, m := range matches {
|
||||||
// If target kind is not ServiceAccount, we shouldn't consider condidates which
|
// If target kind is not ServiceAccount, we shouldn't consider condidates which
|
||||||
// doesn't have same namespace.
|
// doesn't have same namespace.
|
||||||
if target.Kind != "ServiceAccount" && m.GetNamespace() != referrer.GetNamespace() {
|
if f.ReferralTarget.Kind != "ServiceAccount" &&
|
||||||
|
m.GetNamespace() != f.Referrer.GetNamespace() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !referrer.PrefixesSuffixesEquals(m) {
|
if !f.Referrer.PrefixesSuffixesEquals(m) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret = append(ret, m)
|
ret = append(ret, m)
|
||||||
@@ -150,72 +207,57 @@ func filterReferralCandidates(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// selectReferral picks the referral among a subset of candidates.
|
// selectReferral picks the referral among a subset of candidates.
|
||||||
// It returns the current name and namespace of the selected candidate.
|
// The content of the candidateSubset slice is most of the time
|
||||||
// Note that the content of the referricalCandidateSubset slice is most of the time
|
// identical to the ReferralCandidates resmap. Still in some cases, such
|
||||||
// identical to the referralCandidates resmap. Still in some cases, such
|
|
||||||
// as ClusterRoleBinding, the subset only contains the resources of a specific
|
// as ClusterRoleBinding, the subset only contains the resources of a specific
|
||||||
// namespace.
|
// namespace.
|
||||||
func selectReferral(
|
func (f Filter) selectReferral(
|
||||||
oldName string,
|
oldName string,
|
||||||
referrer *resource.Resource,
|
candidateSubset []*resource.Resource) (*resource.Resource, error) {
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap,
|
|
||||||
referralCandidateSubset []*resource.Resource,
|
|
||||||
isRoleRef bool) (string, string, error) {
|
|
||||||
var roleRefGvk *resid.Gvk
|
var roleRefGvk *resid.Gvk
|
||||||
if isRoleRef {
|
if f.isRoleRef() {
|
||||||
var err error
|
var err error
|
||||||
roleRefGvk, err = getRoleRefGvk(referrer)
|
roleRefGvk, err = getRoleRefGvk(f.Referrer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, res := range referralCandidateSubset {
|
for _, res := range candidateSubset {
|
||||||
|
if res.GetOriginalName() != oldName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
id := res.OrgId()
|
id := res.OrgId()
|
||||||
|
if !id.IsSelected(&f.ReferralTarget) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// If the we are processing a roleRef, the apiGroup and Kind in the
|
// If the we are processing a roleRef, the apiGroup and Kind in the
|
||||||
// roleRef are needed to be considered.
|
// roleRef are needed to be considered.
|
||||||
if (!isRoleRef || id.IsSelected(roleRefGvk)) &&
|
if f.isRoleRef() && !id.IsSelected(roleRefGvk) {
|
||||||
id.IsSelected(&target) && res.GetOriginalName() == oldName {
|
continue
|
||||||
matches := referralCandidates.GetMatchingResourcesByOriginalId(id.Equals)
|
|
||||||
// If there's more than one match,
|
|
||||||
// filter the matches by prefix and suffix
|
|
||||||
if len(matches) > 1 {
|
|
||||||
filteredMatches := filterReferralCandidates(referrer, matches, target)
|
|
||||||
if len(filteredMatches) > 1 {
|
|
||||||
return "", "", fmt.Errorf(
|
|
||||||
"multiple matches for %s:\n %v",
|
|
||||||
id, getIds(filteredMatches))
|
|
||||||
}
|
|
||||||
// Check is the match the resource we are working on
|
|
||||||
if len(filteredMatches) == 0 || res != filteredMatches[0] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// In the resource, note that it is referenced
|
|
||||||
// by the referrer.
|
|
||||||
res.AppendRefBy(referrer.CurId())
|
|
||||||
// Return transformed name of the object,
|
|
||||||
// complete with prefixes, hashes, etc.
|
|
||||||
return res.GetName(), res.GetNamespace(), nil
|
|
||||||
}
|
}
|
||||||
|
matches := f.ReferralCandidates.GetMatchingResourcesByOriginalId(id.Equals)
|
||||||
|
// If there's more than one match,
|
||||||
|
// filter the matches by prefix and suffix
|
||||||
|
if len(matches) > 1 {
|
||||||
|
filteredMatches := f.filterReferralCandidates(matches)
|
||||||
|
if len(filteredMatches) > 1 {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"multiple matches for %s:\n %v",
|
||||||
|
id, getIds(filteredMatches))
|
||||||
|
}
|
||||||
|
// Check is the match the resource we are working on
|
||||||
|
if len(filteredMatches) == 0 || res != filteredMatches[0] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// In the resource, note that it is referenced
|
||||||
|
// by the referrer.
|
||||||
|
res.AppendRefBy(f.Referrer.CurId())
|
||||||
|
// Return transformed name of the object,
|
||||||
|
// complete with prefixes, hashes, etc.
|
||||||
|
return res, nil
|
||||||
}
|
}
|
||||||
|
return nil, nil
|
||||||
return oldName, "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// utility function to replace a simple string by the new name
|
|
||||||
func getSimpleNameField(
|
|
||||||
oldName string,
|
|
||||||
referrer *resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap,
|
|
||||||
referralCandidateSubset []*resource.Resource,
|
|
||||||
isRoleRef bool) (string, error) {
|
|
||||||
|
|
||||||
newName, _, err := selectReferral(oldName, referrer, target,
|
|
||||||
referralCandidates, referralCandidateSubset, isRoleRef)
|
|
||||||
|
|
||||||
return newName, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIds(rs []*resource.Resource) []string {
|
func getIds(rs []*resource.Resource) []string {
|
||||||
@@ -225,73 +267,3 @@ func getIds(rs []*resource.Resource) []string {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility function to replace name field within a map RNode
|
|
||||||
// and leverage the namespace field.
|
|
||||||
func setNameAndNs(
|
|
||||||
in *yaml.RNode,
|
|
||||||
referrer *resource.Resource,
|
|
||||||
target resid.Gvk,
|
|
||||||
referralCandidates resmap.ResMap,
|
|
||||||
isRoleRef bool) error {
|
|
||||||
|
|
||||||
if in.YNode().Kind != yaml.MappingNode {
|
|
||||||
return fmt.Errorf("expect a mapping node")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get name field
|
|
||||||
nameNode, err := in.Pipe(yaml.FieldMatcher{
|
|
||||||
Name: "name",
|
|
||||||
})
|
|
||||||
if err != nil || nameNode == nil {
|
|
||||||
return fmt.Errorf("cannot find field 'name' in node")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get namespace field
|
|
||||||
namespaceNode, err := in.Pipe(yaml.FieldMatcher{
|
|
||||||
Name: "namespace",
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error when find field 'namespace'")
|
|
||||||
}
|
|
||||||
|
|
||||||
// check is namespace matched
|
|
||||||
// name will bot be updated if the namespace doesn't match
|
|
||||||
subset := referralCandidates.Resources()
|
|
||||||
if namespaceNode != nil {
|
|
||||||
namespace := namespaceNode.YNode().Value
|
|
||||||
bynamespace := referralCandidates.GroupedByOriginalNamespace()
|
|
||||||
if _, ok := bynamespace[namespace]; !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
subset = bynamespace[namespace]
|
|
||||||
}
|
|
||||||
|
|
||||||
oldName := nameNode.YNode().Value
|
|
||||||
newname, newnamespace, err := selectReferral(oldName, referrer, target,
|
|
||||||
referralCandidates, subset, isRoleRef)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newname == oldName) && (newnamespace == "") {
|
|
||||||
// no candidate found.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// set name
|
|
||||||
in.Pipe(yaml.FieldSetter{
|
|
||||||
Name: "name",
|
|
||||||
StringValue: newname,
|
|
||||||
})
|
|
||||||
if newnamespace != "" {
|
|
||||||
// We don't want value "" to replace value "default" since
|
|
||||||
// the empty string is handled as a wild card here not default namespace
|
|
||||||
// by kubernetes.
|
|
||||||
in.Pipe(yaml.FieldSetter{
|
|
||||||
Name: "namespace",
|
|
||||||
StringValue: newnamespace,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ ref:
|
|||||||
name: newName
|
name: newName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -90,8 +90,8 @@ seq:
|
|||||||
- oldName2
|
- oldName2
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "seq"},
|
NameFieldToUpdate: types.FieldSpec{Path: "seq"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -128,8 +128,8 @@ map:
|
|||||||
name: newName
|
name: newName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "map"},
|
NameFieldToUpdate: types.FieldSpec{Path: "map"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -169,8 +169,8 @@ map:
|
|||||||
namespace: oldNs
|
namespace: oldNs
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "map"},
|
NameFieldToUpdate: types.FieldSpec{Path: "map"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -207,8 +207,8 @@ map:
|
|||||||
name: null
|
name: null
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "map"},
|
NameFieldToUpdate: types.FieldSpec{Path: "map"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -277,8 +277,8 @@ metadata:
|
|||||||
originalNames: []string{"oldName", "oldName"},
|
originalNames: []string{"oldName", "oldName"},
|
||||||
expected: "",
|
expected: "",
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -308,8 +308,8 @@ metadata:
|
|||||||
originalNames: []string{"oldName", "oldName"},
|
originalNames: []string{"oldName", "oldName"},
|
||||||
expected: "",
|
expected: "",
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -395,8 +395,8 @@ ref:
|
|||||||
name: newName
|
name: newName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -438,8 +438,8 @@ ref:
|
|||||||
name: newName
|
name: newName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -481,8 +481,8 @@ ref:
|
|||||||
name: newName
|
name: newName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -517,8 +517,8 @@ metadata:
|
|||||||
inputSuffix: "suffix",
|
inputSuffix: "suffix",
|
||||||
expected: "",
|
expected: "",
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -553,8 +553,8 @@ metadata:
|
|||||||
inputSuffix: "",
|
inputSuffix: "",
|
||||||
expected: "",
|
expected: "",
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -589,8 +589,8 @@ metadata:
|
|||||||
inputSuffix: "suffix",
|
inputSuffix: "suffix",
|
||||||
expected: "",
|
expected: "",
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -632,8 +632,8 @@ ref:
|
|||||||
name: oldName
|
name: oldName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -675,8 +675,8 @@ ref:
|
|||||||
name: oldName
|
name: oldName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
@@ -718,8 +718,8 @@ ref:
|
|||||||
name: oldName
|
name: oldName
|
||||||
`,
|
`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
FieldSpec: types.FieldSpec{Path: "ref/name"},
|
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
|
||||||
Target: resid.Gvk{
|
ReferralTarget: resid.Gvk{
|
||||||
Group: "apps",
|
Group: "apps",
|
||||||
Version: "v1",
|
Version: "v1",
|
||||||
Kind: "Secret",
|
Kind: "Secret",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package patchstrategicmerge
|
package patchstrategicmerge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml/merge2"
|
"sigs.k8s.io/kustomize/kyaml/yaml/merge2"
|
||||||
@@ -15,6 +16,7 @@ type Filter struct {
|
|||||||
|
|
||||||
var _ kio.Filter = Filter{}
|
var _ kio.Filter = Filter{}
|
||||||
|
|
||||||
|
// Filter does a strategic merge patch, which can delete nodes.
|
||||||
func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
var result []*yaml.RNode
|
var result []*yaml.RNode
|
||||||
for i := range nodes {
|
for i := range nodes {
|
||||||
@@ -27,7 +29,9 @@ func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, r)
|
if !konfig.FlagEnableKyamlDefaultValue || r != nil {
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,29 @@ func TestFilter(t *testing.T) {
|
|||||||
patch *yaml.RNode
|
patch *yaml.RNode
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
|
"simple": {
|
||||||
|
input: `apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 1
|
||||||
|
`,
|
||||||
|
patch: yaml.MustParse(`apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`),
|
||||||
|
expected: `apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`,
|
||||||
|
},
|
||||||
"nullMapEntry1": {
|
"nullMapEntry1": {
|
||||||
input: `
|
input: `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
// Package refvar contains a kio.Filter implementation of the kustomize
|
// Package refvar contains a kio.Filter implementation of the kustomize
|
||||||
// refvar transformer.
|
// refvar transformer (find and replace $(FOO) style variables in strings).
|
||||||
package refvar
|
package refvar
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// Package expansion provides functions find and replace $(FOO) style variables in strings.
|
package refvar
|
||||||
package expansion
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -17,38 +17,64 @@ const (
|
|||||||
|
|
||||||
// syntaxWrap returns the input string wrapped by the expansion syntax.
|
// syntaxWrap returns the input string wrapped by the expansion syntax.
|
||||||
func syntaxWrap(input string) string {
|
func syntaxWrap(input string) string {
|
||||||
return string(operator) + string(referenceOpener) + input + string(referenceCloser)
|
var sb strings.Builder
|
||||||
|
sb.WriteByte(operator)
|
||||||
|
sb.WriteByte(referenceOpener)
|
||||||
|
sb.WriteString(input)
|
||||||
|
sb.WriteByte(referenceCloser)
|
||||||
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MappingFuncFor returns a mapping function for use with Expand that
|
// MappingFunc maps a string to anything.
|
||||||
// implements the expansion semantics defined in the expansion spec; it
|
type MappingFunc func(string) interface{}
|
||||||
// returns the input string wrapped in the expansion syntax if no mapping
|
|
||||||
// for the input is found.
|
// MakePrimitiveReplacer returns a MappingFunc that uses a map to do
|
||||||
func MappingFuncFor(
|
// replacements, and a histogram to count map hits.
|
||||||
counts map[string]int,
|
//
|
||||||
context ...map[string]interface{}) func(string) interface{} {
|
// Func behavior:
|
||||||
return func(input string) interface{} {
|
//
|
||||||
for _, vars := range context {
|
// If the input key is NOT found in the map, the key is wrapped up as
|
||||||
val, ok := vars[input]
|
// as a variable declaration string and returned, e.g. key FOO becomes $(FOO).
|
||||||
if ok {
|
// This string is presumably put back where it was found, and might get replaced
|
||||||
counts[input]++
|
// later.
|
||||||
switch typedV := val.(type) {
|
//
|
||||||
case string, int64, float64, bool:
|
// If the key is found in the map, the value is returned if it is a primitive
|
||||||
return typedV
|
// type (string, bool, number), and the hit is counted.
|
||||||
default:
|
//
|
||||||
return syntaxWrap(input)
|
// If it's not a primitive type (e.g. a map, struct, func, etc.) then this
|
||||||
}
|
// function doesn't know what to do with it and it returns the key wrapped up
|
||||||
|
// again as if it had not been replaced. This should probably be an error.
|
||||||
|
func MakePrimitiveReplacer(
|
||||||
|
counts map[string]int, someMap map[string]interface{}) MappingFunc {
|
||||||
|
return func(key string) interface{} {
|
||||||
|
if value, ok := someMap[key]; ok {
|
||||||
|
switch typedV := value.(type) {
|
||||||
|
case string, int, int32, int64, float32, float64, bool:
|
||||||
|
counts[key]++
|
||||||
|
return typedV
|
||||||
|
default:
|
||||||
|
// If the value is some complicated type (e.g. a map or struct),
|
||||||
|
// this function doesn't know how to jam it into a string,
|
||||||
|
// so just pretend it was a cache miss.
|
||||||
|
// Likely this should be an error instead of a silent failure,
|
||||||
|
// since the programmer passed an impossible value.
|
||||||
|
log.Printf(
|
||||||
|
"MakePrimitiveReplacer: bad replacement type=%T val=%v",
|
||||||
|
typedV, typedV)
|
||||||
|
return syntaxWrap(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return syntaxWrap(input)
|
// If unable to return the mapped variable, return it
|
||||||
|
// as it was found, and a later mapping might be able to
|
||||||
|
// replace it.
|
||||||
|
return syntaxWrap(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand replaces variable references in the input string according to
|
// DoReplacements replaces variable references in the input string
|
||||||
// the expansion spec using the given mapping function to resolve the
|
// using the mapping function.
|
||||||
// values of variables.
|
func DoReplacements(input string, mapping MappingFunc) interface{} {
|
||||||
func Expand(input string, mapping func(string) interface{}) interface{} {
|
var buf strings.Builder
|
||||||
var buf bytes.Buffer
|
|
||||||
checkpoint := 0
|
checkpoint := 0
|
||||||
for cursor := 0; cursor < len(input); cursor++ {
|
for cursor := 0; cursor < len(input); cursor++ {
|
||||||
if input[cursor] == operator && cursor+1 < len(input) {
|
if input[cursor] == operator && cursor+1 < len(input) {
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
// Copyright 2019 The Kubernetes Authors.
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package expansion_test
|
package refvar_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
"github.com/stretchr/testify/assert"
|
||||||
|
. "sigs.k8s.io/kustomize/api/filters/refvar"
|
||||||
)
|
)
|
||||||
|
|
||||||
type expected struct {
|
type expected struct {
|
||||||
@@ -15,6 +16,48 @@ type expected struct {
|
|||||||
edited string
|
edited string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrimitiveReplacer(t *testing.T) {
|
||||||
|
varCounts := make(map[string]int)
|
||||||
|
f := MakePrimitiveReplacer(
|
||||||
|
varCounts,
|
||||||
|
map[string]interface{}{
|
||||||
|
"FOO": "bar",
|
||||||
|
"ZOO": "$(FOO)-1",
|
||||||
|
"BLU": "$(ZOO)-2",
|
||||||
|
"EIGHT": 8,
|
||||||
|
"PI": 3.14159,
|
||||||
|
"ZINT": "$(INT)",
|
||||||
|
"BOOL": "true",
|
||||||
|
"HUGENUMBER": int64(9223372036854775807),
|
||||||
|
"CRAZYMAP": map[string]int{"crazy": 200},
|
||||||
|
"ZBOOL": "$(BOOL)",
|
||||||
|
})
|
||||||
|
assert.Equal(t, "$()", f(""))
|
||||||
|
assert.Equal(t, "$( )", f(" "))
|
||||||
|
assert.Equal(t, "$(florida)", f("florida"))
|
||||||
|
assert.Equal(t, "$(0)", f("0"))
|
||||||
|
assert.Equal(t, "bar", f("FOO"))
|
||||||
|
assert.Equal(t, "bar", f("FOO"))
|
||||||
|
assert.Equal(t, "bar", f("FOO"))
|
||||||
|
assert.Equal(t, 8, f("EIGHT"))
|
||||||
|
assert.Equal(t, 8, f("EIGHT"))
|
||||||
|
assert.Equal(t, 3.14159, f("PI"))
|
||||||
|
assert.Equal(t, "true", f("BOOL"))
|
||||||
|
assert.Equal(t, int64(9223372036854775807), f("HUGENUMBER"))
|
||||||
|
assert.Equal(t, "$(FOO)-1", f("ZOO"))
|
||||||
|
assert.Equal(t, "$(CRAZYMAP)", f("CRAZYMAP"))
|
||||||
|
assert.Equal(t,
|
||||||
|
map[string]int{
|
||||||
|
"FOO": 3,
|
||||||
|
"EIGHT": 2,
|
||||||
|
"BOOL": 1,
|
||||||
|
"PI": 1,
|
||||||
|
"ZOO": 1,
|
||||||
|
"HUGENUMBER": 1,
|
||||||
|
},
|
||||||
|
varCounts)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMapReference(t *testing.T) {
|
func TestMapReference(t *testing.T) {
|
||||||
type env struct {
|
type env struct {
|
||||||
Name string
|
Name string
|
||||||
@@ -51,7 +94,7 @@ func TestMapReference(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
declaredEnv := map[string]interface{}{
|
varMap := map[string]interface{}{
|
||||||
"FOO": "bar",
|
"FOO": "bar",
|
||||||
"ZOO": "$(FOO)-1",
|
"ZOO": "$(FOO)-1",
|
||||||
"BLU": "$(ZOO)-2",
|
"BLU": "$(ZOO)-2",
|
||||||
@@ -61,11 +104,11 @@ func TestMapReference(t *testing.T) {
|
|||||||
"ZBOOL": "$(BOOL)",
|
"ZBOOL": "$(BOOL)",
|
||||||
}
|
}
|
||||||
|
|
||||||
counts := make(map[string]int)
|
varCounts := make(map[string]int)
|
||||||
mapping := MappingFuncFor(counts, declaredEnv)
|
|
||||||
|
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
declaredEnv[env.Name] = Expand(fmt.Sprintf("%v", env.Value), mapping)
|
varMap[env.Name] = DoReplacements(
|
||||||
|
fmt.Sprintf("%v", env.Value),
|
||||||
|
MakePrimitiveReplacer(varCounts, varMap))
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedEnv := map[string]expected{
|
expectedEnv := map[string]expected{
|
||||||
@@ -79,45 +122,20 @@ func TestMapReference(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range expectedEnv {
|
for k, v := range expectedEnv {
|
||||||
if e, a := v, declaredEnv[k]; e.edited != a || e.count != counts[k] {
|
if e, a := v, varMap[k]; e.edited != a || e.count != varCounts[k] {
|
||||||
t.Errorf("Expected %v count=%d, got %v count=%d",
|
t.Errorf("Expected %v count=%d, got %v count=%d",
|
||||||
e.edited, e.count, a, counts[k])
|
e.edited, e.count, a, varCounts[k])
|
||||||
} else {
|
} else {
|
||||||
delete(declaredEnv, k)
|
delete(varMap, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(declaredEnv) != 0 {
|
if len(varMap) != 0 {
|
||||||
t.Errorf("Unexpected keys in declared env: %v", declaredEnv)
|
t.Errorf("Unexpected keys in declared env: %v", varMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMapping(t *testing.T) {
|
func TestMapping(t *testing.T) {
|
||||||
context := map[string]interface{}{
|
|
||||||
"VAR_A": "A",
|
|
||||||
"VAR_B": "B",
|
|
||||||
"VAR_C": "C",
|
|
||||||
"VAR_REF": "$(VAR_A)",
|
|
||||||
"VAR_EMPTY": "",
|
|
||||||
}
|
|
||||||
doExpansionTest(t, context)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMappingDual(t *testing.T) {
|
|
||||||
context := map[string]interface{}{
|
|
||||||
"VAR_A": "A",
|
|
||||||
"VAR_EMPTY": "",
|
|
||||||
}
|
|
||||||
context2 := map[string]interface{}{
|
|
||||||
"VAR_B": "B",
|
|
||||||
"VAR_C": "C",
|
|
||||||
"VAR_REF": "$(VAR_A)",
|
|
||||||
}
|
|
||||||
|
|
||||||
doExpansionTest(t, context, context2)
|
|
||||||
}
|
|
||||||
|
|
||||||
func doExpansionTest(t *testing.T, context ...map[string]interface{}) {
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
input string
|
input string
|
||||||
@@ -333,11 +351,17 @@ func doExpansionTest(t *testing.T, context ...map[string]interface{}) {
|
|||||||
expected: "\n",
|
expected: "\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
counts := make(map[string]int)
|
counts := make(map[string]int)
|
||||||
mapping := MappingFuncFor(counts, context...)
|
expanded := DoReplacements(
|
||||||
expanded := Expand(fmt.Sprintf("%v", tc.input), mapping)
|
fmt.Sprintf("%v", tc.input),
|
||||||
|
MakePrimitiveReplacer(counts, map[string]interface{}{
|
||||||
|
"VAR_A": "A",
|
||||||
|
"VAR_B": "B",
|
||||||
|
"VAR_C": "C",
|
||||||
|
"VAR_REF": "$(VAR_A)",
|
||||||
|
"VAR_EMPTY": "",
|
||||||
|
}))
|
||||||
if e, a := tc.expected, expanded; e != a {
|
if e, a := tc.expected, expanded; e != a {
|
||||||
t.Errorf("%v: expected %q, got %q", tc.name, e, a)
|
t.Errorf("%v: expected %q, got %q", tc.name, e, a)
|
||||||
}
|
}
|
||||||
@@ -347,8 +371,7 @@ func doExpansionTest(t *testing.T, context ...map[string]interface{}) {
|
|||||||
}
|
}
|
||||||
if len(tc.counts) > 0 {
|
if len(tc.counts) > 0 {
|
||||||
for k, expectedCount := range tc.counts {
|
for k, expectedCount := range tc.counts {
|
||||||
c, ok := counts[k]
|
if c, ok := counts[k]; ok {
|
||||||
if ok {
|
|
||||||
if c != expectedCount {
|
if c != expectedCount {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"%v: k=%s, expected count %d, got %d",
|
"%v: k=%s, expected count %d, got %d",
|
||||||
@@ -8,15 +8,13 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
|
|
||||||
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Filter updates $(VAR) style variables with values.
|
// Filter updates $(VAR) style variables with values.
|
||||||
// The fieldSpecs are the places to look for occurrences of $(VAR).
|
// The fieldSpecs are the places to look for occurrences of $(VAR).
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
MappingFunc func(string) interface{} `json:"mappingFunc,omitempty" yaml:"mappingFunc,omitempty"`
|
MappingFunc MappingFunc `json:"mappingFunc,omitempty" yaml:"mappingFunc,omitempty"`
|
||||||
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||||
@@ -49,12 +47,21 @@ func (f Filter) set(node *yaml.RNode) error {
|
|||||||
|
|
||||||
func updateNodeValue(node *yaml.Node, newValue interface{}) {
|
func updateNodeValue(node *yaml.Node, newValue interface{}) {
|
||||||
switch newValue := newValue.(type) {
|
switch newValue := newValue.(type) {
|
||||||
|
case int:
|
||||||
|
node.Value = strconv.FormatInt(int64(newValue), 10)
|
||||||
|
node.Tag = yaml.NodeTagInt
|
||||||
|
case int32:
|
||||||
|
node.Value = strconv.FormatInt(int64(newValue), 10)
|
||||||
|
node.Tag = yaml.NodeTagInt
|
||||||
case int64:
|
case int64:
|
||||||
node.Value = strconv.FormatInt(newValue, 10)
|
node.Value = strconv.FormatInt(newValue, 10)
|
||||||
node.Tag = yaml.NodeTagInt
|
node.Tag = yaml.NodeTagInt
|
||||||
case bool:
|
case bool:
|
||||||
node.SetString(strconv.FormatBool(newValue))
|
node.SetString(strconv.FormatBool(newValue))
|
||||||
node.Tag = yaml.NodeTagBool
|
node.Tag = yaml.NodeTagBool
|
||||||
|
case float32:
|
||||||
|
node.SetString(strconv.FormatFloat(float64(newValue), 'f', -1, 32))
|
||||||
|
node.Tag = yaml.NodeTagFloat
|
||||||
case float64:
|
case float64:
|
||||||
node.SetString(strconv.FormatFloat(newValue, 'f', -1, 64))
|
node.SetString(strconv.FormatFloat(newValue, 'f', -1, 64))
|
||||||
node.Tag = yaml.NodeTagFloat
|
node.Tag = yaml.NodeTagFloat
|
||||||
@@ -69,7 +76,7 @@ func (f Filter) setScalar(node *yaml.RNode) error {
|
|||||||
if !yaml.IsYNodeString(node.YNode()) {
|
if !yaml.IsYNodeString(node.YNode()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
v := expansion2.Expand(node.YNode().Value, f.MappingFunc)
|
v := DoReplacements(node.YNode().Value, f.MappingFunc)
|
||||||
updateNodeValue(node.YNode(), v)
|
updateNodeValue(node.YNode(), v)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -78,12 +85,14 @@ func (f Filter) setMap(node *yaml.RNode) error {
|
|||||||
contents := node.YNode().Content
|
contents := node.YNode().Content
|
||||||
for i := 0; i < len(contents); i += 2 {
|
for i := 0; i < len(contents); i += 2 {
|
||||||
if !yaml.IsYNodeString(contents[i]) {
|
if !yaml.IsYNodeString(contents[i]) {
|
||||||
return fmt.Errorf("invalid map key: %s, type: %s", contents[i].Value, contents[i].Tag)
|
return fmt.Errorf(
|
||||||
|
"invalid map key: value='%s', tag='%s'",
|
||||||
|
contents[i].Value, contents[i].Tag)
|
||||||
}
|
}
|
||||||
if !yaml.IsYNodeString(contents[i+1]) {
|
if !yaml.IsYNodeString(contents[i+1]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newValue := expansion2.Expand(contents[i+1].Value, f.MappingFunc)
|
newValue := DoReplacements(contents[i+1].Value, f.MappingFunc)
|
||||||
updateNodeValue(contents[i+1], newValue)
|
updateNodeValue(contents[i+1], newValue)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -94,7 +103,7 @@ func (f Filter) setSeq(node *yaml.RNode) error {
|
|||||||
if !yaml.IsYNodeString(item) {
|
if !yaml.IsYNodeString(item) {
|
||||||
return fmt.Errorf("invalid value type expect a string")
|
return fmt.Errorf("invalid value type expect a string")
|
||||||
}
|
}
|
||||||
newValue := expansion2.Expand(item.Value, f.MappingFunc)
|
newValue := DoReplacements(item.Value, f.MappingFunc)
|
||||||
updateNodeValue(item, newValue)
|
updateNodeValue(item, newValue)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
package refvar
|
package refvar_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
. "sigs.k8s.io/kustomize/api/filters/refvar"
|
||||||
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var makeMf = func(theMap map[string]interface{}) MappingFunc {
|
||||||
|
ignored := make(map[string]int)
|
||||||
|
return MakePrimitiveReplacer(ignored, theMap)
|
||||||
|
}
|
||||||
|
|
||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
replacementCounts := make(map[string]int)
|
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
input string
|
input string
|
||||||
@@ -35,7 +39,7 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
replicas: 5`,
|
replicas: 5`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"VAR": int64(5),
|
"VAR": int64(5),
|
||||||
}),
|
}),
|
||||||
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
||||||
@@ -57,7 +61,7 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
replicas: 1`,
|
replicas: 1`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"VAR": int64(5),
|
"VAR": int64(5),
|
||||||
}),
|
}),
|
||||||
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
|
||||||
@@ -79,7 +83,7 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
replicas: 1`,
|
replicas: 1`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"VAR": int64(5),
|
"VAR": int64(5),
|
||||||
}),
|
}),
|
||||||
FieldSpec: types.FieldSpec{Path: "a/b/c"},
|
FieldSpec: types.FieldSpec{Path: "a/b/c"},
|
||||||
@@ -111,7 +115,7 @@ data:
|
|||||||
- false
|
- false
|
||||||
- 1.23`,
|
- 1.23`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"FOO": "foo",
|
"FOO": "foo",
|
||||||
"BAR": "bar",
|
"BAR": "bar",
|
||||||
"BOOL": false,
|
"BOOL": false,
|
||||||
@@ -142,7 +146,7 @@ data:
|
|||||||
BAZ: $(BAZ)
|
BAZ: $(BAZ)
|
||||||
PLUS: foo+bar`,
|
PLUS: foo+bar`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"FOO": "foo",
|
"FOO": "foo",
|
||||||
"BAR": "bar",
|
"BAR": "bar",
|
||||||
}),
|
}),
|
||||||
@@ -181,7 +185,7 @@ data:
|
|||||||
SLICE:
|
SLICE:
|
||||||
- $(FOO)`,
|
- $(FOO)`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"FOO": "foo",
|
"FOO": "foo",
|
||||||
"BAR": "bar",
|
"BAR": "bar",
|
||||||
}),
|
}),
|
||||||
@@ -204,8 +208,10 @@ metadata:
|
|||||||
data:
|
data:
|
||||||
FOO: null`,
|
FOO: null`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{}),
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
FieldSpec: types.FieldSpec{Path: "data/FOO"},
|
// no replacements!
|
||||||
|
}),
|
||||||
|
FieldSpec: types.FieldSpec{Path: "data/FOO"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -223,8 +229,6 @@ data:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterUnhappy(t *testing.T) {
|
func TestFilterUnhappy(t *testing.T) {
|
||||||
replacementCounts := make(map[string]int)
|
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
input string
|
input string
|
||||||
expectedError string
|
expectedError string
|
||||||
@@ -250,7 +254,7 @@ data:
|
|||||||
- false
|
- false
|
||||||
' at path 'data/slice': invalid value type expect a string`,
|
' at path 'data/slice': invalid value type expect a string`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"VAR": int64(5),
|
"VAR": int64(5),
|
||||||
}),
|
}),
|
||||||
FieldSpec: types.FieldSpec{Path: "data/slice"},
|
FieldSpec: types.FieldSpec{Path: "data/slice"},
|
||||||
@@ -272,9 +276,9 @@ metadata:
|
|||||||
config.kubernetes.io/index: '0'
|
config.kubernetes.io/index: '0'
|
||||||
data:
|
data:
|
||||||
1: str
|
1: str
|
||||||
' at path 'data': invalid map key: 1, type: ` + yaml.NodeTagInt,
|
' at path 'data': invalid map key: value='1', tag='` + yaml.NodeTagInt + `'`,
|
||||||
filter: Filter{
|
filter: Filter{
|
||||||
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
|
MappingFunc: makeMf(map[string]interface{}{
|
||||||
"VAR": int64(5),
|
"VAR": int64(5),
|
||||||
}),
|
}),
|
||||||
FieldSpec: types.FieldSpec{Path: "data"},
|
FieldSpec: types.FieldSpec{Path: "data"},
|
||||||
|
|||||||
@@ -10,16 +10,17 @@ require (
|
|||||||
github.com/google/go-cmp v0.3.0
|
github.com/google/go-cmp v0.3.0
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
github.com/hashicorp/go-multierror v1.1.0
|
github.com/hashicorp/go-multierror v1.1.0
|
||||||
|
github.com/imdario/mergo v0.3.5
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/yujunz/go-getter v1.5.1-lite.0.20201201013212-6d9c071adddf
|
github.com/yujunz/go-getter v1.5.1-lite.0.20201201013212-6d9c071adddf
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
|
||||||
gopkg.in/yaml.v2 v2.3.0
|
gopkg.in/yaml.v2 v2.3.0
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
|
||||||
k8s.io/api v0.17.0
|
k8s.io/api v0.17.0
|
||||||
k8s.io/apimachinery v0.17.0
|
k8s.io/apimachinery v0.17.0
|
||||||
k8s.io/client-go v0.17.0
|
k8s.io/client-go v0.17.0
|
||||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
|
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3
|
sigs.k8s.io/kustomize/kyaml v0.10.6
|
||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
|||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
|
||||||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
@@ -571,8 +572,8 @@ 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.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||||
@@ -598,8 +599,8 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphD
|
|||||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3 h1:ARSJUMN/c3k31DYxRfZ+vp/UepUQjg9zCwny7Oj908I=
|
sigs.k8s.io/kustomize/kyaml v0.10.6 h1:xUJxc/k8JoWqHUahaB8DTqY0KwEPxTbTGStvW8TOcDc=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3/go.mod h1:RA+iCHA2wPCOfv6uG6TfXXWhYsHpgErq/AljxWKuxtg=
|
sigs.k8s.io/kustomize/kyaml v0.10.6/go.mod h1:K9yg1k/HB/6xNOf5VH3LhTo1DK9/5ykSZO5uIv+Y/1k=
|
||||||
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-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
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 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ type Kunstructured interface {
|
|||||||
// Several uses.
|
// Several uses.
|
||||||
Copy() Kunstructured
|
Copy() Kunstructured
|
||||||
|
|
||||||
// Used by Resource.Replace, which in turn is used in many places, e.g.
|
// GetAnnotations returns the k8s annotations.
|
||||||
// - resource.Resource.Merge
|
|
||||||
// - resWrangler.appendReplaceOrMerge (AbsorbAll)
|
|
||||||
// - api.internal.k8sdeps.transformer.patch.conflictdetector
|
|
||||||
GetAnnotations() map[string]string
|
GetAnnotations() map[string]string
|
||||||
|
|
||||||
|
// GetData returns a top-level "data" field, as in a ConfigMap.
|
||||||
|
GetDataMap() map[string]string
|
||||||
|
|
||||||
// Used by ResAccumulator and ReplacementTransformer.
|
// Used by ResAccumulator and ReplacementTransformer.
|
||||||
GetFieldValue(string) (interface{}, error)
|
GetFieldValue(string) (interface{}, error)
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ type Kunstructured interface {
|
|||||||
// Used by resource.Factory.SliceFromBytes
|
// Used by resource.Factory.SliceFromBytes
|
||||||
GetKind() string
|
GetKind() string
|
||||||
|
|
||||||
// Used by Resource.Replace
|
// GetLabels returns the k8s labels.
|
||||||
GetLabels() map[string]string
|
GetLabels() map[string]string
|
||||||
|
|
||||||
// Used by Resource.CurId and resource factory.
|
// Used by Resource.CurId and resource factory.
|
||||||
@@ -84,19 +84,22 @@ type Kunstructured interface {
|
|||||||
// Used by resWrangler.Select
|
// Used by resWrangler.Select
|
||||||
MatchesLabelSelector(selector string) (bool, error)
|
MatchesLabelSelector(selector string) (bool, error)
|
||||||
|
|
||||||
// Used by Resource.Replace.
|
// SetAnnotations replaces the k8s annotations.
|
||||||
SetAnnotations(map[string]string)
|
SetAnnotations(map[string]string)
|
||||||
|
|
||||||
|
// SetDataMap sets a top-level "data" field, as in a ConfigMap.
|
||||||
|
SetDataMap(map[string]string)
|
||||||
|
|
||||||
// Used by PatchStrategicMergeTransformer.
|
// Used by PatchStrategicMergeTransformer.
|
||||||
SetGvk(resid.Gvk)
|
SetGvk(resid.Gvk)
|
||||||
|
|
||||||
// Used by Resource.Replace and used to remove "validated by" labels.
|
// SetLabels replaces the k8s labels.
|
||||||
SetLabels(map[string]string)
|
SetLabels(map[string]string)
|
||||||
|
|
||||||
// Used by Resource.Replace.
|
// SetName changes the name.
|
||||||
SetName(string)
|
SetName(string)
|
||||||
|
|
||||||
// Used by Resource.Replace.
|
// SetNamespace changes the namespace.
|
||||||
SetNamespace(string)
|
SetNamespace(string)
|
||||||
|
|
||||||
// Needed, for now, by kyaml/filtersutil.ApplyToJSON.
|
// Needed, for now, by kyaml/filtersutil.ApplyToJSON.
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/filters/nameref"
|
"sigs.k8s.io/kustomize/api/filters/nameref"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type nameReferenceTransformer struct {
|
type nameReferenceTransformer struct {
|
||||||
@@ -20,7 +19,8 @@ var _ resmap.Transformer = &nameReferenceTransformer{}
|
|||||||
|
|
||||||
// newNameReferenceTransformer constructs a nameReferenceTransformer
|
// newNameReferenceTransformer constructs a nameReferenceTransformer
|
||||||
// with a given slice of NameBackReferences.
|
// with a given slice of NameBackReferences.
|
||||||
func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.Transformer {
|
func newNameReferenceTransformer(
|
||||||
|
br []builtinconfig.NameBackReferences) resmap.Transformer {
|
||||||
if br == nil {
|
if br == nil {
|
||||||
log.Fatal("backrefs not expected to be nil")
|
log.Fatal("backrefs not expected to be nil")
|
||||||
}
|
}
|
||||||
@@ -29,17 +29,17 @@ func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.T
|
|||||||
|
|
||||||
// Transform updates name references in resource A that
|
// Transform updates name references in resource A that
|
||||||
// refer to resource B, given that B's name may have
|
// refer to resource B, given that B's name may have
|
||||||
// changed.
|
// changed. A is the referrer, B is the referralTarget.
|
||||||
//
|
//
|
||||||
// For example, a HorizontalPodAutoscaler (HPA)
|
// For example, a HorizontalPodAutoscaler (HPA)
|
||||||
// necessarily refers to a Deployment, the thing that
|
// necessarily refers to a Deployment, the thing that
|
||||||
// the HPA scales. The Deployment name might change
|
// the HPA scales. The Deployment's name might change
|
||||||
// (e.g. prefix added), and the reference in the HPA
|
// (e.g. prefix added), and the reference in the HPA
|
||||||
// has to be fixed.
|
// has to be fixed.
|
||||||
//
|
//
|
||||||
// In the outer loop over the ResMap below, say we
|
// In the outer loop over the ResMap below, say we
|
||||||
// encounter a specific HPA. Then, in scanning backrefs,
|
// encounter a specific HPA. Then, in scanning the set
|
||||||
// we encounter an entry like
|
// of all known backrefs, we encounter an entry like
|
||||||
//
|
//
|
||||||
// - kind: Deployment
|
// - kind: Deployment
|
||||||
// fieldSpecs:
|
// fieldSpecs:
|
||||||
@@ -74,22 +74,32 @@ func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.T
|
|||||||
// Name transformers should only modify the name in the
|
// Name transformers should only modify the name in the
|
||||||
// body of the resource object (the value in the ResMap).
|
// body of the resource object (the value in the ResMap).
|
||||||
//
|
//
|
||||||
func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
func (t *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
||||||
// TODO: Too much looping, here and in transitive calls.
|
// TODO: Too much looping, here and in transitive calls.
|
||||||
for _, referrer := range m.Resources() {
|
for _, referrer := range m.Resources() {
|
||||||
var candidates resmap.ResMap
|
var candidates resmap.ResMap
|
||||||
for _, target := range o.backRefs {
|
for _, referralTarget := range t.backRefs {
|
||||||
for _, fSpec := range target.FieldSpecs {
|
for _, fSpec := range referralTarget.FieldSpecs {
|
||||||
if referrer.OrgId().IsSelected(&fSpec.Gvk) {
|
if referrer.OrgId().IsSelected(&fSpec.Gvk) {
|
||||||
if candidates == nil {
|
if candidates == nil {
|
||||||
|
// This excludes objects from other namespaces.
|
||||||
|
// In most realistic uses, it returns all elements of m,
|
||||||
|
// (since they're all in the same namespace).
|
||||||
candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
|
candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
|
||||||
}
|
}
|
||||||
err := filtersutil.ApplyToJSON(nameref.Filter{
|
// One way to get here is with, say, a referrer that's an
|
||||||
FieldSpec: fSpec,
|
// HPA, and a target that's a Deployment (one of the
|
||||||
|
// Deployment's fieldSpecs selects an HPA). Now we look
|
||||||
|
// through the candidates to see if one is a Deployment
|
||||||
|
// (the target), and if so, get the Deployment's name and
|
||||||
|
// write it into the referrer, at the field specfied in
|
||||||
|
// fSpec.
|
||||||
|
err := referrer.ApplyFilter(nameref.Filter{
|
||||||
Referrer: referrer,
|
Referrer: referrer,
|
||||||
Target: target.Gvk,
|
NameFieldToUpdate: fSpec,
|
||||||
|
ReferralTarget: referralTarget.Gvk,
|
||||||
ReferralCandidates: candidates,
|
ReferralCandidates: candidates,
|
||||||
}, referrer)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ func TestNameReferenceHappyRun(t *testing.T) {
|
|||||||
"secret1",
|
"secret1",
|
||||||
"secret1",
|
"secret1",
|
||||||
"secret2",
|
"secret2",
|
||||||
|
"cm1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -420,6 +421,7 @@ func TestNameReferenceHappyRun(t *testing.T) {
|
|||||||
"someprefix-secret1-somehash",
|
"someprefix-secret1-somehash",
|
||||||
"someprefix-secret1-somehash",
|
"someprefix-secret1-somehash",
|
||||||
"secret2",
|
"secret2",
|
||||||
|
"someprefix-cm1-somehash",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -719,6 +721,7 @@ func TestNameReferenceNamespace(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||||
t.Fatalf("actual doesn't match expected: %v", err)
|
t.Fatalf("actual doesn't match expected: %v", err)
|
||||||
}
|
}
|
||||||
@@ -880,6 +883,7 @@ func TestNameReferenceClusterWide(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||||
t.Fatalf("actual doesn't match expected: %v", err)
|
t.Fatalf("actual doesn't match expected: %v", err)
|
||||||
}
|
}
|
||||||
@@ -1006,6 +1010,7 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||||
t.Fatalf("actual doesn't match expected: %v", err)
|
t.Fatalf("actual doesn't match expected: %v", err)
|
||||||
}
|
}
|
||||||
@@ -1042,6 +1047,7 @@ func TestNameReferenceCandidateSelection(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
if err = expected.ErrorIfNotEqualLists(m); err != nil {
|
||||||
t.Fatalf("actual doesn't match expected: %v", err)
|
t.Fatalf("actual doesn't match expected: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,15 @@
|
|||||||
package accumulator
|
package accumulator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
|
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/refvar"
|
"sigs.k8s.io/kustomize/api/filters/refvar"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type refVarTransformer struct {
|
type refVarTransformer struct {
|
||||||
varMap map[string]interface{}
|
varMap map[string]interface{}
|
||||||
replacementCounts map[string]int
|
replacementCounts map[string]int
|
||||||
fieldSpecs []types.FieldSpec
|
fieldSpecs []types.FieldSpec
|
||||||
mappingFunc func(string) interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRefVarTransformer returns a new refVarTransformer
|
// newRefVarTransformer returns a new refVarTransformer
|
||||||
@@ -35,8 +31,7 @@ func newRefVarTransformer(
|
|||||||
func (rv *refVarTransformer) UnusedVars() []string {
|
func (rv *refVarTransformer) UnusedVars() []string {
|
||||||
var unused []string
|
var unused []string
|
||||||
for k := range rv.varMap {
|
for k := range rv.varMap {
|
||||||
_, ok := rv.replacementCounts[k]
|
if _, ok := rv.replacementCounts[k]; !ok {
|
||||||
if !ok {
|
|
||||||
unused = append(unused, k)
|
unused = append(unused, k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,14 +41,13 @@ func (rv *refVarTransformer) UnusedVars() []string {
|
|||||||
// Transform replaces $(VAR) style variables with values.
|
// Transform replaces $(VAR) style variables with values.
|
||||||
func (rv *refVarTransformer) Transform(m resmap.ResMap) error {
|
func (rv *refVarTransformer) Transform(m resmap.ResMap) error {
|
||||||
rv.replacementCounts = make(map[string]int)
|
rv.replacementCounts = make(map[string]int)
|
||||||
rv.mappingFunc = expansion2.MappingFuncFor(
|
mf := refvar.MakePrimitiveReplacer(rv.replacementCounts, rv.varMap)
|
||||||
rv.replacementCounts, rv.varMap)
|
|
||||||
for _, res := range m.Resources() {
|
for _, res := range m.Resources() {
|
||||||
for _, fieldSpec := range rv.fieldSpecs {
|
for _, fieldSpec := range rv.fieldSpecs {
|
||||||
err := filtersutil.ApplyToJSON(refvar.Filter{
|
err := res.ApplyFilter(refvar.Filter{
|
||||||
MappingFunc: rv.mappingFunc,
|
MappingFunc: mf,
|
||||||
FieldSpec: fieldSpec,
|
FieldSpec: fieldSpec,
|
||||||
}, res)
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
resmaptest_test "sigs.k8s.io/kustomize/api/testutils/resmaptest"
|
resmaptest_test "sigs.k8s.io/kustomize/api/testutils/resmaptest"
|
||||||
@@ -123,8 +124,19 @@ func TestRefVarTransformer(t *testing.T) {
|
|||||||
"slice": []interface{}{5}, // noticeably *not* a []string
|
"slice": []interface{}{5}, // noticeably *not* a []string
|
||||||
}}).ResMap(),
|
}}).ResMap(),
|
||||||
},
|
},
|
||||||
errMessage: `obj '{"apiVersion": "v1", "data": {"slice": [5]}, "kind": "ConfigMap", "metadata": {"name": "cm1"}}
|
// TODO(#3304): DECISION - kyaml better; not a bug.
|
||||||
|
errMessage: konfig.IfApiMachineryElseKyaml(
|
||||||
|
`obj '{"apiVersion": "v1", "data": {"slice": [5]}, "kind": "ConfigMap", "metadata": {"name": "cm1"}}
|
||||||
' at path 'data/slice': invalid value type expect a string`,
|
' at path 'data/slice': invalid value type expect a string`,
|
||||||
|
`obj 'apiVersion: v1
|
||||||
|
data:
|
||||||
|
slice:
|
||||||
|
- 5
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: cm1
|
||||||
|
' at path 'data/slice': invalid value type expect a string`,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "var replacement in nil",
|
description: "var replacement in nil",
|
||||||
|
|||||||
@@ -41,13 +41,11 @@ func (ra *ResAccumulator) Vars() []types.Var {
|
|||||||
return ra.varSet.AsSlice()
|
return ra.varSet.AsSlice()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ra *ResAccumulator) AppendAll(
|
func (ra *ResAccumulator) AppendAll(resources resmap.ResMap) error {
|
||||||
resources resmap.ResMap) error {
|
|
||||||
return ra.resMap.AppendAll(resources)
|
return ra.resMap.AppendAll(resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ra *ResAccumulator) AbsorbAll(
|
func (ra *ResAccumulator) AbsorbAll(resources resmap.ResMap) error {
|
||||||
resources resmap.ResMap) error {
|
|
||||||
return ra.resMap.AbsorbAll(resources)
|
return ra.resMap.AbsorbAll(resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +59,15 @@ func (ra *ResAccumulator) GetTransformerConfig() *builtinconfig.TransformerConfi
|
|||||||
return ra.tConfig
|
return ra.tConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MergeVars accumulates vars into ResAccumulator.
|
||||||
|
// A Var is a tuple of name, object reference and field reference.
|
||||||
|
// This func takes a list of vars from the current kustomization file and
|
||||||
|
// annotates the accumulated resources with the names of the vars that match
|
||||||
|
// those resources. E.g. if there's a var named "sam" that wants to get
|
||||||
|
// its data from a ConfigMap named "james", and the resource list contains a
|
||||||
|
// ConfigMap named "james", then that ConfigMap will be annotated with the
|
||||||
|
// var name "sam". Later this annotation is used to find the data for "sam"
|
||||||
|
// by digging into a particular fieldpath of "james".
|
||||||
func (ra *ResAccumulator) MergeVars(incoming []types.Var) error {
|
func (ra *ResAccumulator) MergeVars(incoming []types.Var) error {
|
||||||
for _, v := range incoming {
|
for _, v := range incoming {
|
||||||
targetId := resid.NewResIdWithNamespace(v.ObjRef.GVK(), v.ObjRef.Name, v.ObjRef.Namespace)
|
targetId := resid.NewResIdWithNamespace(v.ObjRef.GVK(), v.ObjRef.Name, v.ObjRef.Namespace)
|
||||||
@@ -106,12 +113,10 @@ func (ra *ResAccumulator) findVarValueFromResources(v types.Var) (interface{}, e
|
|||||||
"field specified in var '%v' "+
|
"field specified in var '%v' "+
|
||||||
"not found in corresponding resource", v)
|
"not found in corresponding resource", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf(
|
return "", fmt.Errorf(
|
||||||
"var '%v' cannot be mapped to a field "+
|
"var '%v' cannot be mapped to a field "+
|
||||||
"in the set of known resources", v)
|
"in the set of known resources", v)
|
||||||
@@ -127,10 +132,8 @@ func (ra *ResAccumulator) makeVarReplacementMap() (map[string]interface{}, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result[v.Name] = s
|
result[v.Name] = s
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +164,6 @@ func (ra *ResAccumulator) FixBackReferences() (err error) {
|
|||||||
if ra.tConfig.NameReference == nil {
|
if ra.tConfig.NameReference == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ra.Transform(newNameReferenceTransformer(
|
return ra.Transform(
|
||||||
ra.tConfig.NameReference))
|
newNameReferenceTransformer(ra.tConfig.NameReference))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -355,7 +355,8 @@ func TestResolveVarsWithNoambiguation(t *testing.T) {
|
|||||||
// went through a prefix transformer.
|
// went through a prefix transformer.
|
||||||
r := m.GetByIndex(1)
|
r := m.GetByIndex(1)
|
||||||
r.AddNamePrefix("sub-")
|
r.AddNamePrefix("sub-")
|
||||||
r.SetName("sub-backendOne") // original name remains "backendOne"
|
r.SetName("sub-backendOne")
|
||||||
|
r.SetOriginalName("backendOne", true)
|
||||||
|
|
||||||
err = ra2.AppendAll(m)
|
err = ra2.AppendAll(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ func (c *smPatchMergeOnlyDetector) HasConflict(
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There's at least one case that doesn't work. Suppose one has a
|
||||||
|
// Deployment with a volume with the bizarre "emptyDir: {}" entry.
|
||||||
|
// If you want to get rid of this entry via a patch containing
|
||||||
|
// the entry "emptyDir: null", then the following won't work,
|
||||||
|
// because null entries are eliminated.
|
||||||
func (c *smPatchMergeOnlyDetector) MergePatches(
|
func (c *smPatchMergeOnlyDetector) MergePatches(
|
||||||
r, patch *resource.Resource) (*resource.Resource, error) {
|
r, patch *resource.Resource) (*resource.Resource, error) {
|
||||||
err := r.ApplySmPatch(patch)
|
err := r.ApplySmPatch(patch)
|
||||||
|
|||||||
@@ -220,6 +220,7 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
|||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
|
||||||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||||
@@ -511,8 +512,8 @@ 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.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
@@ -533,8 +534,8 @@ k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl
|
|||||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
||||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3 h1:ARSJUMN/c3k31DYxRfZ+vp/UepUQjg9zCwny7Oj908I=
|
sigs.k8s.io/kustomize/kyaml v0.10.6 h1:xUJxc/k8JoWqHUahaB8DTqY0KwEPxTbTGStvW8TOcDc=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3/go.mod h1:RA+iCHA2wPCOfv6uG6TfXXWhYsHpgErq/AljxWKuxtg=
|
sigs.k8s.io/kustomize/kyaml v0.10.6/go.mod h1:K9yg1k/HB/6xNOf5VH3LhTo1DK9/5ykSZO5uIv+Y/1k=
|
||||||
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-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
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.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package generators
|
package generators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
@@ -38,14 +37,9 @@ func MakeConfigMap(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, k := range filtersutil.SortedMapKeys(m) {
|
if err = rn.LoadMapIntoConfigMapData(m); err != nil {
|
||||||
fldName, vrN := makeConfigMapValueRNode(m[k])
|
return nil, err
|
||||||
if _, err = rn.Pipe(
|
|
||||||
yaml.LookupCreate(yaml.MappingNode, fldName),
|
|
||||||
yaml.SetField(k, vrN)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
copyLabelsAndAnnotations(rn, args.Options)
|
copyLabelsAndAnnotations(rn, args.Options)
|
||||||
return rn, err
|
return rn, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
package generators
|
package generators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
@@ -37,24 +36,23 @@ func MakeSecret(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
t := "Opaque"
|
||||||
|
if args.Type != "" {
|
||||||
|
t = args.Type
|
||||||
|
}
|
||||||
if _, err := rn.Pipe(
|
if _, err := rn.Pipe(
|
||||||
yaml.FieldSetter{
|
yaml.FieldSetter{
|
||||||
Name: "type",
|
Name: "type",
|
||||||
Value: yaml.NewStringRNode("Opaque")}); err != nil {
|
Value: yaml.NewStringRNode(t)}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m, err := makeValidatedDataMap(ldr, args.Name, args.KvPairSources)
|
m, err := makeValidatedDataMap(ldr, args.Name, args.KvPairSources)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, k := range filtersutil.SortedMapKeys(m) {
|
if err = rn.LoadMapIntoSecretData(m); err != nil {
|
||||||
vrN := makeSecretValueRNode(m[k])
|
return nil, err
|
||||||
if _, err = rn.Pipe(
|
|
||||||
yaml.LookupCreate(yaml.MappingNode, yaml.DataField),
|
|
||||||
yaml.SetField(k, vrN)); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
copyLabelsAndAnnotations(rn, args.Options)
|
copyLabelsAndAnnotations(rn, args.Options)
|
||||||
return rn, err
|
return rn, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,34 @@ data:
|
|||||||
b: eQ==
|
b: eQ==
|
||||||
c: SGVsbG8gV29ybGQ=
|
c: SGVsbG8gV29ybGQ=
|
||||||
d: dHJ1ZQ==
|
d: dHJ1ZQ==
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"construct secret with type": {
|
||||||
|
args: types.SecretArgs{
|
||||||
|
GeneratorArgs: types.GeneratorArgs{
|
||||||
|
Name: "literalSecret1",
|
||||||
|
KvPairSources: types.KvPairSources{
|
||||||
|
LiteralSources: []string{"a=x"},
|
||||||
|
},
|
||||||
|
Options: &types.GeneratorOptions{
|
||||||
|
Labels: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Type: "foobar",
|
||||||
|
},
|
||||||
|
exp: expected{
|
||||||
|
out: `apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: literalSecret1
|
||||||
|
labels:
|
||||||
|
foo: 'bar'
|
||||||
|
type: foobar
|
||||||
|
data:
|
||||||
|
a: eA==
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,13 +4,9 @@
|
|||||||
package generators
|
package generators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"sigs.k8s.io/kustomize/api/filters/filtersutil"
|
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
@@ -66,13 +62,13 @@ func copyLabelsAndAnnotations(
|
|||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, k := range filtersutil.SortedMapKeys(opts.Labels) {
|
for _, k := range yaml.SortedMapKeys(opts.Labels) {
|
||||||
v := opts.Labels[k]
|
v := opts.Labels[k]
|
||||||
if _, err := rn.Pipe(yaml.SetLabel(k, v)); err != nil {
|
if _, err := rn.Pipe(yaml.SetLabel(k, v)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, k := range filtersutil.SortedMapKeys(opts.Annotations) {
|
for _, k := range yaml.SortedMapKeys(opts.Annotations) {
|
||||||
v := opts.Annotations[k]
|
v := opts.Annotations[k]
|
||||||
if _, err := rn.Pipe(yaml.SetAnnotation(k, v)); err != nil {
|
if _, err := rn.Pipe(yaml.SetAnnotation(k, v)); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -80,60 +76,3 @@ func copyLabelsAndAnnotations(
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// In a secret, all data is base64 encoded, regardless of its conformance
|
|
||||||
// or lack thereof to UTF-8.
|
|
||||||
func makeSecretValueRNode(s string) *yaml.RNode {
|
|
||||||
yN := &yaml.Node{Kind: yaml.ScalarNode}
|
|
||||||
// Purposely don't use YAML tags to identify the data as being plain text or
|
|
||||||
// binary. It kubernetes Secrets the values in the `data` map are expected
|
|
||||||
// to be base64 encoded, and in ConfigMaps that same can be said for the
|
|
||||||
// values in the `binaryData` field.
|
|
||||||
yN.Tag = yaml.NodeTagString
|
|
||||||
yN.Value = encodeBase64(s)
|
|
||||||
if strings.Contains(yN.Value, "\n") {
|
|
||||||
yN.Style = yaml.LiteralStyle
|
|
||||||
}
|
|
||||||
return yaml.NewRNode(yN)
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeConfigMapValueRNode(s string) (field string, rN *yaml.RNode) {
|
|
||||||
yN := &yaml.Node{Kind: yaml.ScalarNode}
|
|
||||||
yN.Tag = yaml.NodeTagString
|
|
||||||
if utf8.ValidString(s) {
|
|
||||||
field = yaml.DataField
|
|
||||||
yN.Value = s
|
|
||||||
} else {
|
|
||||||
field = yaml.BinaryDataField
|
|
||||||
yN.Value = encodeBase64(s)
|
|
||||||
}
|
|
||||||
if strings.Contains(yN.Value, "\n") {
|
|
||||||
yN.Style = yaml.LiteralStyle
|
|
||||||
}
|
|
||||||
return field, yaml.NewRNode(yN)
|
|
||||||
}
|
|
||||||
|
|
||||||
// encodeBase64 encodes s as base64 that is broken up into multiple lines
|
|
||||||
// as appropriate for the resulting length.
|
|
||||||
func encodeBase64(s string) string {
|
|
||||||
const lineLen = 70
|
|
||||||
encLen := base64.StdEncoding.EncodedLen(len(s))
|
|
||||||
lines := encLen/lineLen + 1
|
|
||||||
buf := make([]byte, encLen*2+lines)
|
|
||||||
in := buf[0:encLen]
|
|
||||||
out := buf[encLen:]
|
|
||||||
base64.StdEncoding.Encode(in, []byte(s))
|
|
||||||
k := 0
|
|
||||||
for i := 0; i < len(in); i += lineLen {
|
|
||||||
j := i + lineLen
|
|
||||||
if j > len(in) {
|
|
||||||
j = len(in)
|
|
||||||
}
|
|
||||||
k += copy(out[k:], in[i:j])
|
|
||||||
if lines > 1 {
|
|
||||||
out[k] = '\n'
|
|
||||||
k++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(out[:k])
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Arbitrary, but non-infinite, timeout for running commands.
|
// Arbitrary, but non-infinite, timeout for running commands.
|
||||||
@@ -41,25 +41,18 @@ func newCmdRunner() (*gitRunner, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run a command with a timeout.
|
// run a command with a timeout.
|
||||||
func (r gitRunner) run(args ...string) (err error) {
|
func (r gitRunner) run(args ...string) error {
|
||||||
ch := make(chan bool, 1)
|
|
||||||
defer close(ch)
|
|
||||||
//nolint: gosec
|
//nolint: gosec
|
||||||
cmd := exec.Command(r.gitProgram, args...)
|
cmd := exec.Command(r.gitProgram, args...)
|
||||||
cmd.Dir = r.dir.String()
|
cmd.Dir = r.dir.String()
|
||||||
timer := time.NewTimer(r.duration)
|
return utils.TimedCall(
|
||||||
defer timer.Stop()
|
cmd.String(),
|
||||||
go func() {
|
r.duration,
|
||||||
_, err = cmd.CombinedOutput()
|
func() error {
|
||||||
ch <- true
|
_, err := cmd.CombinedOutput()
|
||||||
}()
|
if err != nil {
|
||||||
select {
|
return errors.Wrapf(err, "git cmd = '%s'", cmd.String())
|
||||||
case <-ch:
|
}
|
||||||
if err != nil {
|
return err
|
||||||
return errors.Wrapf(err, "git cmd = '%s'", cmd.String())
|
})
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case <-timer.C:
|
|
||||||
return types.NewErrTimeOut(r.duration, cmd.String())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ s/$BAR/bar baz/g
|
|||||||
"argsFromFile": "sed-input.txt",
|
"argsFromFile": "sed-input.txt",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pluginConfig.RemoveBuildAnnotations()
|
||||||
p := NewExecPlugin(
|
p := NewExecPlugin(
|
||||||
pLdr.AbsolutePluginPath(
|
pLdr.AbsolutePluginPath(
|
||||||
konfig.DisabledPluginConfig(),
|
konfig.DisabledPluginConfig(),
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ metadata:
|
|||||||
t.Fatalf("unexpected error %v", err)
|
t.Fatalf("unexpected error %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expected.RemoveBuildAnnotations()
|
||||||
expYaml, err := expected.AsYaml()
|
expYaml, err := expected.AsYaml()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@@ -251,6 +252,7 @@ metadata:
|
|||||||
assert.NoError(t, kt.Load())
|
assert.NoError(t, kt.Load())
|
||||||
actual, err := kt.MakeCustomizedResMap()
|
actual, err := kt.MakeCustomizedResMap()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
actual.RemoveBuildAnnotations()
|
||||||
actYaml, err := actual.AsYaml()
|
actYaml, err := actual.AsYaml()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expYaml, actYaml)
|
assert.Equal(t, expYaml, actYaml)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// Copyright 2020 The Kubernetes Authors.
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
package types
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
23
api/internal/utils/timedcall.go
Normal file
23
api/internal/utils/timedcall.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TimedCall runs fn, failing if it doesn't complete in the given duration.
|
||||||
|
// The description is used in the timeout error message.
|
||||||
|
func TimedCall(description string, d time.Duration, fn func() error) error {
|
||||||
|
done := make(chan error)
|
||||||
|
timer := time.NewTimer(d)
|
||||||
|
defer timer.Stop()
|
||||||
|
go func() { done <- fn() }()
|
||||||
|
select {
|
||||||
|
case err := <-done:
|
||||||
|
return err
|
||||||
|
case <-timer.C:
|
||||||
|
return NewErrTimeOut(d, description)
|
||||||
|
}
|
||||||
|
}
|
||||||
64
api/internal/utils/timedcall_test.go
Normal file
64
api/internal/utils/timedcall_test.go
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package utils_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
. "sigs.k8s.io/kustomize/api/internal/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
timeToWait = 10 * time.Millisecond
|
||||||
|
tooSlow = 2 * timeToWait
|
||||||
|
)
|
||||||
|
|
||||||
|
func errMsg(msg string) string {
|
||||||
|
return fmt.Sprintf("hit %s timeout running '%s'", timeToWait, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTimedCallFastNoError(t *testing.T) {
|
||||||
|
err := TimedCall(
|
||||||
|
"fast no error", timeToWait,
|
||||||
|
func() error { return nil })
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTimedCallFastWithError(t *testing.T) {
|
||||||
|
err := TimedCall(
|
||||||
|
"fast with error", timeToWait,
|
||||||
|
func() error { return assert.AnError })
|
||||||
|
if assert.Error(t, err) {
|
||||||
|
assert.EqualError(t, err, assert.AnError.Error())
|
||||||
|
} else {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTimedCallSlowNoError(t *testing.T) {
|
||||||
|
err := TimedCall(
|
||||||
|
"slow no error", timeToWait,
|
||||||
|
func() error { time.Sleep(tooSlow); return nil })
|
||||||
|
if assert.Error(t, err) {
|
||||||
|
assert.EqualError(t, err, errMsg("slow no error"))
|
||||||
|
} else {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTimedCallSlowWithError(t *testing.T) {
|
||||||
|
err := TimedCall(
|
||||||
|
"slow with error", timeToWait,
|
||||||
|
func() error { time.Sleep(tooSlow); return assert.AnError })
|
||||||
|
if assert.Error(t, err) {
|
||||||
|
assert.EqualError(t, err, errMsg("slow with error"))
|
||||||
|
} else {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,7 +58,7 @@ func (k *WNodeFactory) SliceFromBytes(bs []byte) ([]ifc.Kunstructured, error) {
|
|||||||
|
|
||||||
// shouldDropObject returns true if the resource should not be accumulated.
|
// shouldDropObject returns true if the resource should not be accumulated.
|
||||||
func shouldDropObject(m yaml.ResourceMeta) bool {
|
func shouldDropObject(m yaml.ResourceMeta) bool {
|
||||||
_, y := m.ObjectMeta.Annotations[konfig.IgnoredByKustomizeResourceAnnotation]
|
_, y := m.ObjectMeta.Annotations[konfig.IgnoredByKustomizeAnnotation]
|
||||||
return y
|
return y
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package wrappy
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
@@ -43,6 +45,10 @@ func FromRNode(node *yaml.RNode) *WNode {
|
|||||||
return &WNode{node: node}
|
return &WNode{node: node}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wn *WNode) AsRNode() *yaml.RNode {
|
||||||
|
return wn.node
|
||||||
|
}
|
||||||
|
|
||||||
func (wn *WNode) demandMetaData(label string) yaml.ResourceMeta {
|
func (wn *WNode) demandMetaData(label string) yaml.ResourceMeta {
|
||||||
meta, err := wn.node.GetMeta()
|
meta, err := wn.node.GetMeta()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -62,9 +68,35 @@ func (wn *WNode) GetAnnotations() map[string]string {
|
|||||||
return wn.demandMetaData("GetAnnotations").Annotations
|
return wn.demandMetaData("GetAnnotations").Annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convertSliceIndex traverses the items in `fields` and find
|
||||||
|
// if there is a slice index in the item and change it to a
|
||||||
|
// valid Lookup field path. For example, 'ports[0]' will be
|
||||||
|
// converted to 'ports' and '0'.
|
||||||
|
func convertSliceIndex(fields []string) []string {
|
||||||
|
var res []string
|
||||||
|
for _, s := range fields {
|
||||||
|
if !strings.HasSuffix(s, "]") {
|
||||||
|
res = append(res, s)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
re := regexp.MustCompile(`^(.*)\[(\d+)\]$`)
|
||||||
|
groups := re.FindStringSubmatch(s)
|
||||||
|
if len(groups) == 0 {
|
||||||
|
// no match, add to result
|
||||||
|
res = append(res, s)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if groups[1] != "" {
|
||||||
|
res = append(res, groups[1])
|
||||||
|
}
|
||||||
|
res = append(res, groups[2])
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
// GetFieldValue implements ifc.Kunstructured.
|
// GetFieldValue implements ifc.Kunstructured.
|
||||||
func (wn *WNode) GetFieldValue(path string) (interface{}, error) {
|
func (wn *WNode) GetFieldValue(path string) (interface{}, error) {
|
||||||
fields := strings.Split(path, ".")
|
fields := convertSliceIndex(strings.Split(path, "."))
|
||||||
rn, err := wn.node.Pipe(yaml.Lookup(fields...))
|
rn, err := wn.node.Pipe(yaml.Lookup(fields...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -91,14 +123,34 @@ func (wn *WNode) GetFieldValue(path string) (interface{}, error) {
|
|||||||
// Return value as slice for SequenceNode kind
|
// Return value as slice for SequenceNode kind
|
||||||
if yn.Kind == yaml.SequenceNode {
|
if yn.Kind == yaml.SequenceNode {
|
||||||
var result []interface{}
|
var result []interface{}
|
||||||
for _, node := range yn.Content {
|
if err := yn.Decode(&result); err != nil {
|
||||||
result = append(result, node.Value)
|
return nil, err
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
if yn.Kind != yaml.ScalarNode {
|
||||||
|
return nil, fmt.Errorf("expected ScalarNode, got Kind=%d", yn.Kind)
|
||||||
|
}
|
||||||
|
|
||||||
// Return value value directly for all other (ScalarNode) kinds
|
// TODO: When doing kustomize var replacement, which is likely a
|
||||||
return yn.Value, nil
|
// a primary use of this function and the reason it returns interface{}
|
||||||
|
// rather than string, we do conversion from Nodes to Go types and back
|
||||||
|
// to nodes. We should figure out how to do replacement using raw nodes,
|
||||||
|
// assuming we keep the var feature in kustomize.
|
||||||
|
// The other end of this is: refvar.go:updateNodeValue.
|
||||||
|
switch yn.Tag {
|
||||||
|
case yaml.NodeTagString:
|
||||||
|
return yn.Value, nil
|
||||||
|
case yaml.NodeTagInt:
|
||||||
|
return strconv.Atoi(yn.Value)
|
||||||
|
case yaml.NodeTagFloat:
|
||||||
|
return strconv.ParseFloat(yn.Value, 64)
|
||||||
|
case yaml.NodeTagBool:
|
||||||
|
return strconv.ParseBool(yn.Value)
|
||||||
|
default:
|
||||||
|
// Possibly this should be an error or log.
|
||||||
|
return yn.Value, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGvk implements ifc.Kunstructured.
|
// GetGvk implements ifc.Kunstructured.
|
||||||
@@ -108,6 +160,16 @@ func (wn *WNode) GetGvk() resid.Gvk {
|
|||||||
return resid.Gvk{Group: g, Version: v, Kind: meta.Kind}
|
return resid.Gvk{Group: g, Version: v, Kind: meta.Kind}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDataMap implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) GetDataMap() map[string]string {
|
||||||
|
return wn.node.GetDataMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDataMap implements ifc.Kunstructured.
|
||||||
|
func (wn *WNode) SetDataMap(m map[string]string) {
|
||||||
|
wn.node.SetDataMap(m)
|
||||||
|
}
|
||||||
|
|
||||||
// GetKind implements ifc.Kunstructured.
|
// GetKind implements ifc.Kunstructured.
|
||||||
func (wn *WNode) GetKind() string {
|
func (wn *WNode) GetKind() string {
|
||||||
return wn.demandMetaData("GetKind").Kind
|
return wn.demandMetaData("GetKind").Kind
|
||||||
@@ -149,12 +211,7 @@ func (wn *WNode) GetString(path string) (string, error) {
|
|||||||
|
|
||||||
// Map implements ifc.Kunstructured.
|
// Map implements ifc.Kunstructured.
|
||||||
func (wn *WNode) Map() map[string]interface{} {
|
func (wn *WNode) Map() map[string]interface{} {
|
||||||
var result map[string]interface{}
|
return wn.node.Map()
|
||||||
if err := wn.node.YNode().Decode(&result); err != nil {
|
|
||||||
// Log and die since interface doesn't allow error.
|
|
||||||
log.Fatalf("failed to decode ynode: %v", err)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements ifc.Kunstructured.
|
// MarshalJSON implements ifc.Kunstructured.
|
||||||
@@ -182,9 +239,7 @@ func (wn *WNode) SetAnnotations(annotations map[string]string) {
|
|||||||
// SetGvk implements ifc.Kunstructured.
|
// SetGvk implements ifc.Kunstructured.
|
||||||
func (wn *WNode) SetGvk(gvk resid.Gvk) {
|
func (wn *WNode) SetGvk(gvk resid.Gvk) {
|
||||||
wn.setMapField(yaml.NewScalarRNode(gvk.Kind), yaml.KindField)
|
wn.setMapField(yaml.NewScalarRNode(gvk.Kind), yaml.KindField)
|
||||||
wn.setMapField(
|
wn.setMapField(yaml.NewScalarRNode(gvk.ApiVersion()), yaml.APIVersionField)
|
||||||
yaml.NewScalarRNode(
|
|
||||||
fmt.Sprintf("%s/%s", gvk.Group, gvk.Version)), yaml.APIVersionField)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLabels implements ifc.Kunstructured.
|
// SetLabels implements ifc.Kunstructured.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
|
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
@@ -377,6 +378,39 @@ func TestGetFieldValueReturnsSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFieldValueReturnsSliceOfMappings(t *testing.T) {
|
||||||
|
bytes, err := yaml.Marshal(makeBigMap())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected yaml.Marshal err: %v", err)
|
||||||
|
}
|
||||||
|
rNode, err := kyaml.Parse(string(bytes))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected yaml.Marshal err: %v", err)
|
||||||
|
}
|
||||||
|
wn := FromRNode(rNode)
|
||||||
|
expected := []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": "idx0foo",
|
||||||
|
"field2": "idx0bar",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": "idx1foo",
|
||||||
|
"field2": "idx1bar",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"field1": "idx2foo",
|
||||||
|
"field2": "idx2bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
actual, err := wn.GetFieldValue("those")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error getting slice: %v", err)
|
||||||
|
}
|
||||||
|
if diff := cmp.Diff(expected, actual); diff != "" {
|
||||||
|
t.Fatalf("actual slice does not deep equal expected slice:\n%v", diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetFieldValueReturnsString(t *testing.T) {
|
func TestGetFieldValueReturnsString(t *testing.T) {
|
||||||
wn := NewWNode()
|
wn := NewWNode()
|
||||||
if err := wn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
|
if err := wn.UnmarshalJSON([]byte(deploymentBiggerJson)); err != nil {
|
||||||
@@ -447,6 +481,10 @@ func TestGetSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMapEmpty(t *testing.T) {
|
||||||
|
assert.Equal(t, 0, len(NewWNode().Map()))
|
||||||
|
}
|
||||||
|
|
||||||
func TestMap(t *testing.T) {
|
func TestMap(t *testing.T) {
|
||||||
wn := NewWNode()
|
wn := NewWNode()
|
||||||
if err := wn.UnmarshalJSON([]byte(deploymentLittleJson)); err != nil {
|
if err := wn.UnmarshalJSON([]byte(deploymentLittleJson)); err != nil {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func (kf *KunstructuredFactoryImpl) skipResource(u unstructured.Unstructured) bo
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// check if the Resource has opt-ed out of kustomize
|
// check if the Resource has opt-ed out of kustomize
|
||||||
_, found := an[konfig.IgnoredByKustomizeResourceAnnotation]
|
_, found := an[konfig.IgnoredByKustomizeAnnotation]
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ package kunstruct
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
jsonpatch "github.com/evanphx/json-patch"
|
jsonpatch "github.com/evanphx/json-patch"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -249,6 +250,29 @@ func (fs *UnstructAdapter) GetStringMap(path string) (map[string]string, error)
|
|||||||
return nil, NoFieldError{Field: path}
|
return nil, NoFieldError{Field: path}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *UnstructAdapter) GetDataMap() map[string]string {
|
||||||
|
m, err := fs.GetStringMap("data")
|
||||||
|
if err != nil {
|
||||||
|
return map[string]string{}
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs *UnstructAdapter) SetDataMap(m map[string]string) {
|
||||||
|
if m == nil {
|
||||||
|
unstructured.RemoveNestedField(fs.Object, "data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s := make(map[string]interface{}, len(m))
|
||||||
|
for i, v := range m {
|
||||||
|
s[i] = v
|
||||||
|
}
|
||||||
|
err := unstructured.SetNestedMap(fs.Object, s, "data")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetMap returns value at the given fieldpath.
|
// GetMap returns value at the given fieldpath.
|
||||||
func (fs *UnstructAdapter) GetMap(path string) (map[string]interface{}, error) {
|
func (fs *UnstructAdapter) GetMap(path string) (map[string]interface{}, error) {
|
||||||
content, fields, found, err := fs.selectSubtree(path)
|
content, fields, found, err := fs.selectSubtree(path)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ package kunstruct
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var kunstructured = NewKunstructuredFactoryImpl().FromMap(map[string]interface{}{
|
var kunstructured = NewKunstructuredFactoryImpl().FromMap(map[string]interface{}{
|
||||||
@@ -557,3 +559,139 @@ func compareValues(t *testing.T, name string, pathToField string, expectedValue
|
|||||||
t.Logf("%T value at `%s`", typedV, pathToField)
|
t.Logf("%T value at `%s`", typedV, pathToField)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestKunstGetDataMap(t *testing.T) {
|
||||||
|
emptyMap := map[string]string{}
|
||||||
|
testCases := map[string]struct {
|
||||||
|
theMap map[string]interface{}
|
||||||
|
expected map[string]string
|
||||||
|
}{
|
||||||
|
"actuallyNil": {
|
||||||
|
theMap: nil,
|
||||||
|
expected: emptyMap,
|
||||||
|
},
|
||||||
|
"empty": {
|
||||||
|
theMap: map[string]interface{}{},
|
||||||
|
expected: emptyMap,
|
||||||
|
},
|
||||||
|
"mostlyEmpty": {
|
||||||
|
theMap: map[string]interface{}{
|
||||||
|
"hey": "there",
|
||||||
|
},
|
||||||
|
expected: emptyMap,
|
||||||
|
},
|
||||||
|
"noNameConfigMap": {
|
||||||
|
theMap: map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
},
|
||||||
|
expected: emptyMap,
|
||||||
|
},
|
||||||
|
"configMap": {
|
||||||
|
theMap: map[string]interface{}{
|
||||||
|
"apiVersion": "v1",
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "winnie",
|
||||||
|
},
|
||||||
|
"data": map[string]interface{}{
|
||||||
|
"wine": "cabernet",
|
||||||
|
"truck": "ford",
|
||||||
|
"rocket": "falcon9",
|
||||||
|
"planet": "mars",
|
||||||
|
"city": "brownsville",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// order irrelevant, because assert.Equals is smart about maps.
|
||||||
|
expected: map[string]string{
|
||||||
|
"city": "brownsville",
|
||||||
|
"wine": "cabernet",
|
||||||
|
"planet": "mars",
|
||||||
|
"rocket": "falcon9",
|
||||||
|
"truck": "ford",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for n := range testCases {
|
||||||
|
tc := testCases[n]
|
||||||
|
t.Run(n, func(t *testing.T) {
|
||||||
|
kunstr := NewKunstructuredFactoryImpl().FromMap(tc.theMap)
|
||||||
|
m := kunstr.GetDataMap()
|
||||||
|
if !assert.Equal(t, tc.expected, m) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKunstSetDataMap(t *testing.T) {
|
||||||
|
testCases := map[string]struct {
|
||||||
|
theMap map[string]interface{}
|
||||||
|
input map[string]string
|
||||||
|
expected map[string]string
|
||||||
|
}{
|
||||||
|
"empty": {
|
||||||
|
theMap: map[string]interface{}{},
|
||||||
|
input: map[string]string{
|
||||||
|
"wine": "cabernet",
|
||||||
|
"truck": "ford",
|
||||||
|
},
|
||||||
|
expected: map[string]string{
|
||||||
|
"wine": "cabernet",
|
||||||
|
"truck": "ford",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
theMap: map[string]interface{}{
|
||||||
|
"foo": 3,
|
||||||
|
"data": map[string]string{
|
||||||
|
"rocket": "falcon9",
|
||||||
|
"planet": "mars",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
input: map[string]string{
|
||||||
|
"wine": "cabernet",
|
||||||
|
"truck": "ford",
|
||||||
|
},
|
||||||
|
expected: map[string]string{
|
||||||
|
"wine": "cabernet",
|
||||||
|
"truck": "ford",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"clear1": {
|
||||||
|
theMap: map[string]interface{}{
|
||||||
|
"foo": 3,
|
||||||
|
"data": map[string]string{
|
||||||
|
"rocket": "falcon9",
|
||||||
|
"planet": "mars",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
input: map[string]string{},
|
||||||
|
expected: map[string]string{},
|
||||||
|
},
|
||||||
|
"clear2": {
|
||||||
|
theMap: map[string]interface{}{
|
||||||
|
"foo": 3,
|
||||||
|
"data": map[string]string{
|
||||||
|
"rocket": "falcon9",
|
||||||
|
"planet": "mars",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
input: nil,
|
||||||
|
expected: map[string]string{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for n := range testCases {
|
||||||
|
tc := testCases[n]
|
||||||
|
t.Run(n, func(t *testing.T) {
|
||||||
|
kunstr := NewKunstructuredFactoryImpl().FromMap(tc.theMap)
|
||||||
|
kunstr.SetDataMap(tc.input)
|
||||||
|
m := kunstr.GetDataMap()
|
||||||
|
if !assert.Equal(t, tc.expected, m) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ commonLabels:
|
|||||||
group: apps
|
group: apps
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|
||||||
|
- path: spec/template/spec/topologySpreadConstraints/labelSelector/matchLabels
|
||||||
|
create: false
|
||||||
|
group: apps
|
||||||
|
kind: Deployment
|
||||||
|
|
||||||
- path: spec/selector/matchLabels
|
- path: spec/selector/matchLabels
|
||||||
create: true
|
create: true
|
||||||
kind: ReplicaSet
|
kind: ReplicaSet
|
||||||
@@ -97,6 +102,11 @@ commonLabels:
|
|||||||
group: apps
|
group: apps
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
|
|
||||||
|
- path: spec/template/spec/topologySpreadConstraints/labelSelector/matchLabels
|
||||||
|
create: false
|
||||||
|
group: apps
|
||||||
|
kind: StatefulSet
|
||||||
|
|
||||||
- path: spec/volumeClaimTemplates[]/metadata/labels
|
- path: spec/volumeClaimTemplates[]/metadata/labels
|
||||||
create: true
|
create: true
|
||||||
group: apps
|
group: apps
|
||||||
|
|||||||
@@ -121,6 +121,10 @@ nameReference:
|
|||||||
kind: CronJob
|
kind: CronJob
|
||||||
- path: spec/configSource/configMap
|
- path: spec/configSource/configMap
|
||||||
kind: Node
|
kind: Node
|
||||||
|
- path: rules/resourceNames
|
||||||
|
kind: Role
|
||||||
|
- path: rules/resourceNames
|
||||||
|
kind: ClusterRole
|
||||||
|
|
||||||
- kind: Secret
|
- kind: Secret
|
||||||
version: v1
|
version: v1
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const (
|
|||||||
// Historically, tests passed for enable_kyaml == false, i.e. using
|
// Historically, tests passed for enable_kyaml == false, i.e. using
|
||||||
// apimachinery libs. This doesn't mean the code was better, it just
|
// apimachinery libs. This doesn't mean the code was better, it just
|
||||||
// means regression tests preserved those outcomes.
|
// means regression tests preserved those outcomes.
|
||||||
FlagEnableKyamlDefaultValue = false
|
FlagEnableKyamlDefaultValue = true
|
||||||
|
|
||||||
// An environment variable to consult for kustomization
|
// An environment variable to consult for kustomization
|
||||||
// configuration data. See:
|
// configuration data. See:
|
||||||
@@ -56,8 +56,11 @@ const (
|
|||||||
// A program name, for use in help, finding the XDG_CONFIG_DIR, etc.
|
// A program name, for use in help, finding the XDG_CONFIG_DIR, etc.
|
||||||
ProgramName = "kustomize"
|
ProgramName = "kustomize"
|
||||||
|
|
||||||
|
// ConfigAnnoDomain is configuration-related annotation namespace.
|
||||||
|
ConfigAnnoDomain = "config.kubernetes.io"
|
||||||
|
|
||||||
// If a resource has this annotation, kustomize will drop it.
|
// If a resource has this annotation, kustomize will drop it.
|
||||||
IgnoredByKustomizeResourceAnnotation = "config.kubernetes.io/local-config"
|
IgnoredByKustomizeAnnotation = ConfigAnnoDomain + "/local-config"
|
||||||
|
|
||||||
// Label key that indicates the resources are built from Kustomize
|
// Label key that indicates the resources are built from Kustomize
|
||||||
ManagedbyLabelKey = "app.kubernetes.io/managed-by"
|
ManagedbyLabelKey = "app.kubernetes.io/managed-by"
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -158,15 +157,3 @@ func pwdEnv() string {
|
|||||||
}
|
}
|
||||||
return "PWD"
|
return "PWD"
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBuiltinPluginNames returns a list of builtin plugin names
|
|
||||||
func GetBuiltinPluginNames() []string {
|
|
||||||
var ret []string
|
|
||||||
for k := range builtinhelpers.GeneratorFactories {
|
|
||||||
ret = append(ret, k.String())
|
|
||||||
}
|
|
||||||
for k := range builtinhelpers.TransformerFactories {
|
|
||||||
ret = append(ret, k.String())
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|||||||
102
api/krusty/basic_io_test.go
Normal file
102
api/krusty/basic_io_test.go
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package krusty_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBasicIO_1(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
opts := th.MakeDefaultOptions()
|
||||||
|
if !opts.UseKyaml {
|
||||||
|
// This test won't pass under apimachinery, because in the bowels of
|
||||||
|
// that code (see GetAnnotations in v0.17.0 of
|
||||||
|
// k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructured.go)
|
||||||
|
// an error returned from NestedStringMap is discarded, and an
|
||||||
|
// empty annotation map is silently returned, making this test fail
|
||||||
|
// The swallowed error arises from code like:
|
||||||
|
// var v interface{}
|
||||||
|
// v = true
|
||||||
|
// if str, ok := v.(string); ok {
|
||||||
|
// save the value in a map (doesn't happen)
|
||||||
|
// } else {
|
||||||
|
// return an error (that is then ignored by GetAnnotations)
|
||||||
|
// }
|
||||||
|
// The error happens when any annotation value can be interpreted as
|
||||||
|
// a boolean or number. Such annotations cannot be successfully applied
|
||||||
|
// to an object in a cluster unless they are quoted.
|
||||||
|
t.SkipNow()
|
||||||
|
}
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- service.yaml
|
||||||
|
`)
|
||||||
|
th.WriteF("service.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
port: 8080
|
||||||
|
happy: true
|
||||||
|
color: green
|
||||||
|
name: demo
|
||||||
|
spec:
|
||||||
|
clusterIP: None
|
||||||
|
`)
|
||||||
|
m := th.Run(".", opts)
|
||||||
|
// The annotations are sorted by key, hence the order change.
|
||||||
|
// Quotes are added intentionally.
|
||||||
|
th.AssertActualEqualsExpected(
|
||||||
|
m, `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
color: green
|
||||||
|
happy: "true"
|
||||||
|
port: "8080"
|
||||||
|
name: demo
|
||||||
|
spec:
|
||||||
|
clusterIP: None
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBasicIO_2(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
opts := th.MakeDefaultOptions()
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- service.yaml
|
||||||
|
`)
|
||||||
|
// All the annotation values are quoted in the input.
|
||||||
|
th.WriteF("service.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
port: "8080"
|
||||||
|
happy: "true"
|
||||||
|
color: green
|
||||||
|
name: demo
|
||||||
|
spec:
|
||||||
|
clusterIP: None
|
||||||
|
`)
|
||||||
|
m := th.Run(".", opts)
|
||||||
|
// The annotations are sorted by key, hence the order change.
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
color: green
|
||||||
|
happy: "true"
|
||||||
|
port: "8080"
|
||||||
|
name: demo
|
||||||
|
spec:
|
||||||
|
clusterIP: None
|
||||||
|
`)
|
||||||
|
}
|
||||||
@@ -39,8 +39,8 @@ resources:
|
|||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
literals:
|
literals:
|
||||||
- testValue=1
|
- testValue=purple
|
||||||
- otherValue=10
|
- otherValue=green
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/base/deploy.yaml", `
|
th.WriteF("/app/base/deploy.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -64,8 +64,8 @@ configMapGenerator:
|
|||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- testValue=2
|
- testValue=blue
|
||||||
- compValue=5
|
- compValue=red
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/comp/stub.yaml", `
|
th.WriteF("/app/comp/stub.yaml", `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -125,14 +125,12 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
compValue: "5"
|
compValue: red
|
||||||
otherValue: "10"
|
otherValue: green
|
||||||
testValue: "2"
|
testValue: blue
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: comp-my-configmap-97647ckcmg
|
||||||
labels: {}
|
|
||||||
name: comp-my-configmap-kc6k2kmkh9
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -156,7 +154,7 @@ configMapGenerator:
|
|||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- otherValue=9
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
writeK("/app/prod", `
|
writeK("/app/prod", `
|
||||||
resources:
|
resources:
|
||||||
@@ -179,14 +177,12 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
compValue: "5"
|
compValue: red
|
||||||
otherValue: "9"
|
otherValue: orange
|
||||||
testValue: "2"
|
testValue: blue
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: comp-my-configmap-g486mb229k
|
||||||
labels: {}
|
|
||||||
name: comp-my-configmap-55249mf5kb
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -212,7 +208,7 @@ configMapGenerator:
|
|||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- otherValue=9
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
writeK("/app/prod", `
|
writeK("/app/prod", `
|
||||||
resources:
|
resources:
|
||||||
@@ -234,14 +230,12 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
compValue: "5"
|
compValue: red
|
||||||
otherValue: "9"
|
otherValue: orange
|
||||||
testValue: "2"
|
testValue: blue
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: comp-my-configmap-g486mb229k
|
||||||
labels: {}
|
|
||||||
name: comp-my-configmap-55249mf5kb
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -279,11 +273,11 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
otherValue: "10"
|
otherValue: green
|
||||||
testValue: "1"
|
testValue: purple
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
name: my-configmap-2g9c94mhb8
|
name: my-configmap-9cd648hm8f
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -294,14 +288,12 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
compValue: "5"
|
compValue: red
|
||||||
otherValue: "10"
|
otherValue: green
|
||||||
testValue: "2"
|
testValue: blue
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: comp-my-configmap-97647ckcmg
|
||||||
labels: {}
|
|
||||||
name: comp-my-configmap-kc6k2kmkh9
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -327,8 +319,8 @@ configMapGenerator:
|
|||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- compValue=5
|
- compValue=red
|
||||||
- testValue=2
|
- testValue=blue
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/direct-component",
|
runPath: "/app/direct-component",
|
||||||
@@ -342,14 +334,12 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
compValue: "5"
|
compValue: red
|
||||||
otherValue: "10"
|
otherValue: green
|
||||||
testValue: "2"
|
testValue: blue
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: my-configmap-97647ckcmg
|
||||||
labels: {}
|
|
||||||
name: my-configmap-kc6k2kmkh9
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
"missing-optional-component-api-version": {
|
"missing-optional-component-api-version": {
|
||||||
@@ -360,7 +350,7 @@ configMapGenerator:
|
|||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- otherValue=9
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/app/prod",
|
||||||
@@ -374,13 +364,11 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
otherValue: "9"
|
otherValue: orange
|
||||||
testValue: "1"
|
testValue: purple
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: my-configmap-6hhdg8gkdg
|
||||||
labels: {}
|
|
||||||
name: my-configmap-5g7gh5mgt5
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -423,11 +411,11 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
otherValue: "10"
|
otherValue: green
|
||||||
testValue: "1"
|
testValue: purple
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
name: my-configmap-a-b-2g9c94mhb8
|
name: my-configmap-a-b-9cd648hm8f
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -438,11 +426,11 @@ spec:
|
|||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
otherValue: "10"
|
otherValue: green
|
||||||
testValue: "1"
|
testValue: purple
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
name: my-configmap-b-2g9c94mhb8
|
name: my-configmap-b-9cd648hm8f
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -574,7 +562,7 @@ configMapGenerator:
|
|||||||
- name: my-configmap
|
- name: my-configmap
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- otherValue=9
|
- otherValue=orange
|
||||||
`),
|
`),
|
||||||
},
|
},
|
||||||
runPath: "/app/prod",
|
runPath: "/app/prod",
|
||||||
|
|||||||
@@ -4,11 +4,121 @@
|
|||||||
package krusty_test
|
package krusty_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Numbers and booleans are quoted
|
||||||
|
func TestGeneratorIntVsStringNoMerge(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- service.yaml
|
||||||
|
configMapGenerator:
|
||||||
|
- name: bob
|
||||||
|
literals:
|
||||||
|
- fruit=Indian Gooseberry
|
||||||
|
- year=2020
|
||||||
|
- crisis=true
|
||||||
|
`)
|
||||||
|
th.WriteF("service.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: demo
|
||||||
|
spec:
|
||||||
|
clusterIP: None
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(
|
||||||
|
m, `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: demo
|
||||||
|
spec:
|
||||||
|
clusterIP: None
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
crisis: "true"
|
||||||
|
fruit: Indian Gooseberry
|
||||||
|
year: "2020"
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: bob-79t79mt227
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGeneratorIntVsStringWithMerge(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
configMapGenerator:
|
||||||
|
- name: bob
|
||||||
|
literals:
|
||||||
|
- fruit=Indian Gooseberry
|
||||||
|
- year=2020
|
||||||
|
- crisis=true
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
configMapGenerator:
|
||||||
|
- name: bob
|
||||||
|
behavior: merge
|
||||||
|
literals:
|
||||||
|
- month=12
|
||||||
|
`)
|
||||||
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `apiVersion: v1
|
||||||
|
data:
|
||||||
|
crisis: "true"
|
||||||
|
fruit: Indian Gooseberry
|
||||||
|
month: "12"
|
||||||
|
year: "2020"
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: bob-bk46gm59c6
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGeneratorFromProperties(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
configMapGenerator:
|
||||||
|
- name: test-configmap
|
||||||
|
behavior: create
|
||||||
|
envs:
|
||||||
|
- properties
|
||||||
|
`)
|
||||||
|
th.WriteF("base/properties", `
|
||||||
|
VAR1=100
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
configMapGenerator:
|
||||||
|
- name: test-configmap
|
||||||
|
behavior: "merge"
|
||||||
|
envs:
|
||||||
|
- properties
|
||||||
|
`)
|
||||||
|
th.WriteF("overlay/properties", `
|
||||||
|
VAR2=200
|
||||||
|
`)
|
||||||
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `apiVersion: v1
|
||||||
|
data:
|
||||||
|
VAR1: "100"
|
||||||
|
VAR2: "200"
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: test-configmap-hdghb5ddkg
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
// Generate a Secret and a ConfigMap from the same data
|
// Generate a Secret and a ConfigMap from the same data
|
||||||
// to compare the result.
|
// to compare the result.
|
||||||
func TestGeneratorBasics(t *testing.T) {
|
func TestGeneratorBasics(t *testing.T) {
|
||||||
@@ -59,10 +169,9 @@ electromagnetic
|
|||||||
strong nuclear
|
strong nuclear
|
||||||
weak nuclear
|
weak nuclear
|
||||||
`)
|
`)
|
||||||
|
opts := th.MakeDefaultOptions()
|
||||||
m := th.Run("/app", th.MakeDefaultOptions())
|
m := th.Run("/app", opts)
|
||||||
th.AssertActualEqualsExpected(m, `
|
expFmt := `apiVersion: v1
|
||||||
apiVersion: v1
|
|
||||||
data:
|
data:
|
||||||
MOUNTAIN: everest
|
MOUNTAIN: everest
|
||||||
OCEAN: pacific
|
OCEAN: pacific
|
||||||
@@ -95,15 +204,30 @@ apiVersion: v1
|
|||||||
data:
|
data:
|
||||||
MOUNTAIN: ZXZlcmVzdA==
|
MOUNTAIN: ZXZlcmVzdA==
|
||||||
OCEAN: cGFjaWZpYw==
|
OCEAN: cGFjaWZpYw==
|
||||||
forces.txt: CmdyYXZpdGF0aW9uYWwKZWxlY3Ryb21hZ25ldGljCnN0cm9uZyBudWNsZWFyCndlYWsgbnVjbGVhcgo=
|
forces.txt: %s
|
||||||
fruit: YXBwbGU=
|
fruit: YXBwbGU=
|
||||||
passphrase: CkxpZmUgaXMgc2hvcnQuCkJ1dCB0aGUgeWVhcnMgYXJlIGxvbmcuCk5vdCB3aGlsZSB0aGUgZXZpbCBkYXlzIGNvbWUgbm90Lgo=
|
passphrase: %s
|
||||||
vegetable: YnJvY2NvbGk=
|
vegetable: YnJvY2NvbGk=
|
||||||
kind: Secret
|
kind: Secret
|
||||||
metadata:
|
metadata:
|
||||||
name: blah-bob-ftht6hfgmb
|
name: blah-bob-%s
|
||||||
type: Opaque
|
type: Opaque
|
||||||
`)
|
`
|
||||||
|
th.AssertActualEqualsExpected(
|
||||||
|
m,
|
||||||
|
// TODO(#3304): DECISION - kyaml better; not a bug.
|
||||||
|
opts.IfApiMachineryElseKyaml(
|
||||||
|
fmt.Sprintf(
|
||||||
|
expFmt,
|
||||||
|
`CmdyYXZpdGF0aW9uYWwKZWxlY3Ryb21hZ25ldGljCnN0cm9uZyBudWNsZWFyCndlYWsgbnVjbGVhcgo=`,
|
||||||
|
`CkxpZmUgaXMgc2hvcnQuCkJ1dCB0aGUgeWVhcnMgYXJlIGxvbmcuCk5vdCB3aGlsZSB0aGUgZXZpbCBkYXlzIGNvbWUgbm90Lgo=`,
|
||||||
|
`ftht6hfgmb`),
|
||||||
|
fmt.Sprintf(
|
||||||
|
expFmt, `|
|
||||||
|
CmdyYXZpdGF0aW9uYWwKZWxlY3Ryb21hZ25ldGljCnN0cm9uZyBudWNsZWFyCndlYWsgbn
|
||||||
|
VjbGVhcgo=`, `|
|
||||||
|
CkxpZmUgaXMgc2hvcnQuCkJ1dCB0aGUgeWVhcnMgYXJlIGxvbmcuCk5vdCB3aGlsZSB0aG
|
||||||
|
UgZXZpbCBkYXlzIGNvbWUgbm90Lgo=`, `9t25t44gg4`)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: These should be errors instead.
|
// TODO: These should be errors instead.
|
||||||
@@ -159,6 +283,68 @@ metadata:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue3393(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- cm.yaml
|
||||||
|
configMapGenerator:
|
||||||
|
- name: project
|
||||||
|
behavior: merge
|
||||||
|
literals:
|
||||||
|
- ANOTHER_ENV_VARIABLE="bar"
|
||||||
|
`)
|
||||||
|
th.WriteF("cm.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: project
|
||||||
|
data:
|
||||||
|
A_FIRST_ENV_VARIABLE: "foo"
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
A_FIRST_ENV_VARIABLE: foo
|
||||||
|
ANOTHER_ENV_VARIABLE: bar
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: project
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGeneratorSimpleOverlay(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
namePrefix: p-
|
||||||
|
configMapGenerator:
|
||||||
|
- name: cm
|
||||||
|
behavior: create
|
||||||
|
literals:
|
||||||
|
- fruit=apple
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
configMapGenerator:
|
||||||
|
- name: cm
|
||||||
|
behavior: merge
|
||||||
|
literals:
|
||||||
|
- veggie=broccoli
|
||||||
|
`)
|
||||||
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
fruit: apple
|
||||||
|
veggie: broccoli
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: p-cm-877mt5hc89
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGeneratorOverlays(t *testing.T) {
|
func TestGeneratorOverlays(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base1", `
|
th.WriteK("/app/base1", `
|
||||||
@@ -215,8 +401,6 @@ data:
|
|||||||
from: overlay
|
from: overlay
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
|
||||||
labels: {}
|
|
||||||
name: p1-com1-8tc62428t2
|
name: p1-com1-8tc62428t2
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -224,8 +408,6 @@ data:
|
|||||||
from: overlay
|
from: overlay
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
|
||||||
labels: {}
|
|
||||||
name: p2-com2-87mcggf7d7
|
name: p2-com2-87mcggf7d7
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
@@ -272,8 +454,6 @@ data:
|
|||||||
foo: bar
|
foo: bar
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
|
||||||
labels: {}
|
|
||||||
name: o1-cm-ft9mmdc8c6
|
name: o1-cm-ft9mmdc8c6
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
@@ -282,8 +462,43 @@ data:
|
|||||||
foo: bar
|
foo: bar
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
|
||||||
labels: {}
|
|
||||||
name: cm-o2-5k95kd76ft
|
name: cm-o2-5k95kd76ft
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigMapGeneratorLiteralNewline(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("/app", `
|
||||||
|
generators:
|
||||||
|
- configmaps.yaml
|
||||||
|
`)
|
||||||
|
th.WriteF("/app/configmaps.yaml", `
|
||||||
|
apiVersion: builtin
|
||||||
|
kind: ConfigMapGenerator
|
||||||
|
metadata:
|
||||||
|
name: testing
|
||||||
|
literals:
|
||||||
|
- |
|
||||||
|
initial.txt=greetings
|
||||||
|
everyone
|
||||||
|
- |
|
||||||
|
final.txt=different
|
||||||
|
behavior
|
||||||
|
---
|
||||||
|
`)
|
||||||
|
m := th.Run("/app", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(
|
||||||
|
m, `
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
final.txt: |
|
||||||
|
different
|
||||||
|
behavior
|
||||||
|
initial.txt: |
|
||||||
|
greetings
|
||||||
|
everyone
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: testing-tt4769fb52
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ spec:
|
|||||||
action: fly
|
action: fly
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/base/mykind.yaml", `
|
th.WriteF("/app/base/mykind.yaml", `
|
||||||
apiVersion: jingfang.example.com/v1beta1
|
apiVersion: jingfang.example.com/v1
|
||||||
kind: MyKind
|
kind: MyKind
|
||||||
metadata:
|
metadata:
|
||||||
name: mykind
|
name: mykind
|
||||||
@@ -236,7 +236,7 @@ kind: Secret
|
|||||||
metadata:
|
metadata:
|
||||||
name: x-crdsecret
|
name: x-crdsecret
|
||||||
---
|
---
|
||||||
apiVersion: jingfang.example.com/v1beta1
|
apiVersion: jingfang.example.com/v1
|
||||||
kind: MyKind
|
kind: MyKind
|
||||||
metadata:
|
metadata:
|
||||||
name: x-mykind
|
name: x-mykind
|
||||||
@@ -285,7 +285,7 @@ kind: Secret
|
|||||||
metadata:
|
metadata:
|
||||||
name: prod-x-crdsecret
|
name: prod-x-crdsecret
|
||||||
---
|
---
|
||||||
apiVersion: jingfang.example.com/v1beta1
|
apiVersion: jingfang.example.com/v1
|
||||||
kind: MyKind
|
kind: MyKind
|
||||||
metadata:
|
metadata:
|
||||||
name: prod-x-mykind
|
name: prod-x-mykind
|
||||||
|
|||||||
@@ -93,5 +93,6 @@ func (b *Kustomizer) Run(path string) (resmap.ResMap, error) {
|
|||||||
}
|
}
|
||||||
t.Transform(m)
|
t.Transform(m)
|
||||||
}
|
}
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,334 @@
|
|||||||
package krusty_test
|
package krusty_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestRemoveEmptyDirWithNullFieldInSmp(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- patch.yaml
|
||||||
|
`)
|
||||||
|
th.WriteF("deployment.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
emptyDir: {}
|
||||||
|
`)
|
||||||
|
th.WriteF("patch.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
emptyDir: null
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveEmptyDirAddPersistentDisk(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- patch.yaml
|
||||||
|
`)
|
||||||
|
th.WriteF("deployment.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
emptyDir: {}
|
||||||
|
`)
|
||||||
|
th.WriteF("patch.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
emptyDir: null
|
||||||
|
gcePersistentDisk:
|
||||||
|
pdName: fancyDisk
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- gcePersistentDisk:
|
||||||
|
pdName: fancyDisk
|
||||||
|
name: fancyDisk
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVolumeRemoveEmptyDirInOverlay(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
configMapGenerator:
|
||||||
|
- name: baseCm
|
||||||
|
literals:
|
||||||
|
- foo=bar
|
||||||
|
`)
|
||||||
|
th.WriteF("base/deployment.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: nginx
|
||||||
|
volumeMounts:
|
||||||
|
- name: fancyDisk
|
||||||
|
mountPath: /tmp/ps
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
emptyDir: {}
|
||||||
|
- configMap:
|
||||||
|
name: baseCm
|
||||||
|
name: baseCm
|
||||||
|
`)
|
||||||
|
m := th.Run("base", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /tmp/ps
|
||||||
|
name: fancyDisk
|
||||||
|
volumes:
|
||||||
|
- emptyDir: {}
|
||||||
|
name: fancyDisk
|
||||||
|
- configMap:
|
||||||
|
name: baseCm-798k5k7g9f
|
||||||
|
name: baseCm
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
foo: bar
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: baseCm-798k5k7g9f
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- patch.yaml
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
configMapGenerator:
|
||||||
|
- name: overlayCm
|
||||||
|
literals:
|
||||||
|
- hello=world
|
||||||
|
`)
|
||||||
|
th.WriteF("overlay/patch.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: fancyDisk
|
||||||
|
emptyDir: null
|
||||||
|
gcePersistentDisk:
|
||||||
|
pdName: fancyDisk
|
||||||
|
- configMap:
|
||||||
|
name: overlayCm
|
||||||
|
name: overlayCm
|
||||||
|
`)
|
||||||
|
m = th.Run("overlay", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /tmp/ps
|
||||||
|
name: fancyDisk
|
||||||
|
volumes:
|
||||||
|
- gcePersistentDisk:
|
||||||
|
pdName: fancyDisk
|
||||||
|
name: fancyDisk
|
||||||
|
- configMap:
|
||||||
|
name: overlayCm-dc6fm46dhm
|
||||||
|
name: overlayCm
|
||||||
|
- configMap:
|
||||||
|
name: baseCm-798k5k7g9f
|
||||||
|
name: baseCm
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
foo: bar
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: baseCm-798k5k7g9f
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
hello: world
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: overlayCm-dc6fm46dhm
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveEmptyDirWithPatchesAtSameLevel(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK("base", `
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
`)
|
||||||
|
th.WriteF("base/deployment.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: nginx
|
||||||
|
- name: sidecar
|
||||||
|
image: sidecar:latest
|
||||||
|
volumes:
|
||||||
|
- name: nginx-persistent-storage
|
||||||
|
emptyDir: {}
|
||||||
|
`)
|
||||||
|
th.WriteK("overlay", `
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- deployment-patch1.yaml
|
||||||
|
- deployment-patch2.yaml
|
||||||
|
resources:
|
||||||
|
- ../base
|
||||||
|
`)
|
||||||
|
th.WriteF("overlay/deployment-patch1.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
volumes:
|
||||||
|
- name: nginx-persistent-storage
|
||||||
|
emptyDir: null
|
||||||
|
gcePersistentDisk:
|
||||||
|
pdName: nginx-persistent-storage
|
||||||
|
`)
|
||||||
|
th.WriteF("overlay/deployment-patch2.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: nginx
|
||||||
|
name: nginx
|
||||||
|
env:
|
||||||
|
- name: ANOTHERENV
|
||||||
|
value: FOO
|
||||||
|
volumes:
|
||||||
|
- name: nginx-persistent-storage
|
||||||
|
`)
|
||||||
|
opts := th.MakeDefaultOptions()
|
||||||
|
m := th.Run("overlay", opts)
|
||||||
|
expFmt := `apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: ANOTHERENV
|
||||||
|
value: FOO
|
||||||
|
image: nginx
|
||||||
|
name: nginx
|
||||||
|
- image: sidecar:latest
|
||||||
|
name: sidecar
|
||||||
|
volumes:%s
|
||||||
|
name: nginx-persistent-storage
|
||||||
|
`
|
||||||
|
th.AssertActualEqualsExpected(
|
||||||
|
// TODO(#3394): Should be possible to delete emptyDir with a patch.
|
||||||
|
// TODO(#3304): DECISION - still a bug, emptyDir should be deleted.
|
||||||
|
m, opts.IfApiMachineryElseKyaml(
|
||||||
|
fmt.Sprintf(expFmt, `
|
||||||
|
- gcePersistentDisk:
|
||||||
|
pdName: nginx-persistent-storage`),
|
||||||
|
fmt.Sprintf(expFmt, `
|
||||||
|
- emptyDir: {}
|
||||||
|
gcePersistentDisk:
|
||||||
|
pdName: nginx-persistent-storage`),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
func TestSimpleMultiplePatches(t *testing.T) {
|
func TestSimpleMultiplePatches(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("base", `
|
th.WriteK("base", `
|
||||||
@@ -41,8 +363,6 @@ spec:
|
|||||||
- name: sidecar
|
- name: sidecar
|
||||||
image: sidecar:latest
|
image: sidecar:latest
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
|
||||||
emptyDir: {}
|
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -86,7 +406,6 @@ spec:
|
|||||||
value: ENVVALUE
|
value: ENVVALUE
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- name: nginx-persistent-storage
|
||||||
emptyDir: null
|
|
||||||
gcePersistentDisk:
|
gcePersistentDisk:
|
||||||
pdName: nginx-persistent-storage
|
pdName: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
@@ -106,8 +425,6 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- name: ANOTHERENV
|
- name: ANOTHERENV
|
||||||
value: FOO
|
value: FOO
|
||||||
volumes:
|
|
||||||
- name: nginx-persistent-storage
|
|
||||||
`)
|
`)
|
||||||
m := th.Run("overlay", th.MakeDefaultOptions())
|
m := th.Run("overlay", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -188,7 +505,7 @@ metadata:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCommonFileForMultiplePatchTest(th kusttest_test.Harness) {
|
func makeCommonFilesForMultiplePatchTests(th kusttest_test.Harness) {
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
namePrefix: team-foo-
|
namePrefix: team-foo-
|
||||||
commonLabels:
|
commonLabels:
|
||||||
@@ -227,8 +544,6 @@ spec:
|
|||||||
- name: sidecar
|
- name: sidecar
|
||||||
image: sidecar:latest
|
image: sidecar:latest
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
|
||||||
emptyDir: {}
|
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -264,7 +579,7 @@ configMapGenerator:
|
|||||||
|
|
||||||
func TestMultiplePatchesNoConflict(t *testing.T) {
|
func TestMultiplePatchesNoConflict(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFilesForMultiplePatchTests(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -281,7 +596,6 @@ spec:
|
|||||||
value: ENVVALUE
|
value: ENVVALUE
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- name: nginx-persistent-storage
|
||||||
emptyDir: null
|
|
||||||
gcePersistentDisk:
|
gcePersistentDisk:
|
||||||
pdName: nginx-persistent-storage
|
pdName: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
@@ -301,8 +615,6 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- name: ANOTHERENV
|
- name: ANOTHERENV
|
||||||
value: FOO
|
value: FOO
|
||||||
volumes:
|
|
||||||
- name: nginx-persistent-storage
|
|
||||||
`)
|
`)
|
||||||
m := th.Run("/app/overlay/staging", th.MakeDefaultOptions())
|
m := th.Run("/app/overlay/staging", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
@@ -405,7 +717,7 @@ metadata:
|
|||||||
|
|
||||||
func TestMultiplePatchesWithConflict(t *testing.T) {
|
func TestMultiplePatchesWithConflict(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFilesForMultiplePatchTests(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -421,7 +733,6 @@ spec:
|
|||||||
value: TRUE
|
value: TRUE
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- name: nginx-persistent-storage
|
||||||
emptyDir: null
|
|
||||||
gcePersistentDisk:
|
gcePersistentDisk:
|
||||||
pdName: nginx-persistent-storage
|
pdName: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
@@ -442,13 +753,114 @@ spec:
|
|||||||
- name: ENABLE_FEATURE_FOO
|
- name: ENABLE_FEATURE_FOO
|
||||||
value: FALSE
|
value: FALSE
|
||||||
`)
|
`)
|
||||||
err := th.RunWithErr("/app/overlay/staging", th.MakeDefaultOptions())
|
opts := th.MakeDefaultOptions()
|
||||||
if err == nil {
|
if opts.UseKyaml {
|
||||||
t.Fatalf("expected conflict")
|
// kyaml doesn't try to detect conflicts in patches
|
||||||
}
|
// (so ENABLE_FEATURE_FOO FALSE wins).
|
||||||
if !strings.Contains(
|
m := th.Run("/app/overlay/staging", opts)
|
||||||
err.Error(), "conflict between ") {
|
th.AssertActualEqualsExpected(m, `
|
||||||
t.Fatalf("Unexpected err: %v", err)
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
name: staging-team-foo-nginx
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: ENABLE_FEATURE_FOO
|
||||||
|
value: false
|
||||||
|
image: nginx
|
||||||
|
name: nginx
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /tmp/ps
|
||||||
|
name: nginx-persistent-storage
|
||||||
|
- image: sidecar:latest
|
||||||
|
name: sidecar
|
||||||
|
volumes:
|
||||||
|
- gcePersistentDisk:
|
||||||
|
pdName: nginx-persistent-storage
|
||||||
|
name: nginx-persistent-storage
|
||||||
|
- configMap:
|
||||||
|
name: staging-configmap-in-overlay-dc6fm46dhm
|
||||||
|
name: configmap-in-overlay
|
||||||
|
- configMap:
|
||||||
|
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
||||||
|
name: configmap-in-base
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
name: staging-team-foo-nginx
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
selector:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
foo: bar
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
hello: world
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
env: staging
|
||||||
|
name: staging-configmap-in-overlay-dc6fm46dhm
|
||||||
|
`)
|
||||||
|
} else {
|
||||||
|
err := th.RunWithErr("/app/overlay/staging", opts)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected conflict")
|
||||||
|
}
|
||||||
|
if !strings.Contains(
|
||||||
|
err.Error(), "conflict between ") {
|
||||||
|
t.Fatalf("Unexpected err: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,8 +909,7 @@ spec:
|
|||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
makeCommonFilesForMultiplePatchTests(th)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", c.patch1)
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", c.patch1)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch2.yaml", c.patch2)
|
th.WriteF("/app/overlay/staging/deployment-patch2.yaml", c.patch2)
|
||||||
m := th.Run("/app/overlay/staging", th.MakeDefaultOptions())
|
m := th.Run("/app/overlay/staging", th.MakeDefaultOptions())
|
||||||
@@ -540,8 +951,6 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: nginx-persistent-storage
|
name: nginx-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- emptyDir: {}
|
|
||||||
name: nginx-persistent-storage
|
|
||||||
- configMap:
|
- configMap:
|
||||||
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -595,7 +1004,7 @@ metadata:
|
|||||||
|
|
||||||
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
|
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
makeCommonFileForMultiplePatchTest(th)
|
makeCommonFilesForMultiplePatchTests(th)
|
||||||
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
th.WriteF("/app/overlay/staging/deployment-patch1.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -620,12 +1029,98 @@ spec:
|
|||||||
- $patch: delete
|
- $patch: delete
|
||||||
name: nginx
|
name: nginx
|
||||||
`)
|
`)
|
||||||
err := th.RunWithErr("/app/overlay/staging", th.MakeDefaultOptions())
|
opt := th.MakeDefaultOptions()
|
||||||
if err == nil {
|
if opt.UseKyaml {
|
||||||
t.Fatalf("Expected error")
|
// kyaml doesn't fail on conflicts in patches; both containers
|
||||||
}
|
// (nginx and sidecar) are deleted per this patching instruction.
|
||||||
if !strings.Contains(
|
m := th.Run("/app/overlay/staging", opt)
|
||||||
err.Error(), "both containing ") {
|
th.AssertActualEqualsExpected(m, `
|
||||||
t.Fatalf("Unexpected err: %v", err)
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
name: staging-team-foo-nginx
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
spec:
|
||||||
|
containers: []
|
||||||
|
volumes:
|
||||||
|
- configMap:
|
||||||
|
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
||||||
|
name: configmap-in-base
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
name: staging-team-foo-nginx
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
selector:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
foo: bar
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
note: This is a test annotation
|
||||||
|
labels:
|
||||||
|
app: mynginx
|
||||||
|
env: staging
|
||||||
|
org: example.com
|
||||||
|
team: foo
|
||||||
|
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
hello: world
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
env: staging
|
||||||
|
name: staging-configmap-in-overlay-dc6fm46dhm
|
||||||
|
`)
|
||||||
|
} else {
|
||||||
|
// No kyaml means error on a patch conflict.
|
||||||
|
err := th.RunWithErr("/app/overlay/staging", opt)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("Expected error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(
|
||||||
|
err.Error(), "both containing ") {
|
||||||
|
t.Fatalf("Unexpected err: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ configMapGenerator:
|
|||||||
literals:
|
literals:
|
||||||
- MYSQL_USER=default
|
- MYSQL_USER=default
|
||||||
- MYSQL_DATABASE=default
|
- MYSQL_DATABASE=default
|
||||||
- PORT=3306
|
- HOST=everest
|
||||||
`)
|
`)
|
||||||
|
|
||||||
th.WriteK(".", `
|
th.WriteK(".", `
|
||||||
@@ -82,15 +82,13 @@ patches:
|
|||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
|
HOST: everest
|
||||||
MYSQL_DATABASE: db
|
MYSQL_DATABASE: db
|
||||||
MYSQL_PASSWORD: correct horse battery staple
|
MYSQL_PASSWORD: correct horse battery staple
|
||||||
MYSQL_USER: my-user
|
MYSQL_USER: my-user
|
||||||
PORT: "3306"
|
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: mysql-t7tt4cdbmf
|
||||||
labels: {}
|
|
||||||
name: mysql-9792mdchtg
|
|
||||||
---
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -104,10 +102,10 @@ spec:
|
|||||||
- valueFrom:
|
- valueFrom:
|
||||||
configMapKeyRef:
|
configMapKeyRef:
|
||||||
key: MYSQL_DATABASE
|
key: MYSQL_DATABASE
|
||||||
name: mysql-9792mdchtg
|
name: mysql-t7tt4cdbmf
|
||||||
envFrom:
|
envFrom:
|
||||||
- configMapRef:
|
- configMapRef:
|
||||||
name: mysql-9792mdchtg
|
name: mysql-t7tt4cdbmf
|
||||||
name: handler
|
name: handler
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace: base
|
|||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: testCase
|
- name: testCase
|
||||||
literals:
|
literals:
|
||||||
- base=true
|
- base=apple
|
||||||
`)
|
`)
|
||||||
th.WriteK("/app/overlay", `
|
th.WriteK("/app/overlay", `
|
||||||
resources:
|
resources:
|
||||||
@@ -92,19 +92,17 @@ configMapGenerator:
|
|||||||
- name: testCase
|
- name: testCase
|
||||||
behavior: merge
|
behavior: merge
|
||||||
literals:
|
literals:
|
||||||
- overlay=true
|
- overlay=peach
|
||||||
`)
|
`)
|
||||||
m := th.Run("/app/overlay", th.MakeDefaultOptions())
|
m := th.Run("/app/overlay", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
base: "true"
|
base: apple
|
||||||
overlay: "true"
|
overlay: peach
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations: {}
|
name: testCase-gmfch8gkbt
|
||||||
labels: {}
|
|
||||||
name: testCase-bcbmmg48hd
|
|
||||||
namespace: overlay
|
namespace: overlay
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ metadata:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This serie of constants is used to prove the need of
|
// This series of constants is used to prove the need of
|
||||||
// the namespace field in the objref field of the var declaration.
|
// the namespace field in the objref field of the var declaration.
|
||||||
// The following tests demonstrate that it creates umbiguous variable
|
// The following tests demonstrate that it creates umbiguous variable
|
||||||
// declaration if two entities of the kind with the same name
|
// declaration if two entities of the kind with the same name
|
||||||
@@ -472,10 +472,12 @@ spec:
|
|||||||
// not specified
|
// not specified
|
||||||
func TestVariablesAmbiguous(t *testing.T) {
|
func TestVariablesAmbiguous(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyApp)
|
th.WriteK(".", namespaceNeedInVarMyApp)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
th.WriteF("elasticsearch-dev-service.yaml",
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
namespaceNeedInVarDevResources)
|
||||||
err := th.RunWithErr("/namespaceNeedInVar/myapp", th.MakeDefaultOptions())
|
th.WriteF("elasticsearch-test-service.yaml",
|
||||||
|
namespaceNeedInVarTestResources)
|
||||||
|
err := th.RunWithErr(".", th.MakeDefaultOptions())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected error")
|
t.Fatalf("expected error")
|
||||||
}
|
}
|
||||||
@@ -529,16 +531,17 @@ vars:
|
|||||||
// and resources into multiple kustomization context/folders instead of one.
|
// and resources into multiple kustomization context/folders instead of one.
|
||||||
func TestVariablesAmbiguousWorkaround(t *testing.T) {
|
func TestVariablesAmbiguousWorkaround(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/namespaceNeedInVar/dev", namespaceNeedInVarDevFolder)
|
opts := th.MakeDefaultOptions()
|
||||||
th.WriteF("/namespaceNeedInVar/dev/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
th.WriteK("dev", namespaceNeedInVarDevFolder)
|
||||||
th.WriteK("/namespaceNeedInVar/test", namespaceNeedInVarTestFolder)
|
th.WriteF("dev/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
||||||
th.WriteF("/namespaceNeedInVar/test/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
th.WriteK("test", namespaceNeedInVarTestFolder)
|
||||||
th.WriteK("/namespaceNeedInVar/workaround", `
|
th.WriteF("test/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
||||||
|
th.WriteK("workaround", `
|
||||||
resources:
|
resources:
|
||||||
- ../dev
|
- ../dev
|
||||||
- ../test
|
- ../test
|
||||||
`)
|
`)
|
||||||
m := th.Run("/namespaceNeedInVar/workaround", th.MakeDefaultOptions())
|
m := th.Run("workaround", opts)
|
||||||
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,9 +588,68 @@ vars:
|
|||||||
// to the variable declarations allows to disambiguate the variables.
|
// to the variable declarations allows to disambiguate the variables.
|
||||||
func TestVariablesDisambiguatedWithNamespace(t *testing.T) {
|
func TestVariablesDisambiguatedWithNamespace(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/namespaceNeedInVar/myapp", namespaceNeedInVarMyAppWithNamespace)
|
th.WriteK(".", namespaceNeedInVarMyAppWithNamespace)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
th.WriteF("elasticsearch-dev-service.yaml", namespaceNeedInVarDevResources)
|
||||||
th.WriteF("/namespaceNeedInVar/myapp/elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
th.WriteF("elasticsearch-test-service.yaml", namespaceNeedInVarTestResources)
|
||||||
m := th.Run("/namespaceNeedInVar/myapp", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAddNamePrefixWithNamespace tests that adding a name prefix works within
|
||||||
|
// namespaces other than the default namespace.
|
||||||
|
// Test for issue #3430
|
||||||
|
func TestAddNamePrefixWithNamespace(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
|
||||||
|
th.WriteF("/app/serviceaccount.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteF("/app/clusterrolebinding.yaml", `
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: prometheus
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: prometheus
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteK("/app", `
|
||||||
|
namePrefix: iter8-
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
resources:
|
||||||
|
- clusterrolebinding.yaml
|
||||||
|
- serviceaccount.yaml
|
||||||
|
`)
|
||||||
|
|
||||||
|
m := th.Run("/app", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: iter8-prometheus
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: prometheus
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: iter8-prometheus
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: iter8-prometheus
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ subjects:
|
|||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: default
|
name: default
|
||||||
namespace: foo
|
namespace: foo
|
||||||
---
|
---
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: Role
|
kind: Role
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
package krusty
|
package krusty
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
)
|
)
|
||||||
@@ -50,7 +51,26 @@ func MakeDefaultOptions() *Options {
|
|||||||
LoadRestrictions: types.LoadRestrictionsRootOnly,
|
LoadRestrictions: types.LoadRestrictionsRootOnly,
|
||||||
DoPrune: false,
|
DoPrune: false,
|
||||||
PluginConfig: konfig.DisabledPluginConfig(),
|
PluginConfig: konfig.DisabledPluginConfig(),
|
||||||
UseKyaml: false,
|
UseKyaml: konfig.FlagEnableKyamlDefaultValue,
|
||||||
AllowResourceIdChanges: false,
|
AllowResourceIdChanges: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o Options) IfApiMachineryElseKyaml(s1, s2 string) string {
|
||||||
|
if !o.UseKyaml {
|
||||||
|
return s1
|
||||||
|
}
|
||||||
|
return s2
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBuiltinPluginNames returns a list of builtin plugin names
|
||||||
|
func GetBuiltinPluginNames() []string {
|
||||||
|
var ret []string
|
||||||
|
for k := range builtinhelpers.GeneratorFactories {
|
||||||
|
ret = append(ret, k.String())
|
||||||
|
}
|
||||||
|
for k := range builtinhelpers.TransformerFactories {
|
||||||
|
ret = append(ret, k.String())
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|||||||
96
api/krusty/patchdelete_test.go
Normal file
96
api/krusty/patchdelete_test.go
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package krusty_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPatchDeleteOfNotExistingAttributesShouldNotAddExtraElements(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeEnhancedHarness(t)
|
||||||
|
defer th.Reset()
|
||||||
|
|
||||||
|
th.WriteF("resource.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: whatever
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: EXISTING
|
||||||
|
value: EXISTING_VALUE
|
||||||
|
- name: FOR_REMOVAL
|
||||||
|
value: FOR_REMOVAL_VALUE
|
||||||
|
name: whatever
|
||||||
|
image: helloworld
|
||||||
|
`)
|
||||||
|
th.WriteF("patch.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: whatever
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: whatever
|
||||||
|
env:
|
||||||
|
- name: FOR_REMOVAL
|
||||||
|
$patch: delete
|
||||||
|
- name: NOT_EXISTING_FOR_REMOVAL
|
||||||
|
$patch: delete
|
||||||
|
`)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- resource.yaml
|
||||||
|
patches:
|
||||||
|
- path: patch.yaml
|
||||||
|
target:
|
||||||
|
kind: Deployment
|
||||||
|
`)
|
||||||
|
|
||||||
|
// It's expected that removal of not existing elements should not introduce extra values,
|
||||||
|
// as a patch can be applied to multiple resources, not all of them can have all the elements being deleted.
|
||||||
|
expected := `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: whatever
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: EXISTING
|
||||||
|
value: EXISTING_VALUE
|
||||||
|
image: helloworld
|
||||||
|
name: whatever
|
||||||
|
`
|
||||||
|
// Allow expected variable to be unused
|
||||||
|
_ = expected
|
||||||
|
|
||||||
|
// Currently, kustomize inserts $patch: delete elements into the resulting resources
|
||||||
|
erroneousActual := `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: whatever
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- $patch: delete
|
||||||
|
name: NOT_EXISTING_FOR_REMOVAL
|
||||||
|
- name: EXISTING
|
||||||
|
value: EXISTING_VALUE
|
||||||
|
image: helloworld
|
||||||
|
name: whatever
|
||||||
|
`
|
||||||
|
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, erroneousActual)
|
||||||
|
}
|
||||||
134
api/krusty/poddisruptionbudget_test.go
Normal file
134
api/krusty/poddisruptionbudget_test.go
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
// Copyright 2020 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package krusty_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPodDisruptionBudgetBasics(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteF("pdbLiteral.yaml", `
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: pdbLiteral
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 90
|
||||||
|
`)
|
||||||
|
th.WriteF("pdbPercentage.yaml", `
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: pdbPercentage
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 90%
|
||||||
|
`)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- pdbLiteral.yaml
|
||||||
|
- pdbPercentage.yaml
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
// In a PodDisruptionBudget, the fields maxUnavailable
|
||||||
|
// minAvailable are mutually exclusive, and both can hold
|
||||||
|
// either an integer, i.e. 10, or string that has to be
|
||||||
|
// an int followed by a percent sign, e.g. 10%.
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: pdbLiteral
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 90
|
||||||
|
---
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: pdbPercentage
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 90%
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPodDisruptionBudgetMerging(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
opts := th.MakeDefaultOptions()
|
||||||
|
th.WriteF("pdb-patch.yaml", `
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: generic-pdb
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 1
|
||||||
|
`)
|
||||||
|
th.WriteF("my_file.yaml", `
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: championships-api
|
||||||
|
labels:
|
||||||
|
faceit-pdb: default
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 100%
|
||||||
|
---
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
name: championships-api-2
|
||||||
|
labels:
|
||||||
|
faceit-pdb: default
|
||||||
|
spec:
|
||||||
|
maxUnavailable: 100%
|
||||||
|
`)
|
||||||
|
th.WriteK(".", `
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
patches:
|
||||||
|
- path: pdb-patch.yaml
|
||||||
|
target:
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
labelSelector: faceit-pdb=default
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- my_file.yaml
|
||||||
|
`)
|
||||||
|
m := th.Run(".", opts)
|
||||||
|
expFmt := `
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
faceit-pdb: default
|
||||||
|
name: championships-api
|
||||||
|
spec:
|
||||||
|
maxUnavailable: %s
|
||||||
|
---
|
||||||
|
apiVersion: policy/v1beta1
|
||||||
|
kind: PodDisruptionBudget
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
faceit-pdb: default
|
||||||
|
name: championships-api-2
|
||||||
|
spec:
|
||||||
|
maxUnavailable: %s
|
||||||
|
`
|
||||||
|
// In a PodDisruptionBudget, the fields maxUnavailable
|
||||||
|
// minAvailable are mutually exclusive, and both can hold
|
||||||
|
// either an integer, i.e. 10, or string that has to be
|
||||||
|
// an int followed by a percent sign, e.g. 10%.
|
||||||
|
// In the former case - bare integer - they should NOT be quoted
|
||||||
|
// as the api server will reject it. In the latter case with
|
||||||
|
// the percent sign, quotes can be added and the API server will
|
||||||
|
// accept it, but they don't have to be added.
|
||||||
|
th.AssertActualEqualsExpected(
|
||||||
|
m,
|
||||||
|
// TODO(#3304): DECISION - kyaml better; not a bug.
|
||||||
|
opts.IfApiMachineryElseKyaml(
|
||||||
|
fmt.Sprintf(expFmt, `"1"`, `"1"`),
|
||||||
|
fmt.Sprintf(expFmt, `1`, `1`)))
|
||||||
|
}
|
||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
|
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||||
"sigs.k8s.io/kustomize/api/krusty"
|
"sigs.k8s.io/kustomize/api/krusty"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoteLoad(t *testing.T) {
|
func TestRemoteLoad(t *testing.T) {
|
||||||
@@ -17,7 +17,7 @@ func TestRemoteLoad(t *testing.T) {
|
|||||||
b := krusty.MakeKustomizer(fSys, krusty.MakeDefaultOptions())
|
b := krusty.MakeKustomizer(fSys, krusty.MakeDefaultOptions())
|
||||||
m, err := b.Run(
|
m, err := b.Run(
|
||||||
"github.com/kubernetes-sigs/kustomize/examples/multibases/dev/?ref=v1.0.6")
|
"github.com/kubernetes-sigs/kustomize/examples/multibases/dev/?ref=v1.0.6")
|
||||||
if types.IsErrTimeout(err) {
|
if utils.IsErrTimeout(err) {
|
||||||
// Don't fail on timeouts.
|
// Don't fail on timeouts.
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
|
|||||||
47
api/krusty/simple_test.go
Normal file
47
api/krusty/simple_test.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package krusty_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSimple1(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteF("/dep.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 1
|
||||||
|
`)
|
||||||
|
th.WriteF("/patch.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteK("/", `
|
||||||
|
resources:
|
||||||
|
- dep.yaml
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- patch.yaml
|
||||||
|
`)
|
||||||
|
m := th.Run("/", th.MakeDefaultOptions())
|
||||||
|
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`)
|
||||||
|
}
|
||||||
@@ -74,20 +74,20 @@ kind: ConfigMap
|
|||||||
metadata:
|
metadata:
|
||||||
name: configmap-a
|
name: configmap-a
|
||||||
annotations:
|
annotations:
|
||||||
kustomize.k8s.io/Generated: "false"
|
fruit: peach
|
||||||
data:
|
data:
|
||||||
foo: $FOO
|
foo: $FOO
|
||||||
`)
|
`)
|
||||||
|
|
||||||
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
|
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpectedNoIdAnnotations(m, `
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
foo: foo
|
foo: foo
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
kustomize.k8s.io/Generated: "false"
|
fruit: peach
|
||||||
name: configmap-a
|
name: configmap-a
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
|||||||
@@ -360,6 +360,187 @@ resources:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSimpleServicePortVarReplace(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- service.yaml
|
||||||
|
- statefulset.yaml
|
||||||
|
vars:
|
||||||
|
- name: THE_PORT
|
||||||
|
objref:
|
||||||
|
kind: StatefulSet
|
||||||
|
name: cockroachdb
|
||||||
|
apiVersion: apps/v1beta1
|
||||||
|
fieldref:
|
||||||
|
fieldpath: spec.template.spec.containers[0].ports[1].containerPort
|
||||||
|
`)
|
||||||
|
th.WriteF("service.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: myService
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: $(THE_PORT)
|
||||||
|
targetPort: $(THE_PORT)
|
||||||
|
name: grpc
|
||||||
|
`)
|
||||||
|
th.WriteF("statefulset.yaml", `
|
||||||
|
apiVersion: apps/v1beta1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: cockroachdb
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: cockroachdb
|
||||||
|
image: cockroachdb/cockroach:v1.1.5
|
||||||
|
ports:
|
||||||
|
- containerPort: 26257
|
||||||
|
name: grpc
|
||||||
|
- containerPort: 8888
|
||||||
|
name: http
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: myService
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: grpc
|
||||||
|
port: 8888
|
||||||
|
targetPort: 8888
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1beta1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: cockroachdb
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: cockroachdb/cockroach:v1.1.5
|
||||||
|
name: cockroachdb
|
||||||
|
ports:
|
||||||
|
- containerPort: 26257
|
||||||
|
name: grpc
|
||||||
|
- containerPort: 8888
|
||||||
|
name: http
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(3449): Yield bare primitives in var replacements from configmaps.
|
||||||
|
// The ConfigMap data field is always strings, and anything that looks
|
||||||
|
// like a boolean or int or float must be quoted, or the API server won't
|
||||||
|
// accept the map. This creates a problem if one wants to use a var to
|
||||||
|
// inject a raw number or raw boolean sourced from a configmap, because as
|
||||||
|
// far as the configmap representation is concerned, it's a string.
|
||||||
|
// A workaround would be to source the var from another Kind, from a field
|
||||||
|
// that allowed unquoted vars or booleans.
|
||||||
|
func TestIssue3449(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- workflow.yaml
|
||||||
|
|
||||||
|
configurations:
|
||||||
|
- kustomization-config.yaml
|
||||||
|
|
||||||
|
configMapGenerator:
|
||||||
|
- name: kustomize-vars
|
||||||
|
envs:
|
||||||
|
- vars.env
|
||||||
|
|
||||||
|
vars:
|
||||||
|
- name: DBT_TARGET
|
||||||
|
objref: &config-map-ref
|
||||||
|
kind: ConfigMap
|
||||||
|
name: kustomize-vars
|
||||||
|
apiVersion: v1
|
||||||
|
fieldref:
|
||||||
|
fieldpath: data.DBT_TARGET
|
||||||
|
- name: SUSPENDED
|
||||||
|
objref: *config-map-ref
|
||||||
|
fieldref:
|
||||||
|
fieldpath: data.SUSPENDED
|
||||||
|
`)
|
||||||
|
th.WriteF("workflow.yaml", `
|
||||||
|
apiVersion: argoproj.io/v1alpha1
|
||||||
|
kind: CronWorkflow
|
||||||
|
metadata:
|
||||||
|
name: cron-core-load-workflow
|
||||||
|
spec:
|
||||||
|
schedule: "45 2 * * *"
|
||||||
|
timezone: "Europe/Vienna"
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
suspend: $(SUSPENDED)
|
||||||
|
workflowMetadata:
|
||||||
|
labels:
|
||||||
|
workflowName: core-load-workflow
|
||||||
|
workflowSpec:
|
||||||
|
workflowTemplateRef:
|
||||||
|
name: core-load-pipeline
|
||||||
|
arguments:
|
||||||
|
parameters:
|
||||||
|
- name: dbt_target
|
||||||
|
value: $(DBT_TARGET)
|
||||||
|
`)
|
||||||
|
th.WriteF("kustomization-config.yaml", `
|
||||||
|
nameReference:
|
||||||
|
- kind: ConfigMap
|
||||||
|
version: v1
|
||||||
|
fieldSpecs:
|
||||||
|
- kind: CronWorkflow
|
||||||
|
version: v1alpha1
|
||||||
|
path: spec/workflowSpec/arguments/parameters/value
|
||||||
|
varReference:
|
||||||
|
- path: spec/workflowSpec/arguments/parameters/value
|
||||||
|
kind: CronWorkflow
|
||||||
|
apiVersion: argoproj.io/v1alpha1
|
||||||
|
- path: spec
|
||||||
|
kind: CronWorkflow
|
||||||
|
apiVersion: argoproj.io/v1alpha1
|
||||||
|
`)
|
||||||
|
th.WriteF("vars.env", `
|
||||||
|
DBT_TARGET=development
|
||||||
|
SUSPENDED=True
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: argoproj.io/v1alpha1
|
||||||
|
kind: CronWorkflow
|
||||||
|
metadata:
|
||||||
|
name: cron-core-load-workflow
|
||||||
|
spec:
|
||||||
|
concurrencyPolicy: Forbid
|
||||||
|
schedule: 45 2 * * *
|
||||||
|
suspend: "True"
|
||||||
|
timezone: Europe/Vienna
|
||||||
|
workflowMetadata:
|
||||||
|
labels:
|
||||||
|
workflowName: core-load-workflow
|
||||||
|
workflowSpec:
|
||||||
|
arguments:
|
||||||
|
parameters:
|
||||||
|
- name: dbt_target
|
||||||
|
value: development
|
||||||
|
workflowTemplateRef:
|
||||||
|
name: core-load-pipeline
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
data:
|
||||||
|
DBT_TARGET: development
|
||||||
|
SUSPENDED: "True"
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: kustomize-vars-7mhm8cg5kg
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func TestVarRefBig(t *testing.T) {
|
func TestVarRefBig(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
@@ -925,7 +1106,64 @@ metadata:
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVariableRefIngress(t *testing.T) {
|
func TestVariableRefIngressBasic(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
th.WriteK(".", `
|
||||||
|
resources:
|
||||||
|
- ingress.yaml
|
||||||
|
- deployment.yaml
|
||||||
|
|
||||||
|
vars:
|
||||||
|
- name: DEPLOYMENT_NAME
|
||||||
|
objref:
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: nginxDep
|
||||||
|
fieldref:
|
||||||
|
fieldpath: metadata.name
|
||||||
|
`)
|
||||||
|
th.WriteF("deployment.yaml", `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginxDep
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteF("ingress.yaml", `
|
||||||
|
apiVersion: networking.k8s.io/v1beta1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: nginxIngress
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: $(DEPLOYMENT_NAME).example.com
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- $(DEPLOYMENT_NAME).example.com
|
||||||
|
secretName: $(DEPLOYMENT_NAME).example.com-tls
|
||||||
|
`)
|
||||||
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: networking.k8s.io/v1beta1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: nginxIngress
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: nginxDep.example.com
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- nginxDep.example.com
|
||||||
|
secretName: nginxDep.example.com-tls
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginxDep
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVariableRefIngressOverlay(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app/base", `
|
th.WriteK("/app/base", `
|
||||||
resources:
|
resources:
|
||||||
@@ -1972,67 +2210,64 @@ spec:
|
|||||||
|
|
||||||
func TestDeploymentAnnotations(t *testing.T) {
|
func TestDeploymentAnnotations(t *testing.T) {
|
||||||
th := kusttest_test.MakeHarness(t)
|
th := kusttest_test.MakeHarness(t)
|
||||||
th.WriteK("/app", `
|
th.WriteK(".", `
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
|
||||||
kind: Kustomization
|
|
||||||
|
|
||||||
configMapGenerator:
|
configMapGenerator:
|
||||||
- name: testConfigMap
|
- name: theConfigMap
|
||||||
envs:
|
envs:
|
||||||
- test.properties
|
- test.properties
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
- name: FOO
|
- name: SOMERIVER
|
||||||
objref:
|
objref:
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
name: testConfigMap
|
name: theConfigMap
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
fieldref:
|
fieldref:
|
||||||
fieldpath: data.foo
|
fieldpath: data.waterway
|
||||||
|
|
||||||
commonAnnotations:
|
commonAnnotations:
|
||||||
foo: $(FOO)
|
river: $(SOMERIVER)
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
`)
|
`)
|
||||||
|
|
||||||
th.WriteF("/app/deployment.yaml", `
|
th.WriteF("deployment.yaml", `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: test
|
name: theDeployment
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: test
|
- name: test
|
||||||
`)
|
`)
|
||||||
th.WriteF("/app/test.properties", `foo=bar`)
|
th.WriteF("test.properties", `waterway=mississippi`)
|
||||||
m := th.Run("/app", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, `
|
th.AssertActualEqualsExpected(m, `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
foo: bar
|
river: mississippi
|
||||||
name: test
|
name: theDeployment
|
||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
foo: bar
|
river: mississippi
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: test
|
- name: test
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
foo: bar
|
waterway: mississippi
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
foo: bar
|
river: mississippi
|
||||||
name: testConfigMap-798k5k7g9f
|
name: theConfigMap-hdd8h8cgdt
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
"sigs.k8s.io/kustomize/api/internal/git"
|
"sigs.k8s.io/kustomize/api/internal/git"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type remoteTargetSpec struct {
|
type remoteTargetSpec struct {
|
||||||
@@ -93,22 +93,7 @@ func getRemoteTarget(rs *remoteTargetSpec) error {
|
|||||||
},
|
},
|
||||||
Options: opts,
|
Options: opts,
|
||||||
}
|
}
|
||||||
|
return utils.TimedCall("go-getter client.Get", 21*time.Second, client.Get)
|
||||||
ch := make(chan bool, 1)
|
|
||||||
defer close(ch)
|
|
||||||
d := 21 * time.Second // arbitrary
|
|
||||||
timer := time.NewTimer(d)
|
|
||||||
defer timer.Stop()
|
|
||||||
go func() {
|
|
||||||
err = client.Get()
|
|
||||||
ch <- true
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case <-ch:
|
|
||||||
case <-timer.C:
|
|
||||||
err = types.NewErrTimeOut(d, "go-getter client.Get")
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNothing(rs *remoteTargetSpec) error {
|
func getNothing(rs *remoteTargetSpec) error {
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ func (x Gvk) String() string {
|
|||||||
return strings.Join([]string{g, v, k}, fieldSep)
|
return strings.Join([]string{g, v, k}, fieldSep)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApiVersion returns the combination of Group and Version
|
||||||
|
func (x Gvk) ApiVersion() string {
|
||||||
|
if x.Group == "" {
|
||||||
|
return x.Version
|
||||||
|
}
|
||||||
|
return x.Group + "/" + x.Version
|
||||||
|
}
|
||||||
|
|
||||||
// StringWoEmptyField returns a string representation of the GVK. Non-exist
|
// StringWoEmptyField returns a string representation of the GVK. Non-exist
|
||||||
// fields will be omitted.
|
// fields will be omitted.
|
||||||
func (x Gvk) StringWoEmptyField() string {
|
func (x Gvk) StringWoEmptyField() string {
|
||||||
|
|||||||
@@ -1,18 +1,5 @@
|
|||||||
/*
|
// Copyright 2018 The Kubernetes Authors.
|
||||||
Copyright 2018 The Kubernetes Authors.
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package resid
|
package resid
|
||||||
|
|
||||||
@@ -112,17 +99,31 @@ var stringTests = []struct {
|
|||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestString(t *testing.T) {
|
||||||
for _, hey := range stringTests {
|
for _, hey := range stringTests {
|
||||||
if hey.x.String() != hey.s {
|
assert.Equal(t, hey.s, hey.x.String())
|
||||||
t.Fatalf("bad string for %v '%s'", hey.x, hey.s)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApiVersion(t *testing.T) {
|
||||||
|
for _, hey := range []struct {
|
||||||
|
x Gvk
|
||||||
|
exp string
|
||||||
|
}{
|
||||||
|
{Gvk{}, ""},
|
||||||
|
{Gvk{Kind: "k"}, ""},
|
||||||
|
{Gvk{Version: "v"}, "v"},
|
||||||
|
{Gvk{Version: "v", Kind: "k"}, "v"},
|
||||||
|
{Gvk{Group: "g"}, "g/"},
|
||||||
|
{Gvk{Group: "g", Kind: "k"}, "g/"},
|
||||||
|
{Gvk{Group: "g", Version: "v"}, "g/v"},
|
||||||
|
{Gvk{Group: "g", Version: "v", Kind: "k"}, "g/v"},
|
||||||
|
} {
|
||||||
|
assert.Equal(t, hey.exp, hey.x.ApiVersion())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringWoEmptyField(t *testing.T) {
|
func TestStringWoEmptyField(t *testing.T) {
|
||||||
for _, hey := range stringTests {
|
for _, hey := range stringTests {
|
||||||
if hey.x.StringWoEmptyField() != hey.r {
|
assert.Equal(t, hey.r, hey.x.StringWoEmptyField())
|
||||||
t.Fatalf("bad string %s for %v '%s'", hey.x.StringWoEmptyField(), hey.x, hey.r)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,12 +142,8 @@ func TestParseGroupVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
g, v := ParseGroupVersion(tc.input)
|
g, v := ParseGroupVersion(tc.input)
|
||||||
if g != tc.g {
|
assert.Equal(t, tc.g, g, tc.input)
|
||||||
t.Errorf("%s: expected group '%s', got '%s'", tc.input, tc.g, g)
|
assert.Equal(t, tc.v, v, tc.input)
|
||||||
}
|
|
||||||
if v != tc.v {
|
|
||||||
t.Errorf("%s: expected version '%s', got '%s'", tc.input, tc.v, v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,9 +249,7 @@ func TestSelectByGVK(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
filtered := tc.in.IsSelected(tc.filter)
|
filtered := tc.in.IsSelected(tc.filter)
|
||||||
if filtered != tc.expected {
|
assert.Equal(t, tc.expected, filtered, tc.description)
|
||||||
t.Fatalf("unexpected filter result for test case: %v", tc.description)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,10 +126,11 @@ func (rmF *Factory) FromSecretArgs(
|
|||||||
return rmF.FromResource(res), nil
|
return rmF.FromResource(res), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge creates a new ResMap by merging incoming resources.
|
// ConflatePatches creates a new ResMap containing a merger of the
|
||||||
|
// incoming patches.
|
||||||
// Error if conflict found.
|
// Error if conflict found.
|
||||||
func (rmF *Factory) Merge(incoming []*resource.Resource) (ResMap, error) {
|
func (rmF *Factory) ConflatePatches(patches []*resource.Resource) (ResMap, error) {
|
||||||
return (&merginator{cdf: rmF.cdf}).Merge(incoming)
|
return (&merginator{cdf: rmF.cdf}).ConflatePatches(patches)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newResMapFromResourceSlice(
|
func newResMapFromResourceSlice(
|
||||||
@@ -152,11 +153,11 @@ func (rmF *Factory) NewResMapFromRNodeSlice(rnodes []*yaml.RNode) (ResMap, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r, err := rmF.resF.FromBytes([]byte(s))
|
r, err := rmF.resF.SliceFromBytes([]byte(s))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resources = append(resources, r)
|
resources = append(resources, r...)
|
||||||
}
|
}
|
||||||
return newResMapFromResourceSlice(resources)
|
return newResMapFromResourceSlice(resources)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -277,7 +277,17 @@ func TestNewResMapFromSecretArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFromRNodeSlice(t *testing.T) {
|
func TestFromRNodeSlice(t *testing.T) {
|
||||||
input := `apiVersion: rbac.authorization.k8s.io/v1
|
type testcase struct {
|
||||||
|
input string
|
||||||
|
expected ResMap
|
||||||
|
}
|
||||||
|
testcases := map[string]testcase{
|
||||||
|
"no resource": {
|
||||||
|
input: "---",
|
||||||
|
expected: resmaptest_test.NewRmBuilder(t, rf).ResMap(),
|
||||||
|
},
|
||||||
|
"single resource": {
|
||||||
|
input: `apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
metadata:
|
metadata:
|
||||||
name: namespace-reader
|
name: namespace-reader
|
||||||
@@ -290,52 +300,64 @@ rules:
|
|||||||
- get
|
- get
|
||||||
- watch
|
- watch
|
||||||
- list
|
- list
|
||||||
`
|
`,
|
||||||
rnodes := []*yaml.RNode{
|
expected: resmaptest_test.NewRmBuilder(t, rf).Add(
|
||||||
yaml.MustParse(input),
|
|
||||||
}
|
|
||||||
|
|
||||||
rm, err := rmF.NewResMapFromRNodeSlice(rnodes)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := resmaptest_test.NewRmBuilder(t, rf).Add(
|
|
||||||
map[string]interface{}{
|
|
||||||
"apiVersion": "rbac.authorization.k8s.io/v1",
|
|
||||||
"kind": "ClusterRole",
|
|
||||||
"metadata": map[string]interface{}{
|
|
||||||
"name": "namespace-reader",
|
|
||||||
},
|
|
||||||
"rules": []interface{}{
|
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"apiGroups": []interface{}{
|
"apiVersion": "rbac.authorization.k8s.io/v1",
|
||||||
"",
|
"kind": "ClusterRole",
|
||||||
|
"metadata": map[string]interface{}{
|
||||||
|
"name": "namespace-reader",
|
||||||
},
|
},
|
||||||
"resources": []interface{}{
|
"rules": []interface{}{
|
||||||
"namespaces",
|
map[string]interface{}{
|
||||||
|
"apiGroups": []interface{}{
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
"resources": []interface{}{
|
||||||
|
"namespaces",
|
||||||
|
},
|
||||||
|
"verbs": []interface{}{
|
||||||
|
"get",
|
||||||
|
"watch",
|
||||||
|
"list",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"verbs": []interface{}{
|
}).ResMap(),
|
||||||
"get",
|
},
|
||||||
"watch",
|
"local config": {
|
||||||
"list",
|
// local config should be ignored
|
||||||
},
|
input: `apiVersion: v1
|
||||||
},
|
kind: ConfigMap
|
||||||
},
|
metadata:
|
||||||
}).ResMap()
|
name: my-config
|
||||||
|
annotations:
|
||||||
if err = expected.ErrorIfNotEqualLists(rm); err != nil {
|
config.kubernetes.io/local-config: 'true'
|
||||||
t.Fatalf("error: %s", err)
|
`,
|
||||||
|
expected: resmaptest_test.NewRmBuilder(t, rf).ResMap(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for name, tc := range testcases {
|
||||||
|
rnodes := []*yaml.RNode{
|
||||||
|
yaml.MustParse(tc.input),
|
||||||
|
}
|
||||||
|
rm, err := rmF.NewResMapFromRNodeSlice(rnodes)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error in test case [%s]: %v", name, err)
|
||||||
|
}
|
||||||
|
if err = tc.expected.ErrorIfNotEqualLists(rm); err != nil {
|
||||||
|
t.Fatalf("error in test case [%s]: %s", name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMerge_Empty(t *testing.T) {
|
func TestConflatePatches_Empty(t *testing.T) {
|
||||||
rm, err := rmF.Merge([]*resource.Resource{})
|
rm, err := rmF.ConflatePatches([]*resource.Resource{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, 0, rm.Size())
|
assert.Equal(t, 0, rm.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMerge(t *testing.T) {
|
func TestConflatePatches(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
yml []byte
|
yml []byte
|
||||||
@@ -365,12 +387,12 @@ spec:
|
|||||||
`))
|
`))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
rm, err := rmF.Merge([]*resource.Resource{r1, r2})
|
rm, err := rmF.ConflatePatches([]*resource.Resource{r1, r2})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
yml, err = rm.AsYaml()
|
yml, err = rm.AsYaml()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// TODO(#3304): DECISION - kyaml better; not a bug.
|
||||||
assert.Equal(t, konfig.IfApiMachineryElseKyaml(`apiVersion: example.com/v1
|
assert.Equal(t, konfig.IfApiMachineryElseKyaml(`apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type merginator struct {
|
|||||||
result ResMap
|
result ResMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *merginator) Merge(in []*resource.Resource) (ResMap, error) {
|
func (m *merginator) ConflatePatches(in []*resource.Resource) (ResMap, error) {
|
||||||
m.result = New()
|
m.result = New()
|
||||||
m.incoming = in
|
m.incoming = in
|
||||||
for index := range m.incoming {
|
for index := range m.incoming {
|
||||||
|
|||||||
@@ -245,4 +245,7 @@ type ResMap interface {
|
|||||||
// selected set of resources.
|
// selected set of resources.
|
||||||
ApplySmPatch(
|
ApplySmPatch(
|
||||||
selectedSet *resource.IdSet, patch *resource.Resource) error
|
selectedSet *resource.IdSet, patch *resource.Resource) error
|
||||||
|
|
||||||
|
// RemoveBuildAnnotations removes annotations created by the build process.
|
||||||
|
RemoveBuildAnnotations()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -456,8 +456,7 @@ func (m *resWrangler) AbsorbAll(other ResMap) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *resWrangler) appendReplaceOrMerge(
|
func (m *resWrangler) appendReplaceOrMerge(res *resource.Resource) error {
|
||||||
res *resource.Resource) error {
|
|
||||||
id := res.CurId()
|
id := res.CurId()
|
||||||
matches := m.GetMatchingResourcesByOriginalId(id.Equals)
|
matches := m.GetMatchingResourcesByOriginalId(id.Equals)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
@@ -471,10 +470,7 @@ func (m *resWrangler) appendReplaceOrMerge(
|
|||||||
"id %#v does not exist; cannot merge or replace", id)
|
"id %#v does not exist; cannot merge or replace", id)
|
||||||
default:
|
default:
|
||||||
// presumably types.BehaviorCreate
|
// presumably types.BehaviorCreate
|
||||||
err := m.Append(res)
|
return m.Append(res)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
old := matches[0]
|
old := matches[0]
|
||||||
@@ -487,9 +483,10 @@ func (m *resWrangler) appendReplaceOrMerge(
|
|||||||
}
|
}
|
||||||
switch res.Behavior() {
|
switch res.Behavior() {
|
||||||
case types.BehaviorReplace:
|
case types.BehaviorReplace:
|
||||||
res.Replace(old)
|
res.CopyMergeMetaDataFieldsFrom(old)
|
||||||
case types.BehaviorMerge:
|
case types.BehaviorMerge:
|
||||||
res.Merge(old)
|
res.CopyMergeMetaDataFieldsFrom(old)
|
||||||
|
res.MergeDataMapFrom(old)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"id %#v exists; behavior must be merge or replace", id)
|
"id %#v exists; behavior must be merge or replace", id)
|
||||||
@@ -499,14 +496,14 @@ func (m *resWrangler) appendReplaceOrMerge(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if i != index {
|
if i != index {
|
||||||
return fmt.Errorf("unexpected index in replacement")
|
return fmt.Errorf("unexpected target index in replacement")
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"found multiple objects %v that could accept merge of %v",
|
"found multiple objects %v that could accept merge of %v",
|
||||||
matches, id)
|
matches, id)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select returns a list of resources that
|
// Select returns a list of resources that
|
||||||
@@ -592,6 +589,7 @@ func (m *resWrangler) ApplySmPatch(
|
|||||||
patchCopy.SetName(res.GetName())
|
patchCopy.SetName(res.GetName())
|
||||||
patchCopy.SetNamespace(res.GetNamespace())
|
patchCopy.SetNamespace(res.GetNamespace())
|
||||||
patchCopy.SetGvk(res.GetGvk())
|
patchCopy.SetGvk(res.GetGvk())
|
||||||
|
patchCopy.SetOriginalName(res.GetOriginalName(), true)
|
||||||
err := res.ApplySmPatch(patchCopy)
|
err := res.ApplySmPatch(patchCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Check for an error string from UnmarshalJSON that's indicative
|
// Check for an error string from UnmarshalJSON that's indicative
|
||||||
@@ -622,3 +620,9 @@ func (m *resWrangler) ApplySmPatch(
|
|||||||
m.AppendAll(newRm)
|
m.AppendAll(newRm)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *resWrangler) RemoveBuildAnnotations() {
|
||||||
|
for _, r := range m.Resources() {
|
||||||
|
r.RemoveBuildAnnotations()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/api/konfig"
|
|
||||||
"sigs.k8s.io/kustomize/api/provider"
|
"sigs.k8s.io/kustomize/api/provider"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
. "sigs.k8s.io/kustomize/api/resmap"
|
. "sigs.k8s.io/kustomize/api/resmap"
|
||||||
@@ -694,10 +693,6 @@ func TestAbsorbAll(t *testing.T) {
|
|||||||
metadata := map[string]interface{}{
|
metadata := map[string]interface{}{
|
||||||
"name": "cmap",
|
"name": "cmap",
|
||||||
}
|
}
|
||||||
if !konfig.FlagEnableKyamlDefaultValue {
|
|
||||||
metadata["annotations"] = map[string]interface{}{}
|
|
||||||
metadata["labels"] = map[string]interface{}{}
|
|
||||||
}
|
|
||||||
expected := rmF.FromResource(rf.FromMapAndOption(
|
expected := rmF.FromResource(rf.FromMapAndOption(
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"apiVersion": "apps/v1",
|
"apiVersion": "apps/v1",
|
||||||
@@ -750,7 +745,6 @@ rules:
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rnodes, err := rm.ToRNodeSlice()
|
rnodes, err := rm.ToRNodeSlice()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
@@ -804,6 +798,34 @@ spec:
|
|||||||
errorExpected bool
|
errorExpected bool
|
||||||
errorMsg string
|
errorMsg string
|
||||||
}{
|
}{
|
||||||
|
"clown": {
|
||||||
|
base: []string{`apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 1
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
patches: []string{`apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
errorExpected: false,
|
||||||
|
expected: []string{
|
||||||
|
`apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
},
|
||||||
"confusion": {
|
"confusion": {
|
||||||
base: []string{`apiVersion: example.com/v1
|
base: []string{`apiVersion: example.com/v1
|
||||||
kind: Foo
|
kind: Foo
|
||||||
@@ -976,6 +998,7 @@ spec:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert.False(t, tc.errorExpected)
|
assert.False(t, tc.errorExpected)
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
yml, err := m.AsYaml()
|
yml, err := m.AsYaml()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, strings.Join(tc.expected, "---\n"), string(yml))
|
assert.Equal(t, strings.Join(tc.expected, "---\n"), string(yml))
|
||||||
@@ -1077,18 +1100,22 @@ $patch: delete
|
|||||||
finalMapSize: 0,
|
finalMapSize: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for name, test := range tests {
|
for name := range tests {
|
||||||
m, err := rmF.NewResMapFromBytes([]byte(target))
|
tc := tests[name]
|
||||||
assert.NoError(t, err, name)
|
t.Run(name, func(t *testing.T) {
|
||||||
idSet := resource.MakeIdSet(m.Resources())
|
m, err := rmF.NewResMapFromBytes([]byte(target))
|
||||||
assert.Equal(t, 1, idSet.Size(), name)
|
assert.NoError(t, err, name)
|
||||||
p, err := rf.FromBytes([]byte(test.patch))
|
idSet := resource.MakeIdSet(m.Resources())
|
||||||
assert.NoError(t, err, name)
|
assert.Equal(t, 1, idSet.Size(), name)
|
||||||
assert.NoError(t, m.ApplySmPatch(idSet, p), name)
|
p, err := rf.FromBytes([]byte(tc.patch))
|
||||||
assert.Equal(t, test.finalMapSize, m.Size(), name)
|
assert.NoError(t, err, name)
|
||||||
yml, err := m.AsYaml()
|
assert.NoError(t, m.ApplySmPatch(idSet, p), name)
|
||||||
assert.NoError(t, err, name)
|
assert.Equal(t, tc.finalMapSize, m.Size(), name)
|
||||||
assert.Equal(t, test.expected, string(yml), name)
|
m.RemoveBuildAnnotations()
|
||||||
|
yml, err := m.AsYaml()
|
||||||
|
assert.NoError(t, err, name)
|
||||||
|
assert.Equal(t, tc.expected, string(yml), name)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,17 +35,17 @@ func (rf *Factory) FromMap(m map[string]interface{}) *Resource {
|
|||||||
|
|
||||||
// FromMapWithName returns a new instance with the given "original" name.
|
// FromMapWithName returns a new instance with the given "original" name.
|
||||||
func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource {
|
func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource {
|
||||||
return rf.makeOne(rf.kf.FromMap(m), nil).setOriginalName(n)
|
return rf.makeOne(rf.kf.FromMap(m), nil).SetOriginalName(n, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromMapWithNamespace returns a new instance with the given "original" namespace.
|
// FromMapWithNamespace returns a new instance with the given "original" namespace.
|
||||||
func (rf *Factory) FromMapWithNamespace(n string, m map[string]interface{}) *Resource {
|
func (rf *Factory) FromMapWithNamespace(n string, m map[string]interface{}) *Resource {
|
||||||
return rf.makeOne(rf.kf.FromMap(m), nil).setOriginalNs(n)
|
return rf.makeOne(rf.kf.FromMap(m), nil).SetOriginalNs(n, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromMapWithNamespaceAndName returns a new instance with the given "original" namespace.
|
// FromMapWithNamespaceAndName returns a new instance with the given "original" namespace.
|
||||||
func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource {
|
func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource {
|
||||||
return rf.makeOne(rf.kf.FromMap(m), nil).setOriginalNs(ns).setOriginalName(n)
|
return rf.makeOne(rf.kf.FromMap(m), nil).SetOriginalNs(ns, true).SetOriginalName(n, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FromMapAndOption returns a new instance of Resource with given options.
|
// FromMapAndOption returns a new instance of Resource with given options.
|
||||||
@@ -72,7 +72,7 @@ func (rf *Factory) makeOne(
|
|||||||
kunStr: u,
|
kunStr: u,
|
||||||
options: o,
|
options: o,
|
||||||
}
|
}
|
||||||
return r.setOriginalName(r.kunStr.GetName()).setOriginalNs(r.GetNamespace())
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// SliceFromPatches returns a slice of resources given a patch path
|
// SliceFromPatches returns a slice of resources given a patch path
|
||||||
@@ -157,7 +157,7 @@ func (rf *Factory) SliceFromBytesWithNames(names []string, in []byte) ([]*Resour
|
|||||||
return nil, fmt.Errorf("number of names doesn't match number of resources")
|
return nil, fmt.Errorf("number of names doesn't match number of resources")
|
||||||
}
|
}
|
||||||
for i, res := range result {
|
for i, res := range result {
|
||||||
res.originalName = names[i]
|
res.SetOriginalName(names[i], true)
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -343,14 +343,13 @@ kind: List
|
|||||||
name: "listWithAnchorReference",
|
name: "listWithAnchorReference",
|
||||||
input: []types.PatchStrategicMerge{patchList2},
|
input: []types.PatchStrategicMerge{patchList2},
|
||||||
expectedOut: []*Resource{testDeploymentA, testDeploymentB},
|
expectedOut: []*Resource{testDeploymentA, testDeploymentB},
|
||||||
// See https://github.com/kubernetes-sigs/kustomize/issues/3271
|
|
||||||
// This test should not have an error, but does when kyaml is used.
|
|
||||||
// The error using kyaml is:
|
// The error using kyaml is:
|
||||||
// json: unsupported type: map[interface {}]interface {}
|
// json: unsupported type: map[interface {}]interface {}
|
||||||
// probably arising from too many conversions between
|
// maybe arising from too many conversions between
|
||||||
// yaml, json, Resource, RNode, Unstructured etc.
|
// yaml, json, Resource, RNode, Unstructured etc.
|
||||||
// These conversions can be removed after closing
|
// These conversions go away after closing #3506
|
||||||
// https://github.com/kubernetes-sigs/kustomize/issues/2506
|
// TODO(#3271) This shouldn't have an error, but does when kyaml is used.
|
||||||
|
// TODO(#3304): DECISION - still a bug, but not a blocker to #3304 or #2506
|
||||||
expectedErr: konfig.FlagEnableKyamlDefaultValue,
|
expectedErr: konfig.FlagEnableKyamlDefaultValue,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ import (
|
|||||||
|
|
||||||
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
|
||||||
"sigs.k8s.io/kustomize/api/ifc"
|
"sigs.k8s.io/kustomize/api/ifc"
|
||||||
|
"sigs.k8s.io/kustomize/api/internal/wrappy"
|
||||||
|
"sigs.k8s.io/kustomize/api/konfig"
|
||||||
"sigs.k8s.io/kustomize/api/resid"
|
"sigs.k8s.io/kustomize/api/resid"
|
||||||
"sigs.k8s.io/kustomize/api/types"
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
"sigs.k8s.io/kustomize/kyaml/filtersutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
|
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,16 +24,19 @@ import (
|
|||||||
// paired with metadata used by kustomize.
|
// paired with metadata used by kustomize.
|
||||||
// For more history, see sigs.k8s.io/kustomize/api/ifc.Unstructured
|
// For more history, see sigs.k8s.io/kustomize/api/ifc.Unstructured
|
||||||
type Resource struct {
|
type Resource struct {
|
||||||
kunStr ifc.Kunstructured
|
kunStr ifc.Kunstructured
|
||||||
originalName string
|
options *types.GenArgs
|
||||||
originalNs string
|
refBy []resid.ResId
|
||||||
options *types.GenArgs
|
refVarNames []string
|
||||||
refBy []resid.ResId
|
|
||||||
refVarNames []string
|
|
||||||
namePrefixes []string
|
|
||||||
nameSuffixes []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
buildAnnotationOriginalName = konfig.ConfigAnnoDomain + "/originalName"
|
||||||
|
buildAnnotationPrefixes = konfig.ConfigAnnoDomain + "/prefixes"
|
||||||
|
buildAnnotationSuffixes = konfig.ConfigAnnoDomain + "/suffixes"
|
||||||
|
buildAnnotationOriginalNamespace = konfig.ConfigAnnoDomain + "/originalNs"
|
||||||
|
)
|
||||||
|
|
||||||
func (r *Resource) ResetPrimaryData(incoming *Resource) {
|
func (r *Resource) ResetPrimaryData(incoming *Resource) {
|
||||||
r.kunStr = incoming.Copy()
|
r.kunStr = incoming.Copy()
|
||||||
}
|
}
|
||||||
@@ -46,6 +53,10 @@ func (r *Resource) GetFieldValue(f string) (interface{}, error) {
|
|||||||
return r.kunStr.GetFieldValue(f)
|
return r.kunStr.GetFieldValue(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resource) GetDataMap() map[string]string {
|
||||||
|
return r.kunStr.GetDataMap()
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Resource) GetGvk() resid.Gvk {
|
func (r *Resource) GetGvk() resid.Gvk {
|
||||||
return r.kunStr.GetGvk()
|
return r.kunStr.GetGvk()
|
||||||
}
|
}
|
||||||
@@ -91,14 +102,28 @@ func (r *Resource) MatchesAnnotationSelector(selector string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) SetAnnotations(m map[string]string) {
|
func (r *Resource) SetAnnotations(m map[string]string) {
|
||||||
|
if len(m) == 0 {
|
||||||
|
// Force field erasure.
|
||||||
|
r.kunStr.SetAnnotations(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
r.kunStr.SetAnnotations(m)
|
r.kunStr.SetAnnotations(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resource) SetDataMap(m map[string]string) {
|
||||||
|
r.kunStr.SetDataMap(m)
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Resource) SetGvk(gvk resid.Gvk) {
|
func (r *Resource) SetGvk(gvk resid.Gvk) {
|
||||||
r.kunStr.SetGvk(gvk)
|
r.kunStr.SetGvk(gvk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) SetLabels(m map[string]string) {
|
func (r *Resource) SetLabels(m map[string]string) {
|
||||||
|
if len(m) == 0 {
|
||||||
|
// Force field erasure.
|
||||||
|
r.kunStr.SetLabels(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
r.kunStr.SetLabels(m)
|
r.kunStr.SetLabels(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,23 +164,25 @@ func (r *Resource) DeepCopy() *Resource {
|
|||||||
return rc
|
return rc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace performs replace with other resource.
|
// CopyMergeMetaDataFields copies everything but the non-metadata in
|
||||||
func (r *Resource) Replace(other *Resource) {
|
// the ifc.Kunstructured map, merging labels and annotations.
|
||||||
|
func (r *Resource) CopyMergeMetaDataFieldsFrom(other *Resource) {
|
||||||
r.SetLabels(mergeStringMaps(other.GetLabels(), r.GetLabels()))
|
r.SetLabels(mergeStringMaps(other.GetLabels(), r.GetLabels()))
|
||||||
r.SetAnnotations(mergeStringMaps(other.GetAnnotations(), r.GetAnnotations()))
|
r.SetAnnotations(
|
||||||
|
mergeStringMaps(other.GetAnnotations(), r.GetAnnotations()))
|
||||||
r.SetName(other.GetName())
|
r.SetName(other.GetName())
|
||||||
r.SetNamespace(other.GetNamespace())
|
r.SetNamespace(other.GetNamespace())
|
||||||
r.copyOtherFields(other)
|
r.copyOtherFields(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) copyOtherFields(other *Resource) {
|
func (r *Resource) copyOtherFields(other *Resource) {
|
||||||
r.originalName = other.originalName
|
|
||||||
r.originalNs = other.originalNs
|
|
||||||
r.options = other.options
|
r.options = other.options
|
||||||
r.refBy = other.copyRefBy()
|
r.refBy = other.copyRefBy()
|
||||||
r.refVarNames = copyStringSlice(other.refVarNames)
|
r.refVarNames = copyStringSlice(other.refVarNames)
|
||||||
r.namePrefixes = copyStringSlice(other.namePrefixes)
|
}
|
||||||
r.nameSuffixes = copyStringSlice(other.nameSuffixes)
|
|
||||||
|
func (r *Resource) MergeDataMapFrom(o *Resource) {
|
||||||
|
r.SetDataMap(mergeStringMaps(o.GetDataMap(), r.GetDataMap()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) ErrIfNotEquals(o *Resource) error {
|
func (r *Resource) ErrIfNotEquals(o *Resource) error {
|
||||||
@@ -198,12 +225,6 @@ func (r *Resource) KunstructEqual(o *Resource) bool {
|
|||||||
return reflect.DeepEqual(r.kunStr, o.kunStr)
|
return reflect.DeepEqual(r.kunStr, o.kunStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge performs merge with other resource.
|
|
||||||
func (r *Resource) Merge(other *Resource) {
|
|
||||||
r.Replace(other)
|
|
||||||
mergeConfigmap(r.Map(), other.Map(), r.Map())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Resource) copyRefBy() []resid.ResId {
|
func (r *Resource) copyRefBy() []resid.ResId {
|
||||||
if r.refBy == nil {
|
if r.refBy == nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -224,28 +245,46 @@ func copyStringSlice(s []string) []string {
|
|||||||
|
|
||||||
// Implements ResCtx AddNamePrefix
|
// Implements ResCtx AddNamePrefix
|
||||||
func (r *Resource) AddNamePrefix(p string) {
|
func (r *Resource) AddNamePrefix(p string) {
|
||||||
r.namePrefixes = append(r.namePrefixes, p)
|
r.addAdditiveAnnotation(buildAnnotationPrefixes, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ResCtx AddNameSuffix
|
// Implements ResCtx AddNameSuffix
|
||||||
func (r *Resource) AddNameSuffix(s string) {
|
func (r *Resource) AddNameSuffix(s string) {
|
||||||
r.nameSuffixes = append(r.nameSuffixes, s)
|
r.addAdditiveAnnotation(buildAnnotationSuffixes, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) addAdditiveAnnotation(name, value string) {
|
||||||
|
if value == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
if annotations == nil {
|
||||||
|
annotations = make(map[string]string)
|
||||||
|
}
|
||||||
|
if existing, ok := annotations[name]; ok {
|
||||||
|
annotations[name] = existing + "," + value
|
||||||
|
} else {
|
||||||
|
annotations[name] = value
|
||||||
|
}
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ResCtx GetOutermostNamePrefix
|
// Implements ResCtx GetOutermostNamePrefix
|
||||||
func (r *Resource) GetOutermostNamePrefix() string {
|
func (r *Resource) GetOutermostNamePrefix() string {
|
||||||
if len(r.namePrefixes) == 0 {
|
namePrefixes := r.GetNamePrefixes()
|
||||||
|
if len(namePrefixes) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return r.namePrefixes[len(r.namePrefixes)-1]
|
return namePrefixes[len(namePrefixes)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ResCtx GetOutermostNameSuffix
|
// Implements ResCtx GetOutermostNameSuffix
|
||||||
func (r *Resource) GetOutermostNameSuffix() string {
|
func (r *Resource) GetOutermostNameSuffix() string {
|
||||||
if len(r.nameSuffixes) == 0 {
|
nameSuffixes := r.GetNameSuffixes()
|
||||||
|
if len(nameSuffixes) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return r.nameSuffixes[len(r.nameSuffixes)-1]
|
return nameSuffixes[len(nameSuffixes)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func sameEndingSubarray(a, b []string) bool {
|
func sameEndingSubarray(a, b []string) bool {
|
||||||
@@ -270,12 +309,20 @@ func sameEndingSubarray(a, b []string) bool {
|
|||||||
|
|
||||||
// Implements ResCtx GetNamePrefixes
|
// Implements ResCtx GetNamePrefixes
|
||||||
func (r *Resource) GetNamePrefixes() []string {
|
func (r *Resource) GetNamePrefixes() []string {
|
||||||
return r.namePrefixes
|
annotations := r.GetAnnotations()
|
||||||
|
if _, ok := annotations[buildAnnotationPrefixes]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return strings.Split(annotations[buildAnnotationPrefixes], ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements ResCtx GetNameSuffixes
|
// Implements ResCtx GetNameSuffixes
|
||||||
func (r *Resource) GetNameSuffixes() []string {
|
func (r *Resource) GetNameSuffixes() []string {
|
||||||
return r.nameSuffixes
|
annotations := r.GetAnnotations()
|
||||||
|
if _, ok := annotations[buildAnnotationSuffixes]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return strings.Split(annotations[buildAnnotationSuffixes], ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutermostPrefixSuffixEquals returns true if both resources
|
// OutermostPrefixSuffixEquals returns true if both resources
|
||||||
@@ -299,23 +346,65 @@ func (r *Resource) PrefixesSuffixesEquals(o ResCtx) bool {
|
|||||||
return sameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && sameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
|
return sameEndingSubarray(r.GetNamePrefixes(), o.GetNamePrefixes()) && sameEndingSubarray(r.GetNameSuffixes(), o.GetNameSuffixes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) GetOriginalName() string {
|
// RemoveBuildAnnotations removes annotations created by the build process.
|
||||||
return r.originalName
|
// These are internal-only to kustomize, added to the data pipeline to
|
||||||
|
// track name changes so name references can be fixed.
|
||||||
|
func (r *Resource) RemoveBuildAnnotations() {
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
if len(annotations) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
delete(annotations, buildAnnotationOriginalName)
|
||||||
|
delete(annotations, buildAnnotationPrefixes)
|
||||||
|
delete(annotations, buildAnnotationSuffixes)
|
||||||
|
delete(annotations, buildAnnotationOriginalNamespace)
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Making this public would be bad.
|
func (r *Resource) GetOriginalName() string {
|
||||||
func (r *Resource) setOriginalName(n string) *Resource {
|
annotations := r.GetAnnotations()
|
||||||
r.originalName = n
|
if name, ok := annotations[buildAnnotationOriginalName]; ok {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
return r.kunStr.GetName()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Resource) SetOriginalName(n string, overwrite bool) *Resource {
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
if annotations == nil {
|
||||||
|
annotations = make(map[string]string)
|
||||||
|
}
|
||||||
|
if _, ok := annotations[buildAnnotationOriginalName]; !ok || overwrite {
|
||||||
|
annotations[buildAnnotationOriginalName] = n
|
||||||
|
}
|
||||||
|
r.kunStr.SetAnnotations(annotations)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resource) GetOriginalNs() string {
|
func (r *Resource) GetOriginalNs() string {
|
||||||
return r.originalNs
|
annotations := r.GetAnnotations()
|
||||||
|
if ns, ok := annotations[buildAnnotationOriginalNamespace]; ok {
|
||||||
|
return ns
|
||||||
|
}
|
||||||
|
ns := r.GetNamespace()
|
||||||
|
if ns == "default" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return ns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Making this public would be bad.
|
func (r *Resource) SetOriginalNs(n string, overwrite bool) *Resource {
|
||||||
func (r *Resource) setOriginalNs(n string) *Resource {
|
if n == "" {
|
||||||
r.originalNs = n
|
n = "default"
|
||||||
|
}
|
||||||
|
annotations := r.GetAnnotations()
|
||||||
|
if annotations == nil {
|
||||||
|
annotations = make(map[string]string)
|
||||||
|
}
|
||||||
|
if _, ok := annotations[buildAnnotationOriginalNamespace]; !ok || overwrite {
|
||||||
|
annotations[buildAnnotationOriginalNamespace] = n
|
||||||
|
}
|
||||||
|
r.SetAnnotations(annotations)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,9 +493,12 @@ func (r *Resource) ApplySmPatch(patch *Resource) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
n, ns := r.GetName(), r.GetNamespace()
|
n, ns := r.GetName(), r.GetNamespace()
|
||||||
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
|
err = r.ApplyFilter(patchstrategicmerge.Filter{
|
||||||
Patch: node,
|
Patch: node,
|
||||||
}, r)
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !r.IsEmpty() {
|
if !r.IsEmpty() {
|
||||||
r.SetName(n)
|
r.SetName(n)
|
||||||
r.SetNamespace(ns)
|
r.SetNamespace(ns)
|
||||||
@@ -414,20 +506,16 @@ func (r *Resource) ApplySmPatch(patch *Resource) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add BinaryData once we sync to new k8s.io/api
|
func (r *Resource) ApplyFilter(f kio.Filter) error {
|
||||||
func mergeConfigmap(
|
if wn, ok := r.kunStr.(*wrappy.WNode); ok {
|
||||||
mergedTo map[string]interface{},
|
l, err := f.Filter([]*kyaml.RNode{wn.AsRNode()})
|
||||||
maps ...map[string]interface{}) {
|
if len(l) == 0 {
|
||||||
mergedMap := map[string]interface{}{}
|
// Hack to deal with deletion.
|
||||||
for _, m := range maps {
|
r.kunStr = wrappy.NewWNode()
|
||||||
datamap, ok := m["data"].(map[string]interface{})
|
|
||||||
if ok {
|
|
||||||
for key, value := range datamap {
|
|
||||||
mergedMap[key] = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
mergedTo["data"] = mergedMap
|
return filtersutil.ApplyToJSON(f, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeStringMaps(maps ...map[string]string) map[string]string {
|
func mergeStringMaps(maps ...map[string]string) map[string]string {
|
||||||
|
|||||||
@@ -250,6 +250,73 @@ spec:
|
|||||||
`, string(bytes))
|
`, string(bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplySmPatch_3(t *testing.T) {
|
||||||
|
resource, err := factory.FromBytes([]byte(`
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 1
|
||||||
|
`))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
patch, err := factory.FromBytes([]byte(`
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NoError(t, resource.ApplySmPatch(patch))
|
||||||
|
bytes, err := resource.AsYAML()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, `apiVersion: v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
spec:
|
||||||
|
numReplicas: 999
|
||||||
|
`, string(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMergeDataMapFrom(t *testing.T) {
|
||||||
|
resource, err := factory.FromBytes([]byte(`
|
||||||
|
apiVersion: v1
|
||||||
|
kind: BlahBlah
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
data:
|
||||||
|
fruit: pear
|
||||||
|
`))
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
patch, err := factory.FromBytes([]byte(`
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Whatever
|
||||||
|
metadata:
|
||||||
|
name: spaceship
|
||||||
|
data:
|
||||||
|
spaceship: enterprise
|
||||||
|
`))
|
||||||
|
if !assert.NoError(t, err) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
resource.MergeDataMapFrom(patch)
|
||||||
|
bytes, err := resource.AsYAML()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, `apiVersion: v1
|
||||||
|
data:
|
||||||
|
fruit: pear
|
||||||
|
spaceship: enterprise
|
||||||
|
kind: BlahBlah
|
||||||
|
metadata:
|
||||||
|
name: clown
|
||||||
|
`, string(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
func TestApplySmPatch_SwapOrder(t *testing.T) {
|
func TestApplySmPatch_SwapOrder(t *testing.T) {
|
||||||
s1 := `
|
s1 := `
|
||||||
apiVersion: example.com/v1
|
apiVersion: example.com/v1
|
||||||
@@ -628,6 +695,325 @@ spec:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetOriginalNameAndNs(t *testing.T) {
|
||||||
|
input := `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName`
|
||||||
|
|
||||||
|
factory := provider.NewDefaultDepProvider().GetResourceFactory()
|
||||||
|
resources, err := factory.SliceFromBytes([]byte(input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := resources[0]
|
||||||
|
res.SetOriginalName("oldName", false)
|
||||||
|
res.SetOriginalNs("default", false)
|
||||||
|
|
||||||
|
expected := `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
config.kubernetes.io/originalNs: default
|
||||||
|
name: newName
|
||||||
|
`
|
||||||
|
bytes, err := res.AsYAML()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, string(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetOriginalName(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// no name annotation, return the name
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: mySecret`,
|
||||||
|
expected: "mySecret",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// return name from name annotation
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
name: newName`,
|
||||||
|
expected: "oldName",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
factory := provider.NewDefaultDepProvider().GetResourceFactory()
|
||||||
|
resources, err := factory.SliceFromBytes([]byte(test.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expected, resources[0].GetOriginalName())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetOriginalName(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
originalName string
|
||||||
|
overwrite bool
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// no original name set, overwrite is false
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName`,
|
||||||
|
originalName: "oldName",
|
||||||
|
overwrite: false,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// no original name set, overwrite is true
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName`,
|
||||||
|
originalName: "oldName",
|
||||||
|
overwrite: true,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// original name is set, overwrite is false, resource shouldn't change
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
name: newName`,
|
||||||
|
originalName: "newOriginalName",
|
||||||
|
overwrite: false,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// original name is set, overwrite is true, resource should change
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: oldName
|
||||||
|
name: newName`,
|
||||||
|
originalName: "newOriginalName",
|
||||||
|
overwrite: true,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalName: newOriginalName
|
||||||
|
name: newName
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
factory := provider.NewDefaultDepProvider().GetResourceFactory()
|
||||||
|
resources, err := factory.SliceFromBytes([]byte(test.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := resources[0]
|
||||||
|
res.SetOriginalName(test.originalName, test.overwrite)
|
||||||
|
|
||||||
|
bytes, err := res.AsYAML()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expected, string(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetOriginalNs(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// no namespace, return default
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: mySecret`,
|
||||||
|
expected: "",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// return old namespace
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: oldNamespace
|
||||||
|
name: mySecret
|
||||||
|
namespace: myNamespace`,
|
||||||
|
expected: "oldNamespace",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// return namespace
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: mySecret
|
||||||
|
namespace: myNamespace`,
|
||||||
|
expected: "myNamespace",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
factory := provider.NewDefaultDepProvider().GetResourceFactory()
|
||||||
|
resources, err := factory.SliceFromBytes([]byte(test.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expected, resources[0].GetOriginalNs())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetOriginalNs(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
originalNs string
|
||||||
|
overwrite bool
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// no original namespace set, overwrite is false
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace`,
|
||||||
|
originalNs: "oldNamespace",
|
||||||
|
overwrite: false,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: oldNamespace
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// no original name set, overwrite is true
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace`,
|
||||||
|
|
||||||
|
originalNs: "oldNamespace",
|
||||||
|
overwrite: true,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: oldNamespace
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// original name is set, overwrite is false, resource shouldn't change
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: oldNamespace
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace`,
|
||||||
|
originalNs: "newOriginalNamespace",
|
||||||
|
overwrite: false,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: oldNamespace
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
// original name is set, overwrite is true, resource should change
|
||||||
|
input: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: oldNamespace
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace`,
|
||||||
|
originalNs: "newOriginalNamespace",
|
||||||
|
overwrite: true,
|
||||||
|
expected: `apiVersion: apps/v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
config.kubernetes.io/originalNs: newOriginalNamespace
|
||||||
|
name: newName
|
||||||
|
namespace: newNamespace
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
factory := provider.NewDefaultDepProvider().GetResourceFactory()
|
||||||
|
resources, err := factory.SliceFromBytes([]byte(test.input))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := resources[0]
|
||||||
|
res.SetOriginalNs(test.originalNs, test.overwrite)
|
||||||
|
|
||||||
|
bytes, err := res.AsYAML()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expected, string(bytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// baseResource produces a base object which used to test
|
// baseResource produces a base object which used to test
|
||||||
// patch transformation
|
// patch transformation
|
||||||
// Also the structure is matching the Deployment syntax
|
// Also the structure is matching the Deployment syntax
|
||||||
|
|||||||
@@ -126,6 +126,11 @@ func (th Harness) AssertActualEqualsExpected(
|
|||||||
th.AssertActualEqualsExpectedWithTweak(m, nil, expected)
|
th.AssertActualEqualsExpectedWithTweak(m, nil, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (th Harness) AssertActualEqualsExpectedNoIdAnnotations(m resmap.ResMap, expected string) {
|
||||||
|
m.RemoveBuildAnnotations()
|
||||||
|
th.AssertActualEqualsExpectedWithTweak(m, nil, expected)
|
||||||
|
}
|
||||||
|
|
||||||
func (th Harness) AssertActualEqualsExpectedWithTweak(
|
func (th Harness) AssertActualEqualsExpectedWithTweak(
|
||||||
m resmap.ResMap, tweaker func([]byte) []byte, expected string) {
|
m resmap.ResMap, tweaker func([]byte) []byte, expected string) {
|
||||||
assertActualEqualsExpectedWithTweak(th, m, tweaker, expected)
|
assertActualEqualsExpectedWithTweak(th, m, tweaker, expected)
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ func (th *HarnessEnhanced) LoadAndRunGenerator(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
th.t.Fatalf("Err: %v", err)
|
th.t.Fatalf("Err: %v", err)
|
||||||
}
|
}
|
||||||
|
rm.RemoveBuildAnnotations()
|
||||||
return rm
|
return rm
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ func (th *HarnessEnhanced) LoadAndRunTransformer(
|
|||||||
func (th *HarnessEnhanced) RunTransformerAndCheckResult(
|
func (th *HarnessEnhanced) RunTransformerAndCheckResult(
|
||||||
config, input, expected string) {
|
config, input, expected string) {
|
||||||
resMap := th.LoadAndRunTransformer(config, input)
|
resMap := th.LoadAndRunTransformer(config, input)
|
||||||
th.AssertActualEqualsExpected(resMap, expected)
|
th.AssertActualEqualsExpectedNoIdAnnotations(resMap, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (th *HarnessEnhanced) ErrorFromLoadAndRunTransformer(
|
func (th *HarnessEnhanced) ErrorFromLoadAndRunTransformer(
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ type HelmChartArgs struct {
|
|||||||
ChartRepoURL string `json:"chartRepoUrl,omitempty" yaml:"chartRepoUrl,omitempty"`
|
ChartRepoURL string `json:"chartRepoUrl,omitempty" yaml:"chartRepoUrl,omitempty"`
|
||||||
ChartHome string `json:"chartHome,omitempty" yaml:"chartHome,omitempty"`
|
ChartHome string `json:"chartHome,omitempty" yaml:"chartHome,omitempty"`
|
||||||
// Use chartRelease to keep compatible with old exec plugin
|
// Use chartRelease to keep compatible with old exec plugin
|
||||||
ChartRepoName string `json:"chartRelease,omitempty" yaml:"chartRelease,omitempty"`
|
ChartRepoName string `json:"chartRelease,omitempty" yaml:"chartRelease,omitempty"`
|
||||||
HelmBin string `json:"helmBin,omitempty" yaml:"helmBin,omitempty"`
|
HelmBin string `json:"helmBin,omitempty" yaml:"helmBin,omitempty"`
|
||||||
HelmHome string `json:"helmHome,omitempty" yaml:"helmHome,omitempty"`
|
HelmHome string `json:"helmHome,omitempty" yaml:"helmHome,omitempty"`
|
||||||
Values string `json:"values,omitempty" yaml:"values,omitempty"`
|
Values string `json:"values,omitempty" yaml:"values,omitempty"`
|
||||||
ReleaseName string `json:"releaseName,omitempty" yaml:"releaseName,omitempty"`
|
ValuesLocal map[string]interface{} `json:"valuesLocal,omitempty" yaml:"valuesLocal,omitempty"`
|
||||||
ReleaseNamespace string `json:"releaseNamespace,omitempty" yaml:"releaseNamespace,omitempty"`
|
ValuesMerge string `json:"valuesMerge,omitempty" yaml:"valuesMerge,omitempty"`
|
||||||
ExtraArgs []string `json:"extraArgs,omitempty" yaml:"extraArgs,omitempty"`
|
ReleaseName string `json:"releaseName,omitempty" yaml:"releaseName,omitempty"`
|
||||||
|
ReleaseNamespace string `json:"releaseNamespace,omitempty" yaml:"releaseNamespace,omitempty"`
|
||||||
|
ExtraArgs []string `json:"extraArgs,omitempty" yaml:"extraArgs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ require (
|
|||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||||
k8s.io/apimachinery v0.18.10
|
k8s.io/apimachinery v0.18.10
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3
|
sigs.k8s.io/kustomize/kyaml v0.10.6
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -378,8 +378,6 @@ 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.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
@@ -390,8 +388,8 @@ k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUc
|
|||||||
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
||||||
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||||
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
|
k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C9bd8UpWHZ5plfAS9fzPjJuQ6JL3E=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3 h1:ARSJUMN/c3k31DYxRfZ+vp/UepUQjg9zCwny7Oj908I=
|
sigs.k8s.io/kustomize/kyaml v0.10.6 h1:xUJxc/k8JoWqHUahaB8DTqY0KwEPxTbTGStvW8TOcDc=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3/go.mod h1:RA+iCHA2wPCOfv6uG6TfXXWhYsHpgErq/AljxWKuxtg=
|
sigs.k8s.io/kustomize/kyaml v0.10.6/go.mod h1:K9yg1k/HB/6xNOf5VH3LhTo1DK9/5ykSZO5uIv+Y/1k=
|
||||||
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
||||||
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
||||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ func (e *Editor) Tidy() error {
|
|||||||
func (e *Editor) Pin(target misc.LaModule, oldV, newV semver.SemVer) error {
|
func (e *Editor) Pin(target misc.LaModule, oldV, newV semver.SemVer) error {
|
||||||
err := e.run(
|
err := e.run(
|
||||||
"edit",
|
"edit",
|
||||||
|
"-dropreplace="+target.ImportPath(),
|
||||||
"-dropreplace="+target.ImportPath()+"@"+oldV.String(),
|
"-dropreplace="+target.ImportPath()+"@"+oldV.String(),
|
||||||
"-require="+target.ImportPath()+"@"+newV.String(),
|
"-require="+target.ImportPath()+"@"+newV.String(),
|
||||||
)
|
)
|
||||||
@@ -66,8 +67,9 @@ func (e *Editor) Pin(target misc.LaModule, oldV, newV semver.SemVer) error {
|
|||||||
func (e *Editor) UnPin(target misc.LaModule, oldV semver.SemVer) error {
|
func (e *Editor) UnPin(target misc.LaModule, oldV semver.SemVer) error {
|
||||||
var r strings.Builder
|
var r strings.Builder
|
||||||
r.WriteString(target.ImportPath())
|
r.WriteString(target.ImportPath())
|
||||||
r.WriteString("@")
|
// Don't specify the old version.
|
||||||
r.WriteString(oldV.String())
|
// r.WriteString("@")
|
||||||
|
// r.WriteString(oldV.String())
|
||||||
r.WriteString("=")
|
r.WriteString("=")
|
||||||
r.WriteString(upstairs(e.module.ShortName().Depth()))
|
r.WriteString(upstairs(e.module.ShortName().Depth()))
|
||||||
r.WriteString(string(target.ShortName()))
|
r.WriteString(string(target.ShortName()))
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ require (
|
|||||||
github.com/rakyll/statik v0.1.7
|
github.com/rakyll/statik v0.1.7
|
||||||
github.com/spf13/cobra v1.0.0
|
github.com/spf13/cobra v1.0.0
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
sigs.k8s.io/kustomize/api v0.6.6
|
sigs.k8s.io/kustomize/api v0.7.1
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3
|
sigs.k8s.io/kustomize/kyaml v0.10.6
|
||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace sigs.k8s.io/kustomize/api => ../../api
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
|||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
|
||||||
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
@@ -511,8 +512,8 @@ gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 h1:Xe2gvTZUJpsvOWUnvmL/tmhVBZUmHSvLbMjRj6NUUKo=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
@@ -533,10 +534,8 @@ k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl
|
|||||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
||||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||||
sigs.k8s.io/kustomize/api v0.6.6 h1:Da5JBSFqA22R5Q1mHiVD4+vgs1j8OwTXcT+l6bbrVzk=
|
sigs.k8s.io/kustomize/kyaml v0.10.6 h1:xUJxc/k8JoWqHUahaB8DTqY0KwEPxTbTGStvW8TOcDc=
|
||||||
sigs.k8s.io/kustomize/api v0.6.6/go.mod h1:3TxKEyaxwOIfHmRbQF14hDUSRmVQI0iSn8qDA5zaO/0=
|
sigs.k8s.io/kustomize/kyaml v0.10.6/go.mod h1:K9yg1k/HB/6xNOf5VH3LhTo1DK9/5ykSZO5uIv+Y/1k=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3 h1:ARSJUMN/c3k31DYxRfZ+vp/UepUQjg9zCwny7Oj908I=
|
|
||||||
sigs.k8s.io/kustomize/kyaml v0.10.3/go.mod h1:RA+iCHA2wPCOfv6uG6TfXXWhYsHpgErq/AljxWKuxtg=
|
|
||||||
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-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
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.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
|
|
||||||
Moved to [https://kubernetes-sigs.github.io/kustomize](https://kubernetes-sigs.github.io/kustomize/guides/plugins)
|
Moved to [https://kubernetes-sigs.github.io/kustomize](https://kubectl.docs.kubernetes.io/guides/extending_kustomize/)
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
metadata:
|
||||||
|
name: arbitrary
|
||||||
|
|
||||||
# Example configuration for the webserver
|
# Example configuration for the webserver
|
||||||
# at https://github.com/monopole/hello
|
# at https://github.com/monopole/hello
|
||||||
commonLabels:
|
commonLabels:
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ resources:
|
|||||||
EOF
|
EOF
|
||||||
```
|
```
|
||||||
|
|
||||||
Make a transformer configration file.
|
Make a transformer configuration file.
|
||||||
|
|
||||||
The transformer used is called `AddValueTransformer`. It's
|
The transformer used is called `AddValueTransformer`. It's
|
||||||
intended to implement the 'add' operation of
|
intended to implement the 'add' operation of
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#
|
#
|
||||||
# Fails if the file already exists.
|
# Fails if the file already exists.
|
||||||
|
|
||||||
|
curl_timeout=600
|
||||||
release_url=https://api.github.com/repos/kubernetes-sigs/kustomize/releases
|
release_url=https://api.github.com/repos/kubernetes-sigs/kustomize/releases
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
@@ -45,11 +46,11 @@ elif [[ "$OSTYPE" == darwin* ]]; then
|
|||||||
opsys=darwin
|
opsys=darwin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
curl -s $release_url |\
|
curl -m $curl_timeout -s $release_url |\
|
||||||
grep browser_download.*${opsys}_${arch} |\
|
grep browser_download.*${opsys}_${arch} |\
|
||||||
cut -d '"' -f 4 |\
|
cut -d '"' -f 4 |\
|
||||||
sort | tail -n 1 |\
|
sort | tail -n 1 |\
|
||||||
xargs curl -sLO
|
xargs curl -m $curl_timeout -sLO
|
||||||
|
|
||||||
if [ -e ./kustomize_v*_${opsys}_amd64.tar.gz ]; then
|
if [ -e ./kustomize_v*_${opsys}_amd64.tar.gz ]; then
|
||||||
tar xzf ./kustomize_v*_${opsys}_amd64.tar.gz
|
tar xzf ./kustomize_v*_${opsys}_amd64.tar.gz
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user