mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 09:51:23 +00:00
Compare commits
21 Commits
no-partial
...
api/v0.13.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f851cc7181 | ||
|
|
7e3ad53890 | ||
|
|
5cdc080406 | ||
|
|
10fb04cdf2 | ||
|
|
ea8fc77f2f | ||
|
|
e9507c940d | ||
|
|
bea105d793 | ||
|
|
e4d7eaa479 | ||
|
|
85949329b8 | ||
|
|
0c34cf4192 | ||
|
|
95edcc0681 | ||
|
|
9d8ed39d3d | ||
|
|
1957d5c746 | ||
|
|
236166097e | ||
|
|
3370177b9d | ||
|
|
c8b112c79f | ||
|
|
d91e31cf18 | ||
|
|
00b0bd8473 | ||
|
|
e2aff13587 | ||
|
|
361154dabc | ||
|
|
7db330d2cc |
@@ -110,6 +110,7 @@ linters-settings:
|
|||||||
gomnd:
|
gomnd:
|
||||||
ignored-functions:
|
ignored-functions:
|
||||||
- os.WriteFile
|
- os.WriteFile
|
||||||
|
- make
|
||||||
gomoddirectives:
|
gomoddirectives:
|
||||||
replace-local: true
|
replace-local: true
|
||||||
gosec:
|
gosec:
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -75,7 +75,8 @@ $(MYGOBIN)/pluginator:
|
|||||||
# Build from local source.
|
# Build from local source.
|
||||||
$(MYGOBIN)/kustomize: build-kustomize-api
|
$(MYGOBIN)/kustomize: build-kustomize-api
|
||||||
cd kustomize; \
|
cd kustomize; \
|
||||||
go install .
|
go install -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
|
||||||
|
.
|
||||||
|
|
||||||
kustomize: $(MYGOBIN)/kustomize
|
kustomize: $(MYGOBIN)/kustomize
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ functions-examples-all:
|
|||||||
done
|
done
|
||||||
|
|
||||||
test-go-mod:
|
test-go-mod:
|
||||||
./hack/for-each-module.sh "go list -m -json all > /dev/null && go mod tidy -v"
|
./hack/for-each-module.sh "\$$KUSTOMIZE_ROOT/hack/with-unpinned-kust-dev.sh 'go mod tidy -v'"
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
|
verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
include ../Makefile-modules.mk
|
include ../Makefile-modules.mk
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v -timeout 45m -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
|
go test -v -timeout 45m -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-01-31T23:38:41Z -X sigs.k8s.io/kustomize/api/provenance.version=(test)"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222" ./...
|
go build -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")" ./...
|
||||||
|
|
||||||
generate: $(MYGOBIN)/k8scopy $(MYGOBIN)/stringer
|
generate: $(MYGOBIN)/k8scopy $(MYGOBIN)/stringer
|
||||||
go generate ./...
|
go generate ./...
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.1
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,6 +28,7 @@ require (
|
|||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/sergi/go-diff v1.1.0 // indirect
|
||||||
github.com/xlab/treeprint v1.1.0 // indirect
|
github.com/xlab/treeprint v1.1.0 // indirect
|
||||||
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
|
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
|
||||||
golang.org/x/sys v0.3.0 // indirect
|
golang.org/x/sys v0.3.0 // indirect
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
|
|||||||
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
@@ -68,11 +69,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||||
|
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||||
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
@@ -135,6 +138,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
|
|||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
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=
|
||||||
@@ -145,7 +149,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
|
|||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
|
sigs.k8s.io/kustomize/kyaml v0.14.0 h1:uzH0MzMtYypHW09LbMDk8k/lT/LSsUuCoZIuEGhIBNE=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
|
sigs.k8s.io/kustomize/kyaml v0.14.0/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
|
||||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"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/errors"
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -86,12 +87,20 @@ func (p *HelmChartInflationGeneratorPlugin) validateArgs() (err error) {
|
|||||||
p.ChartHome = types.HelmDefaultHome
|
p.ChartHome = types.HelmDefaultHome
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ValuesFile may be consulted by the plugin, so it must
|
// The ValuesFile(s) may be consulted by the plugin, so it must
|
||||||
// be under the loader root (unless root restrictions are
|
// be under the loader root (unless root restrictions are
|
||||||
// disabled).
|
// disabled).
|
||||||
if p.ValuesFile == "" {
|
if p.ValuesFile == "" {
|
||||||
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
|
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
|
||||||
}
|
}
|
||||||
|
for i, file := range p.AdditionalValuesFiles {
|
||||||
|
// use Load() to enforce root restrictions
|
||||||
|
if _, err := p.h.Loader().Load(file); err != nil {
|
||||||
|
return errors.WrapPrefixf(err, "could not load additionalValuesFile")
|
||||||
|
}
|
||||||
|
// the additional values filepaths must be relative to the kust root
|
||||||
|
p.AdditionalValuesFiles[i] = filepath.Join(p.h.Loader().Root(), file)
|
||||||
|
}
|
||||||
|
|
||||||
if err = p.errIfIllegalValuesMerge(); err != nil {
|
if err = p.errIfIllegalValuesMerge(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -240,49 +249,28 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var stdout []byte
|
var stdout []byte
|
||||||
stdout, err = p.runHelmCommand(p.templateCommand())
|
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rm, err = p.h.ResmapFactory().NewResMapFromBytes(stdout)
|
rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout)
|
||||||
if err == nil {
|
if resMapErr == nil {
|
||||||
return rm, nil
|
return rm, nil
|
||||||
}
|
}
|
||||||
// try to remove the contents before first "---" because
|
// try to remove the contents before first "---" because
|
||||||
// helm may produce messages to stdout before it
|
// helm may produce messages to stdout before it
|
||||||
stdoutStr := string(stdout)
|
r := &kio.ByteReader{Reader: bytes.NewBufferString(string(stdout)), OmitReaderAnnotations: true}
|
||||||
if idx := strings.Index(stdoutStr, "\n---\n"); idx != -1 {
|
nodes, err := r.Read()
|
||||||
return p.h.ResmapFactory().NewResMapFromBytes([]byte(stdoutStr[idx:]))
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
|
if len(nodes) != 0 {
|
||||||
args := []string{"template"}
|
rm, err = p.h.ResmapFactory().NewResMapFromRNodeSlice(nodes)
|
||||||
if p.ReleaseName != "" {
|
if err != nil {
|
||||||
args = append(args, p.ReleaseName)
|
return nil, fmt.Errorf("could not parse rnode slice into resource map: %w\n", err)
|
||||||
|
}
|
||||||
|
return rm, nil
|
||||||
}
|
}
|
||||||
if p.Namespace != "" {
|
return nil, fmt.Errorf("could not parse bytes into resource map: %w\n", resMapErr)
|
||||||
args = append(args, "--namespace", p.Namespace)
|
|
||||||
}
|
|
||||||
args = append(args, filepath.Join(p.absChartHome(), p.Name))
|
|
||||||
if p.ValuesFile != "" {
|
|
||||||
args = append(args, "--values", p.ValuesFile)
|
|
||||||
}
|
|
||||||
if p.ReleaseName == "" {
|
|
||||||
// AFAICT, this doesn't work as intended due to a bug in helm.
|
|
||||||
// See https://github.com/helm/helm/issues/6019
|
|
||||||
// I've tried placing the flag before and after the name argument.
|
|
||||||
args = append(args, "--generate-name")
|
|
||||||
}
|
|
||||||
if p.IncludeCRDs {
|
|
||||||
args = append(args, "--include-crds")
|
|
||||||
}
|
|
||||||
if p.SkipHooks {
|
|
||||||
args = append(args, "--no-hooks")
|
|
||||||
}
|
|
||||||
return args
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {
|
func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ func (lbp *localizeBuiltinPlugins) Filter(plugins []*yaml.RNode) ([]*yaml.RNode,
|
|||||||
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.SecretGenerator.String()},
|
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.SecretGenerator.String()},
|
||||||
Path: "envs",
|
Path: "envs",
|
||||||
},
|
},
|
||||||
|
types.FieldSpec{
|
||||||
|
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.HelmChartInflationGenerator.String()},
|
||||||
|
Path: "valuesFile",
|
||||||
|
},
|
||||||
|
types.FieldSpec{
|
||||||
|
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.HelmChartInflationGenerator.String()},
|
||||||
|
Path: "additionalValuesFiles",
|
||||||
|
},
|
||||||
types.FieldSpec{
|
types.FieldSpec{
|
||||||
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.PatchTransformer.String()},
|
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.PatchTransformer.String()},
|
||||||
Path: "path",
|
Path: "path",
|
||||||
@@ -82,6 +90,24 @@ func (lbp *localizeBuiltinPlugins) Filter(plugins []*yaml.RNode) ([]*yaml.RNode,
|
|||||||
return lbp.localizeAll(node)
|
return lbp.localizeAll(node)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
yaml.FilterFunc(func(node *yaml.RNode) (*yaml.RNode, error) {
|
||||||
|
isHelm := node.GetApiVersion() == konfig.BuiltinPluginApiVersion &&
|
||||||
|
node.GetKind() == builtinhelpers.HelmChartInflationGenerator.String()
|
||||||
|
if !isHelm {
|
||||||
|
return node, nil
|
||||||
|
}
|
||||||
|
home, err := node.Pipe(yaml.Lookup("chartHome"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err)
|
||||||
|
}
|
||||||
|
if home == nil {
|
||||||
|
_, err = lbp.lc.copyChartHomeEntry("")
|
||||||
|
} else {
|
||||||
|
lbp.locPathFn = lbp.lc.copyChartHomeEntry
|
||||||
|
err = lbp.localizeScalar(home)
|
||||||
|
}
|
||||||
|
return node, errors.WrapPrefixf(err, "plugin %s", resid.FromRNode(node))
|
||||||
|
}),
|
||||||
fieldspec.Filter{
|
fieldspec.Filter{
|
||||||
FieldSpec: types.FieldSpec{
|
FieldSpec: types.FieldSpec{
|
||||||
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.PatchStrategicMergeTransformer.String()},
|
Gvk: resid.Gvk{Version: konfig.BuiltinPluginApiVersion, Kind: builtinhelpers.PatchStrategicMergeTransformer.String()},
|
||||||
@@ -92,7 +118,6 @@ func (lbp *localizeBuiltinPlugins) Filter(plugins []*yaml.RNode) ([]*yaml.RNode,
|
|||||||
return lbp.localizeAll(node)
|
return lbp.localizeAll(node)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
// TODO(annasong): localize HelmChartInflationGenerator
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err)
|
return nil, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ type localizer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run attempts to localize the kustomization root at target with the given localize arguments
|
// Run attempts to localize the kustomization root at target with the given localize arguments
|
||||||
func Run(target string, scope string, newDir string, fSys filesys.FileSystem) error {
|
// and returns the path to the created newDir.
|
||||||
|
func Run(target, scope, newDir string, fSys filesys.FileSystem) (string, error) {
|
||||||
ldr, args, err := NewLoader(target, scope, newDir, fSys)
|
ldr, args, err := NewLoader(target, scope, newDir, fSys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err)
|
return "", errors.Wrap(err)
|
||||||
}
|
}
|
||||||
defer func() { _ = ldr.Cleanup() }()
|
defer func() { _ = ldr.Cleanup() }()
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ func Run(target string, scope string, newDir string, fSys filesys.FileSystem) er
|
|||||||
}
|
}
|
||||||
dst := args.NewDir.Join(toDst)
|
dst := args.NewDir.Join(toDst)
|
||||||
if err = fSys.MkdirAll(dst); err != nil {
|
if err = fSys.MkdirAll(dst); err != nil {
|
||||||
return errors.WrapPrefixf(err, "unable to create directory in localize destination")
|
return "", errors.WrapPrefixf(err, "unable to create directory in localize destination")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = (&localizer{
|
err = (&localizer{
|
||||||
@@ -66,9 +67,9 @@ func Run(target string, scope string, newDir string, fSys filesys.FileSystem) er
|
|||||||
if errCleanup != nil {
|
if errCleanup != nil {
|
||||||
log.Printf("unable to clean localize destination: %s", errCleanup)
|
log.Printf("unable to clean localize destination: %s", errCleanup)
|
||||||
}
|
}
|
||||||
return errors.WrapPrefixf(err, "unable to localize target %q", target)
|
return "", errors.WrapPrefixf(err, "unable to localize target %q", target)
|
||||||
}
|
}
|
||||||
return nil
|
return args.NewDir.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// localize localizes the root that lc is at
|
// localize localizes the root that lc is at
|
||||||
@@ -279,6 +280,14 @@ func (lc *localizer) localizeHelmCharts(kust *types.Kustomization) error {
|
|||||||
return errors.WrapPrefixf(err, "unable to localize helmCharts entry %d valuesFile", i)
|
return errors.WrapPrefixf(err, "unable to localize helmCharts entry %d valuesFile", i)
|
||||||
}
|
}
|
||||||
kust.HelmCharts[i].ValuesFile = locFile
|
kust.HelmCharts[i].ValuesFile = locFile
|
||||||
|
|
||||||
|
for j, valuesFile := range chart.AdditionalValuesFiles {
|
||||||
|
locFile, err = lc.localizeFile(valuesFile)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WrapPrefixf(err, "unable to localize helmCharts entry %d additionalValuesFiles", i)
|
||||||
|
}
|
||||||
|
kust.HelmCharts[i].AdditionalValuesFiles[j] = locFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if kust.HelmGlobals != nil {
|
if kust.HelmGlobals != nil {
|
||||||
locDir, err := lc.copyChartHomeEntry(kust.HelmGlobals.ChartHome)
|
locDir, err := lc.copyChartHomeEntry(kust.HelmGlobals.ChartHome)
|
||||||
|
|||||||
@@ -102,6 +102,14 @@ func addFiles(t *testing.T, fSys filesys.FileSystem, parentDir string, files map
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkRun(t *testing.T, fSys filesys.FileSystem, target, scope, dst string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
actualDst, err := Run(target, scope, dst, fSys)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, dst, actualDst)
|
||||||
|
}
|
||||||
|
|
||||||
func makeFileSystems(t *testing.T, target string, files map[string]string) (expected filesys.FileSystem, actual filesys.FileSystem) {
|
func makeFileSystems(t *testing.T, target string, files map[string]string) (expected filesys.FileSystem, actual filesys.FileSystem) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -161,9 +169,7 @@ func checkLocalizeInTargetSuccess(t *testing.T, files map[string]string) {
|
|||||||
fSys := makeMemoryFs(t)
|
fSys := makeMemoryFs(t)
|
||||||
addFiles(t, fSys, "/a", files)
|
addFiles(t, fSys, "/a", files)
|
||||||
|
|
||||||
err := Run("/a", "/", "dst", fSys)
|
checkRun(t, fSys, "/a", "/", "/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
fSysExpected := makeMemoryFs(t)
|
fSysExpected := makeMemoryFs(t)
|
||||||
addFiles(t, fSysExpected, "/a", files)
|
addFiles(t, fSysExpected, "/a", files)
|
||||||
addFiles(t, fSysExpected, "/dst/a", files)
|
addFiles(t, fSysExpected, "/dst/a", files)
|
||||||
@@ -179,9 +185,7 @@ namePrefix: my-
|
|||||||
}
|
}
|
||||||
fSysExpected, fSysActual := makeFileSystems(t, "/a", kustomization)
|
fSysExpected, fSysActual := makeFileSystems(t, "/a", kustomization)
|
||||||
|
|
||||||
err := Run("/a", "", "/a/b/dst", fSysActual)
|
checkRun(t, fSysActual, "/a", "/a", "/a/b/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, fSysExpected, "/a/b/dst", kustomization)
|
addFiles(t, fSysExpected, "/a/b/dst", kustomization)
|
||||||
checkFSys(t, fSysExpected, fSysActual)
|
checkFSys(t, fSysExpected, fSysActual)
|
||||||
}
|
}
|
||||||
@@ -202,9 +206,7 @@ patches:
|
|||||||
}
|
}
|
||||||
fSysExpected, fSysActual := makeFileSystems(t, "/a/b", kustomization)
|
fSysExpected, fSysActual := makeFileSystems(t, "/a/b", kustomization)
|
||||||
|
|
||||||
err := Run("/a/b", "/", "/a/b/dst", fSysActual)
|
checkRun(t, fSysActual, "/a/b", "/", "/a/b/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, fSysExpected, "/a/b/dst/a/b", kustomization)
|
addFiles(t, fSysExpected, "/a/b/dst/a/b", kustomization)
|
||||||
checkFSys(t, fSysExpected, fSysActual)
|
checkFSys(t, fSysExpected, fSysActual)
|
||||||
}
|
}
|
||||||
@@ -259,7 +261,7 @@ func TestLoadUnknownKustFields(t *testing.T) {
|
|||||||
suffix: invalid`,
|
suffix: invalid`,
|
||||||
})
|
})
|
||||||
|
|
||||||
err := Run("/a", "", "", fSysTest)
|
_, err := Run("/a", "", "", fSysTest)
|
||||||
require.EqualError(t, err,
|
require.EqualError(t, err,
|
||||||
`unable to localize target "/a": invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)
|
`unable to localize target "/a": invalid Kustomization: error unmarshaling JSON: while decoding JSON: json: unknown field "suffix"`)
|
||||||
|
|
||||||
@@ -299,9 +301,7 @@ patches:
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/alpha/beta/gamma", kustAndPatch)
|
expected, actual := makeFileSystems(t, "/alpha/beta/gamma", kustAndPatch)
|
||||||
|
|
||||||
err := Run("/alpha/beta/gamma", "/", "", actual)
|
checkRun(t, actual, "/alpha/beta/gamma", "/", "/localized-gamma")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/localized-gamma/alpha/beta/gamma", map[string]string{
|
addFiles(t, expected, "/localized-gamma/alpha/beta/gamma", map[string]string{
|
||||||
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
|
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
@@ -328,9 +328,7 @@ kind: Kustomization
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/alpha/beta", targetAndUnreferenced)
|
expected, actual := makeFileSystems(t, "/alpha/beta", targetAndUnreferenced)
|
||||||
|
|
||||||
err := Run("/alpha/beta", "/alpha", "/beta", actual)
|
checkRun(t, actual, "/alpha/beta", "/alpha", "/beta")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/beta/beta", map[string]string{
|
addFiles(t, expected, "/beta/beta", map[string]string{
|
||||||
"kustomization.yaml": targetAndUnreferenced["kustomization.yaml"],
|
"kustomization.yaml": targetAndUnreferenced["kustomization.yaml"],
|
||||||
"env": targetAndUnreferenced["env"],
|
"env": targetAndUnreferenced["env"],
|
||||||
@@ -586,15 +584,43 @@ patches:
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/a/b", kustAndPatch)
|
expected, actual := makeFileSystems(t, "/a/b", kustAndPatch)
|
||||||
|
|
||||||
err := Run("/a/b", "", "/dst", actual)
|
_, err := Run("/a/b", "", "/dst", actual)
|
||||||
require.EqualError(t, err, `unable to localize target "/a/b": unable to localize patches: invalid file reference: '/a/b/name-DNE.yaml' doesn't exist`)
|
require.EqualError(t, err, `unable to localize target "/a/b": unable to localize patches: invalid file reference: '/a/b/name-DNE.yaml' doesn't exist`)
|
||||||
|
|
||||||
checkFSys(t, expected, actual)
|
checkFSys(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalizePluginsInlineAndFile(t *testing.T) {
|
func TestLocalizePluginsInlineAndFile(t *testing.T) {
|
||||||
kustAndPlugins := map[string]string{
|
for _, test := range []struct {
|
||||||
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
|
name string
|
||||||
|
files map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "generators",
|
||||||
|
files: map[string]string{
|
||||||
|
"kustomization.yaml": `generators:
|
||||||
|
- generator.yaml
|
||||||
|
- |
|
||||||
|
apiVersion: builtin
|
||||||
|
env: second.properties
|
||||||
|
kind: ConfigMapGenerator
|
||||||
|
metadata:
|
||||||
|
name: inline
|
||||||
|
`,
|
||||||
|
"generator.yaml": `apiVersion: builtin
|
||||||
|
env: first.properties
|
||||||
|
kind: ConfigMapGenerator
|
||||||
|
metadata:
|
||||||
|
name: file
|
||||||
|
`,
|
||||||
|
"first.properties": "APPLE=orange",
|
||||||
|
"second.properties": "BANANA=pear",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "transformers",
|
||||||
|
files: map[string]string{
|
||||||
|
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
transformers:
|
transformers:
|
||||||
- |
|
- |
|
||||||
@@ -605,16 +631,39 @@ transformers:
|
|||||||
path: patchSM-one.yaml
|
path: patchSM-one.yaml
|
||||||
- patch.yaml
|
- patch.yaml
|
||||||
`,
|
`,
|
||||||
"patch.yaml": `apiVersion: builtin
|
"patch.yaml": `apiVersion: builtin
|
||||||
kind: PatchTransformer
|
kind: PatchTransformer
|
||||||
metadata:
|
metadata:
|
||||||
name: file
|
name: file
|
||||||
path: patchSM-two.yaml
|
path: patchSM-two.yaml
|
||||||
`,
|
`,
|
||||||
"patchSM-one.yaml": podConfiguration,
|
"patchSM-one.yaml": podConfiguration,
|
||||||
"patchSM-two.yaml": podConfiguration,
|
"patchSM-two.yaml": podConfiguration,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "validators",
|
||||||
|
files: map[string]string{
|
||||||
|
"kustomization.yaml": `validators:
|
||||||
|
- |
|
||||||
|
apiVersion: builtin
|
||||||
|
kind: ReplacementTransformer
|
||||||
|
metadata:
|
||||||
|
name: inline
|
||||||
|
replacements:
|
||||||
|
- path: first.yaml
|
||||||
|
- second.yaml
|
||||||
|
`,
|
||||||
|
"first.yaml": replacementTransformerWithPath,
|
||||||
|
"second.yaml": replacementTransformerWithPath,
|
||||||
|
"replacement.yaml": replacements,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
checkLocalizeInTargetSuccess(t, test.files)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
checkLocalizeInTargetSuccess(t, kustAndPlugins)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalizeMultiplePluginsInEntry(t *testing.T) {
|
func TestLocalizeMultiplePluginsInEntry(t *testing.T) {
|
||||||
@@ -659,9 +708,7 @@ transformers:
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/a", kustAndPlugins)
|
expected, actual := makeFileSystems(t, "/a", kustAndPlugins)
|
||||||
|
|
||||||
err := Run("/a", "", "/dst", actual)
|
checkRun(t, actual, "/a", "/a", "/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/dst", map[string]string{
|
addFiles(t, expected, "/dst", map[string]string{
|
||||||
"kustomization.yaml": kustAndPlugins["kustomization.yaml"],
|
"kustomization.yaml": kustAndPlugins["kustomization.yaml"],
|
||||||
"patch.yaml": fmt.Sprintf(patchf, "patchSM.yaml"),
|
"patch.yaml": fmt.Sprintf(patchf, "patchSM.yaml"),
|
||||||
@@ -920,7 +967,7 @@ metadata:
|
|||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
expected, actual := makeFileSystems(t, "/", test.files)
|
expected, actual := makeFileSystems(t, "/", test.files)
|
||||||
|
|
||||||
err := Run("/", "", "/dst", actual)
|
_, err := Run("/", "", "/dst", actual)
|
||||||
|
|
||||||
var actualErr ResourceLoadError
|
var actualErr ResourceLoadError
|
||||||
require.ErrorAs(t, err, &actualErr)
|
require.ErrorAs(t, err, &actualErr)
|
||||||
@@ -974,7 +1021,7 @@ func TestLocalizeBuiltinPlugins_Errors(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
expected, actual := makeFileSystems(t, "/a", test.files)
|
expected, actual := makeFileSystems(t, "/a", test.files)
|
||||||
err := Run("/a", "", "/dst", actual)
|
_, err := Run("/a", "", "/dst", actual)
|
||||||
const errPrefix = `unable to localize target "/a"`
|
const errPrefix = `unable to localize target "/a"`
|
||||||
require.EqualError(t, err, fmt.Sprintf(
|
require.EqualError(t, err, fmt.Sprintf(
|
||||||
"%s: %s: %s", errPrefix, test.fieldSpecErr, test.locErr))
|
"%s: %s: %s", errPrefix, test.fieldSpecErr, test.locErr))
|
||||||
@@ -1094,9 +1141,7 @@ namespace: kustomize-namespace
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/alpha", kustAndComponents)
|
expected, actual := makeFileSystems(t, "/alpha", kustAndComponents)
|
||||||
|
|
||||||
err := Run("/alpha/beta/gamma", "/alpha", "/alpha/beta/dst", actual)
|
checkRun(t, actual, "/alpha/beta/gamma", "/alpha", "/alpha/beta/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
cleanedFiles := map[string]string{
|
cleanedFiles := map[string]string{
|
||||||
"beta/gamma/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
|
"beta/gamma/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
components:
|
components:
|
||||||
@@ -1159,9 +1204,7 @@ namePrefix: my-
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/a/b", kustAndResources)
|
expected, actual := makeFileSystems(t, "/a/b", kustAndResources)
|
||||||
|
|
||||||
err := Run("/a/b", "/", "", actual)
|
checkRun(t, actual, "/a/b", "/", "/localized-b")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/localized-b/a/b", kustAndResources)
|
addFiles(t, expected, "/localized-b/a/b", kustAndResources)
|
||||||
checkFSys(t, expected, actual)
|
checkFSys(t, expected, actual)
|
||||||
}
|
}
|
||||||
@@ -1176,7 +1219,7 @@ resources:
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/a", kustAndResources)
|
expected, actual := makeFileSystems(t, "/a", kustAndResources)
|
||||||
|
|
||||||
err := Run("/a", "/", "", actual)
|
_, err := Run("/a", "/", "", actual)
|
||||||
|
|
||||||
const expectedFileErr = `invalid file reference: '/a/b' must resolve to a file`
|
const expectedFileErr = `invalid file reference: '/a/b' must resolve to a file`
|
||||||
const expectedRootErr = `unable to localize root "b": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory '/a/b'`
|
const expectedRootErr = `unable to localize root "b": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory '/a/b'`
|
||||||
@@ -1230,8 +1273,13 @@ func TestLocalizeHelmCharts(t *testing.T) {
|
|||||||
- includeCRDs: true
|
- includeCRDs: true
|
||||||
name: localize-valuesFile
|
name: localize-valuesFile
|
||||||
valuesFile: file
|
valuesFile: file
|
||||||
|
- additionalValuesFiles:
|
||||||
|
- another
|
||||||
|
- third
|
||||||
`,
|
`,
|
||||||
"file": valuesFile,
|
"file": valuesFile,
|
||||||
|
"another": valuesFile,
|
||||||
|
"third": valuesFile,
|
||||||
"charts/nothing-to-localize/values.yaml": valuesFile,
|
"charts/nothing-to-localize/values.yaml": valuesFile,
|
||||||
"charts/localize-valuesFile/values.yaml": valuesFile,
|
"charts/localize-valuesFile/values.yaml": valuesFile,
|
||||||
},
|
},
|
||||||
@@ -1273,9 +1321,7 @@ func TestLocalizeHelmChartsNoDefault(t *testing.T) {
|
|||||||
}
|
}
|
||||||
expected, actual := makeFileSystems(t, "/a", files)
|
expected, actual := makeFileSystems(t, "/a", files)
|
||||||
|
|
||||||
err := Run("/a", "", "/dst", actual)
|
checkRun(t, actual, "/a", "/a", "/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/dst", map[string]string{
|
addFiles(t, expected, "/dst", map[string]string{
|
||||||
"kustomization.yaml": files["kustomization.yaml"],
|
"kustomization.yaml": files["kustomization.yaml"],
|
||||||
"home/name/values.yaml": valuesFile,
|
"home/name/values.yaml": valuesFile,
|
||||||
@@ -1389,9 +1435,7 @@ helmGlobals:
|
|||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
expected, actual := makeFileSystems(t, "/a/b", test.files)
|
expected, actual := makeFileSystems(t, "/a/b", test.files)
|
||||||
|
|
||||||
err := Run("/a/b", "/a/b", "/dst", actual)
|
checkRun(t, actual, "/a/b", "/a/b", "/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/dst", test.copiedFiles)
|
addFiles(t, expected, "/dst", test.copiedFiles)
|
||||||
checkFSys(t, expected, actual)
|
checkFSys(t, expected, actual)
|
||||||
})
|
})
|
||||||
@@ -1408,9 +1452,7 @@ func TestCopyChartHomeEmpty(t *testing.T) {
|
|||||||
require.NoError(t, actual.Mkdir("/a/home"))
|
require.NoError(t, actual.Mkdir("/a/home"))
|
||||||
require.NoError(t, expected.Mkdir("/a/home"))
|
require.NoError(t, expected.Mkdir("/a/home"))
|
||||||
|
|
||||||
err := Run("/a", "", "/dst", actual)
|
checkRun(t, actual, "/a", "/a", "/dst")
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
addFiles(t, expected, "/dst", kustomization)
|
addFiles(t, expected, "/dst", kustomization)
|
||||||
require.NoError(t, expected.Mkdir("/dst/home"))
|
require.NoError(t, expected.Mkdir("/dst/home"))
|
||||||
checkFSys(t, expected, actual)
|
checkFSys(t, expected, actual)
|
||||||
@@ -1452,7 +1494,7 @@ func TestCopyChartHomeError(t *testing.T) {
|
|||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
expected, actual := makeFileSystems(t, "/", test.files)
|
expected, actual := makeFileSystems(t, "/", test.files)
|
||||||
|
|
||||||
err := Run("/a/b", "/a", "/dst", actual)
|
_, err := Run("/a/b", "/a", "/dst", actual)
|
||||||
const prefix = `unable to localize target "/a/b"`
|
const prefix = `unable to localize target "/a/b"`
|
||||||
require.EqualError(t, err, fmt.Sprintf("%s: %s", prefix, test.err))
|
require.EqualError(t, err, fmt.Sprintf("%s: %s", prefix, test.err))
|
||||||
|
|
||||||
@@ -1461,6 +1503,67 @@ func TestCopyChartHomeError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLocalizeGeneratorsHelm(t *testing.T) {
|
||||||
|
files := map[string]string{
|
||||||
|
"kustomization.yaml": `generators:
|
||||||
|
- default.yaml
|
||||||
|
- explicit.yaml
|
||||||
|
`,
|
||||||
|
"default.yaml": `apiVersion: builtin
|
||||||
|
kind: HelmChartInflationGenerator
|
||||||
|
metadata:
|
||||||
|
name: no-explicit-references
|
||||||
|
name: minecraft
|
||||||
|
releaseName: moria
|
||||||
|
repo: https://itzg.github.io/minecraft-server-charts
|
||||||
|
version: 3.1.3
|
||||||
|
`,
|
||||||
|
"explicit.yaml": `additionalValuesFiles:
|
||||||
|
- time.yaml
|
||||||
|
- life.yaml
|
||||||
|
- light.yaml
|
||||||
|
apiVersion: builtin
|
||||||
|
chartHome: home
|
||||||
|
kind: HelmChartInflationGenerator
|
||||||
|
metadata:
|
||||||
|
name: explicit-references
|
||||||
|
name: mapleStory
|
||||||
|
valuesFile: mapleValues.yaml
|
||||||
|
`,
|
||||||
|
"time.yaml": valuesFile,
|
||||||
|
"life.yaml": valuesFile,
|
||||||
|
"light.yaml": valuesFile,
|
||||||
|
"mapleValues.yaml": valuesFile,
|
||||||
|
"home/mapleStory/values.yaml": valuesFile,
|
||||||
|
"charts/minecraft/values.yaml": valuesFile,
|
||||||
|
}
|
||||||
|
checkLocalizeInTargetSuccess(t, files)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocalizeGeneratorsNoHelm(t *testing.T) {
|
||||||
|
files := map[string]string{
|
||||||
|
"kustomization.yaml": `generators:
|
||||||
|
- configMap.yaml
|
||||||
|
`,
|
||||||
|
"configMap.yaml": `apiVersion: builtin
|
||||||
|
kind: ConfigMapGenerator
|
||||||
|
literals:
|
||||||
|
- APPLE=orange
|
||||||
|
metadata:
|
||||||
|
name: not-helm-shouldn't-copy-default-helm-chart-home
|
||||||
|
`,
|
||||||
|
"charts/minecraft/values.yaml": valuesFile,
|
||||||
|
}
|
||||||
|
expected, actual := makeFileSystems(t, "/a", files)
|
||||||
|
|
||||||
|
checkRun(t, actual, "/a", "/a", "/dst")
|
||||||
|
addFiles(t, expected, "/dst", map[string]string{
|
||||||
|
"kustomization.yaml": files["kustomization.yaml"],
|
||||||
|
"configMap.yaml": files["configMap.yaml"],
|
||||||
|
})
|
||||||
|
checkFSys(t, expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
func TestLocalizeEmpty(t *testing.T) {
|
func TestLocalizeEmpty(t *testing.T) {
|
||||||
for name, kustomization := range map[string]string{
|
for name, kustomization := range map[string]string{
|
||||||
"file": `configurations:
|
"file": `configurations:
|
||||||
|
|||||||
@@ -4,9 +4,12 @@
|
|||||||
package krusty_test
|
package krusty_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const expectedHelm = `
|
const expectedHelm = `
|
||||||
@@ -233,3 +236,193 @@ spec:
|
|||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHelmChartInflationGeneratorMultipleValuesFiles(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
|
||||||
|
defer th.Reset()
|
||||||
|
if err := th.ErrIfNoHelm(); err != nil {
|
||||||
|
t.Skip("skipping: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
copyValuesFilesTestChartsIntoHarness(t, th)
|
||||||
|
|
||||||
|
th.WriteK(th.GetRoot(), `
|
||||||
|
helmCharts:
|
||||||
|
- name: test-chart
|
||||||
|
releaseName: test-chart
|
||||||
|
additionalValuesFiles:
|
||||||
|
- charts/valuesFiles/file1.yaml
|
||||||
|
- charts/valuesFiles/file2.yaml
|
||||||
|
`)
|
||||||
|
|
||||||
|
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
|
||||||
|
asYaml, err := m.AsYaml()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, string(asYaml), `apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
chart: test-1.0.0
|
||||||
|
name: my-deploy
|
||||||
|
namespace: file-2
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: test
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: test-image-file1:file1
|
||||||
|
imagePullPolicy: Never
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
helm.sh/hook: test
|
||||||
|
name: test-chart
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelmChartInflationGeneratorApiVersions(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
|
||||||
|
defer th.Reset()
|
||||||
|
if err := th.ErrIfNoHelm(); err != nil {
|
||||||
|
t.Skip("skipping: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
copyValuesFilesTestChartsIntoHarness(t, th)
|
||||||
|
|
||||||
|
th.WriteK(th.GetRoot(), `
|
||||||
|
helmCharts:
|
||||||
|
- name: test-chart
|
||||||
|
releaseName: test-chart
|
||||||
|
apiVersions:
|
||||||
|
- foo/v1
|
||||||
|
`)
|
||||||
|
|
||||||
|
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
|
||||||
|
asYaml, err := m.AsYaml()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, string(asYaml), `apiVersion: foo/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
chart: test-1.0.0
|
||||||
|
name: my-deploy
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: test
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: test-image:v1.0.0
|
||||||
|
imagePullPolicy: Always
|
||||||
|
---
|
||||||
|
apiVersion: foo/v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
helm.sh/hook: test
|
||||||
|
name: test-chart
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelmChartInflationGeneratorSkipTests(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
|
||||||
|
defer th.Reset()
|
||||||
|
if err := th.ErrIfNoHelm(); err != nil {
|
||||||
|
t.Skip("skipping: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
copyValuesFilesTestChartsIntoHarness(t, th)
|
||||||
|
|
||||||
|
th.WriteK(th.GetRoot(), `
|
||||||
|
helmCharts:
|
||||||
|
- name: test-chart
|
||||||
|
releaseName: test-chart
|
||||||
|
skipTests: true
|
||||||
|
`)
|
||||||
|
|
||||||
|
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
|
||||||
|
asYaml, err := m.AsYaml()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, string(asYaml), `apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
chart: test-1.0.0
|
||||||
|
name: my-deploy
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: test
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: test-image:v1.0.0
|
||||||
|
imagePullPolicy: Always
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelmChartInflationGeneratorNameTemplate(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
|
||||||
|
defer th.Reset()
|
||||||
|
if err := th.ErrIfNoHelm(); err != nil {
|
||||||
|
t.Skip("skipping: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
copyValuesFilesTestChartsIntoHarness(t, th)
|
||||||
|
|
||||||
|
th.WriteK(th.GetRoot(), `
|
||||||
|
helmCharts:
|
||||||
|
- name: test-chart
|
||||||
|
nameTemplate: name-template
|
||||||
|
`)
|
||||||
|
|
||||||
|
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
|
||||||
|
asYaml, err := m.AsYaml()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, string(asYaml), `apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
chart: test-1.0.0
|
||||||
|
name: my-deploy
|
||||||
|
namespace: default
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: test
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: test-image:v1.0.0
|
||||||
|
imagePullPolicy: Always
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
helm.sh/hook: test
|
||||||
|
name: name-template
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyValuesFilesTestChartsIntoHarness(t *testing.T, th *kusttest_test.HarnessEnhanced) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
thDir := filepath.Join(th.GetRoot(), "charts")
|
||||||
|
chartDir := "testdata/helmcharts"
|
||||||
|
|
||||||
|
fs := th.GetFSys()
|
||||||
|
require.NoError(t, fs.MkdirAll(filepath.Join(thDir, "templates")))
|
||||||
|
require.NoError(t, copyutil.CopyDir(th.GetFSys(), chartDir, thDir))
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run `kustomize localize`s files referenced by kustomization target in scope to destination newDir on fSys.
|
// Run executes `kustomize localize` on fSys given the `localize` arguments and
|
||||||
func Run(fSys filesys.FileSystem, target, scope, newDir string) error {
|
// returns the path to the created newDir.
|
||||||
return errors.Wrap(localizer.Run(target, scope, newDir, fSys))
|
func Run(fSys filesys.FileSystem, target, scope, newDir string) (string, error) {
|
||||||
|
dst, err := localizer.Run(target, scope, newDir, fSys)
|
||||||
|
return dst, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,10 +264,11 @@ func TestWorkingDir(t *testing.T) {
|
|||||||
fsExpected, fsActual, wd := PrepareFs(t, []string{"target", "base"}, files)
|
fsExpected, fsActual, wd := PrepareFs(t, []string{"target", "base"}, files)
|
||||||
SetWorkingDir(t, wd.String())
|
SetWorkingDir(t, wd.String())
|
||||||
|
|
||||||
err := localizer.Run(fsActual, "target", ".", "")
|
dst, err := localizer.Run(fsActual, "target", ".", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, wd.Join("localized-target"), dst)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, wd.Join("localized-target"), files)
|
SetupDir(t, fsExpected, dst, files)
|
||||||
CheckFs(t, wd.String(), fsExpected, fsActual)
|
CheckFs(t, wd.String(), fsExpected, fsActual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,10 +302,10 @@ func TestLoaderSymlinks(t *testing.T) {
|
|||||||
})
|
})
|
||||||
SetWorkingDir(t, testDir.String())
|
SetWorkingDir(t, testDir.String())
|
||||||
|
|
||||||
err := localizer.Run(fsActual, "target-link", "target", "")
|
dst, err := localizer.Run(fsActual, "target-link", "target", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, testDir.Join("localized-target"), dst)
|
||||||
|
|
||||||
dst := testDir.Join("localized-target")
|
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
"kustomization.yaml": fmt.Sprintf(`resources:
|
"kustomization.yaml": fmt.Sprintf(`resources:
|
||||||
- %s
|
- %s
|
||||||
@@ -322,10 +323,10 @@ func TestRemoteTargetDefaultDst(t *testing.T) {
|
|||||||
SetWorkingDir(t, testDir.String())
|
SetWorkingDir(t, testDir.String())
|
||||||
|
|
||||||
const target = simpleURL + urlQuery
|
const target = simpleURL + urlQuery
|
||||||
err := localizer.Run(fsActual, target, "", "")
|
dst, err := localizer.Run(fsActual, target, "", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, testDir.Join("localized-simple-kustomize-v4.5.7"), dst)
|
||||||
|
|
||||||
dst := testDir.Join("localized-simple-kustomize-v4.5.7")
|
|
||||||
_, files := simplePathAndFiles(t)
|
_, files := simplePathAndFiles(t)
|
||||||
SetupDir(t, fsExpected,
|
SetupDir(t, fsExpected,
|
||||||
filepath.Join(dst, "api", "krusty", "testdata", "localize", "simple"),
|
filepath.Join(dst, "api", "krusty", "testdata", "localize", "simple"),
|
||||||
@@ -364,7 +365,7 @@ func TestBadArgs(t *testing.T) {
|
|||||||
fsExpected, fsActual, testDir := PrepareFs(t, nil, kust)
|
fsExpected, fsActual, testDir := PrepareFs(t, nil, kust)
|
||||||
SetWorkingDir(t, testDir.String())
|
SetWorkingDir(t, testDir.String())
|
||||||
|
|
||||||
err := localizer.Run(fsActual, test.target, test.scope, test.dst)
|
_, err := localizer.Run(fsActual, test.target, test.scope, test.dst)
|
||||||
require.EqualError(t, err, test.err)
|
require.EqualError(t, err, test.err)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, testDir.String(), kust)
|
SetupDir(t, fsExpected, testDir.String(), kust)
|
||||||
@@ -383,9 +384,10 @@ openapi:
|
|||||||
"kustomization.yaml": fmt.Sprintf(kustf, `https://raw.githubusercontent.com/kubernetes-sigs/kustomize/kustomize/v4.5.7/api/krusty/testdata/customschema.json`),
|
"kustomization.yaml": fmt.Sprintf(kustf, `https://raw.githubusercontent.com/kubernetes-sigs/kustomize/kustomize/v4.5.7/api/krusty/testdata/customschema.json`),
|
||||||
})
|
})
|
||||||
|
|
||||||
dst := testDir.Join("dst")
|
newDir := testDir.Join("dst")
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
localizedPath := filepath.Join(LocalizeDir, "raw.githubusercontent.com",
|
localizedPath := filepath.Join(LocalizeDir, "raw.githubusercontent.com",
|
||||||
"kubernetes-sigs", "kustomize", "kustomize", "v4.5.7", "api", "krusty",
|
"kubernetes-sigs", "kustomize", "kustomize", "v4.5.7", "api", "krusty",
|
||||||
@@ -404,9 +406,10 @@ func TestRemoteRoot(t *testing.T) {
|
|||||||
`, simpleURL+urlQuery),
|
`, simpleURL+urlQuery),
|
||||||
})
|
})
|
||||||
|
|
||||||
dst := testDir.Join("dst")
|
newDir := testDir.Join("dst")
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
localizedPath, files := simplePathAndFiles(t)
|
localizedPath, files := simplePathAndFiles(t)
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
@@ -427,9 +430,10 @@ func TestNestedRemoteRoots(t *testing.T) {
|
|||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|
||||||
dst := testDir.Join("dst")
|
newDir := testDir.Join("dst")
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
localizedPath, files := remotePathAndFiles(t)
|
localizedPath, files := remotePathAndFiles(t)
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
@@ -450,15 +454,13 @@ func TestResourcesRepoNotFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
|
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
|
||||||
|
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||||
|
|
||||||
const readmeErr = `mapping values are not allowed in this context`
|
fileErr := fmt.Sprintf(`invalid resource at file "%s"`, repo)
|
||||||
fileErr := fmt.Sprintf(`invalid resource at file "%s": MalformedYAMLError:`, repo)
|
|
||||||
rootErr := fmt.Sprintf(`unable to localize root "%s": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization'`, repo)
|
rootErr := fmt.Sprintf(`unable to localize root "%s": unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization'`, repo)
|
||||||
var actualErr PathLocalizeError
|
var actualErr PathLocalizeError
|
||||||
require.ErrorAs(t, err, &actualErr)
|
require.ErrorAs(t, err, &actualErr)
|
||||||
require.Equal(t, repo, actualErr.Path)
|
require.Equal(t, repo, actualErr.Path)
|
||||||
require.ErrorContains(t, actualErr.FileError, readmeErr)
|
|
||||||
require.ErrorContains(t, actualErr.FileError, fileErr)
|
require.ErrorContains(t, actualErr.FileError, fileErr)
|
||||||
require.ErrorContains(t, actualErr.RootError, rootErr)
|
require.ErrorContains(t, actualErr.RootError, rootErr)
|
||||||
|
|
||||||
@@ -475,7 +477,7 @@ func TestRemoteRootNoRef(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
|
fsExpected, fsActual, testDir := PrepareFs(t, nil, kustomization)
|
||||||
|
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||||
|
|
||||||
const fileErr = "invalid file reference: URL is a git repository"
|
const fileErr = "invalid file reference: URL is a git repository"
|
||||||
rootErr := fmt.Sprintf(`localize remote root "%s" missing ref query string parameter`, root)
|
rootErr := fmt.Sprintf(`localize remote root "%s" missing ref query string parameter`, root)
|
||||||
@@ -499,7 +501,7 @@ func TestExistingCacheDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
fsExpected, fsActual, testDir := PrepareFs(t, []string{LocalizeDir}, file)
|
fsExpected, fsActual, testDir := PrepareFs(t, []string{LocalizeDir}, file)
|
||||||
|
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
_, err := localizer.Run(fsActual, testDir.String(), "", testDir.Join("dst"))
|
||||||
require.ErrorContains(t, err, fmt.Sprintf(`already contains localized-files needed to store file "%s"`, remoteFile))
|
require.ErrorContains(t, err, fmt.Sprintf(`already contains localized-files needed to store file "%s"`, remoteFile))
|
||||||
|
|
||||||
SetupDir(t, fsExpected, testDir.String(), file)
|
SetupDir(t, fsExpected, testDir.String(), file)
|
||||||
@@ -520,9 +522,10 @@ minecraftServer:
|
|||||||
filepath.Join("nested", "dirs", "home", "name"),
|
filepath.Join("nested", "dirs", "home", "name"),
|
||||||
}, files)
|
}, files)
|
||||||
|
|
||||||
dst := testDir.Join("dst")
|
newDir := testDir.Join("dst")
|
||||||
err := localizer.Run(fsActual, testDir.String(), "", dst)
|
dst, err := localizer.Run(fsActual, testDir.String(), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, dst, files)
|
SetupDir(t, fsExpected, dst, files)
|
||||||
CheckFs(t, dst, fsExpected, fsActual)
|
CheckFs(t, dst, fsExpected, fsActual)
|
||||||
@@ -555,9 +558,10 @@ helmGlobals:
|
|||||||
filepath.Join("target", "home-link"): "home",
|
filepath.Join("target", "home-link"): "home",
|
||||||
})
|
})
|
||||||
|
|
||||||
dst := scope.Join("dst")
|
newDir := scope.Join("dst")
|
||||||
err := localizer.Run(fsActual, scope.Join("target"), scope.String(), dst)
|
dst, err := localizer.Run(fsActual, scope.Join("target"), scope.String(), newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
filepath.Join("target", "Kustomization"): fmt.Sprintf(`helmCharts:
|
filepath.Join("target", "Kustomization"): fmt.Sprintf(`helmCharts:
|
||||||
@@ -594,9 +598,10 @@ helmChartInflationGenerator:
|
|||||||
})
|
})
|
||||||
link(t, target, map[string]string{"charts": "home"})
|
link(t, target, map[string]string{"charts": "home"})
|
||||||
|
|
||||||
dst := target.Join("dst")
|
newDir := target.Join("dst")
|
||||||
err := localizer.Run(fsActual, target.String(), "", dst)
|
dst, err := localizer.Run(fsActual, target.String(), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
"kustomization.yaml": `helmChartInflationGenerator:
|
"kustomization.yaml": `helmChartInflationGenerator:
|
||||||
@@ -634,9 +639,10 @@ func TestHelmHomeEscapesScope(t *testing.T) {
|
|||||||
filepath.Join("target", "home", "file-link"): "file",
|
filepath.Join("target", "home", "file-link"): "file",
|
||||||
})
|
})
|
||||||
|
|
||||||
dst := testDir.Join("dst")
|
newDir := testDir.Join("dst")
|
||||||
err := localizer.Run(fsActual, testDir.Join("target"), "", dst)
|
dst, err := localizer.Run(fsActual, testDir.Join("target"), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
"kustomization.yaml": `helmGlobals:
|
"kustomization.yaml": `helmGlobals:
|
||||||
@@ -663,9 +669,10 @@ func TestSymlinkedFileSource(t *testing.T) {
|
|||||||
"filename-used-as-key-in-configMap": "different-key",
|
"filename-used-as-key-in-configMap": "different-key",
|
||||||
})
|
})
|
||||||
|
|
||||||
dst := target.Join("dst")
|
newDir := target.Join("dst")
|
||||||
err := localizer.Run(fsActual, target.String(), "", dst)
|
dst, err := localizer.Run(fsActual, target.String(), "", newDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, newDir, dst)
|
||||||
|
|
||||||
SetupDir(t, fsExpected, dst, map[string]string{
|
SetupDir(t, fsExpected, dst, map[string]string{
|
||||||
"kustomization.yaml": `configMapGenerator:
|
"kustomization.yaml": `configMapGenerator:
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ const expected = `apiVersion: v1
|
|||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app.kubernetes.io/managed-by: kustomize-v444.333.222
|
app.kubernetes.io/managed-by: kustomize-(test)
|
||||||
name: myService
|
name: myService
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- port: 7002
|
- port: 7002
|
||||||
`
|
`
|
||||||
|
|
||||||
// This test may failed when running on package tests using the go command because `v444.333.222` is set on makefile.
|
// This test may fail when running on package tests using the go command because `(test)` is set on makefile.
|
||||||
func TestAddManagedbyLabel(t *testing.T) {
|
func TestAddManagedbyLabel(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
kustFile string
|
kustFile string
|
||||||
|
|||||||
5
api/krusty/testdata/helmcharts/test-chart/Chart.yaml
vendored
Normal file
5
api/krusty/testdata/helmcharts/test-chart/Chart.yaml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
appVersion: "1.0"
|
||||||
|
description: A simple test helm chart.
|
||||||
|
name: test
|
||||||
|
version: 1.0.0
|
||||||
1
api/krusty/testdata/helmcharts/test-chart/README.md
vendored
Normal file
1
api/krusty/testdata/helmcharts/test-chart/README.md
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This is a simple test chart.
|
||||||
7
api/krusty/testdata/helmcharts/test-chart/templates/_helpers.tpl
vendored
Normal file
7
api/krusty/testdata/helmcharts/test-chart/templates/_helpers.tpl
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{{- define "apiversion" -}}
|
||||||
|
{{- if .Capabilities.APIVersions.Has "foo/v1" -}}
|
||||||
|
foo/v1
|
||||||
|
{{- else -}}
|
||||||
|
apps/v1
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
18
api/krusty/testdata/helmcharts/test-chart/templates/deployment.yaml
vendored
Normal file
18
api/krusty/testdata/helmcharts/test-chart/templates/deployment.yaml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
apiVersion: {{ template "apiversion" . }}
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
|
||||||
|
name: my-deploy
|
||||||
|
namespace: {{ .Values.data.namespace }}
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: {{ .Chart.Name }}
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: "{{ .Values.data.image.name }}:{{ .Values.data.image.tag }}"
|
||||||
|
imagePullPolicy: {{ .Values.data.image.imagePullPolicy }}
|
||||||
6
api/krusty/testdata/helmcharts/test-chart/templates/tests/test-pod.yaml
vendored
Normal file
6
api/krusty/testdata/helmcharts/test-chart/templates/tests/test-pod.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: {{ template "apiversion" . }}
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}
|
||||||
|
annotations:
|
||||||
|
"helm.sh/hook": test
|
||||||
6
api/krusty/testdata/helmcharts/test-chart/values.yaml
vendored
Normal file
6
api/krusty/testdata/helmcharts/test-chart/values.yaml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
data:
|
||||||
|
namespace: default
|
||||||
|
image:
|
||||||
|
name: test-image
|
||||||
|
tag: v1.0.0
|
||||||
|
imagePullPolicy: Always
|
||||||
5
api/krusty/testdata/helmcharts/valuesFiles/file1.yaml
vendored
Normal file
5
api/krusty/testdata/helmcharts/valuesFiles/file1.yaml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
data:
|
||||||
|
image:
|
||||||
|
name: test-image-file1
|
||||||
|
tag: file1
|
||||||
|
imagePullPolicy: Never
|
||||||
2
api/krusty/testdata/helmcharts/valuesFiles/file2.yaml
vendored
Normal file
2
api/krusty/testdata/helmcharts/valuesFiles/file2.yaml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
data:
|
||||||
|
namespace: file-2
|
||||||
@@ -6,47 +6,63 @@ package provenance
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// These variables are set at build time using ldflags.
|
||||||
|
//
|
||||||
|
//nolint:gochecknoglobals
|
||||||
var (
|
var (
|
||||||
version = "unknown"
|
// During a release, this will be set to the release tag, e.g. "kustomize/v4.5.7"
|
||||||
// sha1 from git, output of $(git rev-parse HEAD)
|
version = developmentVersion
|
||||||
gitCommit = "$Format:%H$"
|
|
||||||
// build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
// build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
||||||
buildDate = "1970-01-01T00:00:00Z"
|
buildDate = "unknown"
|
||||||
goos = runtime.GOOS
|
|
||||||
goarch = runtime.GOARCH
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// This default value, (devel), matches
|
||||||
|
// the value debug.BuildInfo uses for an unset main module version.
|
||||||
|
const developmentVersion = "(devel)"
|
||||||
|
|
||||||
// Provenance holds information about the build of an executable.
|
// Provenance holds information about the build of an executable.
|
||||||
type Provenance struct {
|
type Provenance struct {
|
||||||
// Version of the kustomize binary.
|
// Version of the kustomize binary.
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty" yaml:"version,omitempty"`
|
||||||
// GitCommit is a git commit
|
// GitCommit is a git commit
|
||||||
GitCommit string `json:"gitCommit,omitempty"`
|
GitCommit string `json:"gitCommit,omitempty" yaml:"gitCommit,omitempty"`
|
||||||
// BuildDate is date of the build.
|
// BuildDate is date of the build.
|
||||||
BuildDate string `json:"buildDate,omitempty"`
|
BuildDate string `json:"buildDate,omitempty" yaml:"buildDate,omitempty"`
|
||||||
// GoOs holds OS name.
|
// GoOs holds OS name.
|
||||||
GoOs string `json:"goOs,omitempty"`
|
GoOs string `json:"goOs,omitempty" yaml:"goOs,omitempty"`
|
||||||
// GoArch holds architecture name.
|
// GoArch holds architecture name.
|
||||||
GoArch string `json:"goArch,omitempty"`
|
GoArch string `json:"goArch,omitempty" yaml:"goArch,omitempty"`
|
||||||
|
// GoVersion holds Go version.
|
||||||
|
GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetProvenance returns an instance of Provenance.
|
// GetProvenance returns an instance of Provenance.
|
||||||
func GetProvenance() Provenance {
|
func GetProvenance() Provenance {
|
||||||
return Provenance{
|
p := Provenance{
|
||||||
version,
|
BuildDate: buildDate,
|
||||||
gitCommit,
|
Version: version,
|
||||||
buildDate,
|
GitCommit: "unknown",
|
||||||
goos,
|
GoOs: runtime.GOOS,
|
||||||
goarch,
|
GoArch: runtime.GOARCH,
|
||||||
|
GoVersion: runtime.Version(),
|
||||||
|
}
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Full returns the full provenance stamp.
|
for _, setting := range info.Settings {
|
||||||
func (v Provenance) Full() string {
|
// For now, the git commit is the only information of interest.
|
||||||
return fmt.Sprintf("%+v", v)
|
// We could consider adding other info such as the commit date in the future.
|
||||||
|
if setting.Key == "vcs.revision" {
|
||||||
|
p.GitCommit = setting.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Short returns the shortened provenance stamp.
|
// Short returns the shortened provenance stamp.
|
||||||
|
|||||||
47
api/provenance/provenance_test.go
Normal file
47
api/provenance/provenance_test.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2022 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package provenance_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"sigs.k8s.io/kustomize/api/provenance"
|
||||||
|
)
|
||||||
|
|
||||||
|
const expectedBuildDateFromLdFlag = "2023-01-31T23:38:41Z"
|
||||||
|
const expectedVersionFromLdFlag = "(test)"
|
||||||
|
|
||||||
|
func TestGetProvenance(t *testing.T) {
|
||||||
|
p := provenance.GetProvenance()
|
||||||
|
// These are set by ldflags in our Makefile
|
||||||
|
assert.Equal(t, expectedVersionFromLdFlag, p.Version)
|
||||||
|
assert.Equal(t, expectedBuildDateFromLdFlag, p.BuildDate)
|
||||||
|
// This comes from BuildInfo, which is not set during go test: https://github.com/golang/go/issues/33976
|
||||||
|
assert.Equal(t, "unknown", p.GitCommit)
|
||||||
|
|
||||||
|
// These are set properly during go test
|
||||||
|
assert.NotEmpty(t, p.GoArch)
|
||||||
|
assert.NotEmpty(t, p.GoOs)
|
||||||
|
assert.Contains(t, p.GoVersion, "go1.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProvenance_Short(t *testing.T) {
|
||||||
|
p := provenance.GetProvenance()
|
||||||
|
// The version not set during go test, so this comes from an ldflag: https://github.com/golang/go/issues/33976
|
||||||
|
assert.Equal(t, fmt.Sprintf("{%s %s }", expectedVersionFromLdFlag, expectedBuildDateFromLdFlag), p.Short())
|
||||||
|
|
||||||
|
p.Version = "kustomize/v4.11.12"
|
||||||
|
assert.Equal(t, fmt.Sprintf("{kustomize/v4.11.12 %s }", expectedBuildDateFromLdFlag), p.Short())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProvenance_Semver(t *testing.T) {
|
||||||
|
p := provenance.GetProvenance()
|
||||||
|
// The version not set during go test
|
||||||
|
assert.Equal(t, "(test)", p.Semver())
|
||||||
|
|
||||||
|
p.Version = "kustomize/v4.11.12"
|
||||||
|
assert.Equal(t, "v4.11.12", p.Semver())
|
||||||
|
}
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
|
import "path/filepath"
|
||||||
|
|
||||||
const HelmDefaultHome = "charts"
|
const HelmDefaultHome = "charts"
|
||||||
|
|
||||||
type HelmGlobals struct {
|
type HelmGlobals struct {
|
||||||
@@ -57,7 +59,11 @@ type HelmChart struct {
|
|||||||
// in the helm template
|
// in the helm template
|
||||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||||
|
|
||||||
// ValuesFile is local file path to a values file to use _instead of_
|
// AdditionalValuesFiles are local file paths to values files to be used in
|
||||||
|
// addition to either the default values file or the values specified in ValuesFile.
|
||||||
|
AdditionalValuesFiles []string `json:"additionalValuesFiles,omitempty" yaml:"additionalValuesFiles,omitempty"`
|
||||||
|
|
||||||
|
// ValuesFile is a local file path to a values file to use _instead of_
|
||||||
// the default values that accompanied the chart.
|
// the default values that accompanied the chart.
|
||||||
// The default values are in '{ChartHome}/{Name}/values.yaml'.
|
// The default values are in '{ChartHome}/{Name}/values.yaml'.
|
||||||
ValuesFile string `json:"valuesFile,omitempty" yaml:"valuesFile,omitempty"`
|
ValuesFile string `json:"valuesFile,omitempty" yaml:"valuesFile,omitempty"`
|
||||||
@@ -78,6 +84,15 @@ type HelmChart struct {
|
|||||||
// SkipHooks sets the --no-hooks flag when calling helm template. This prevents
|
// SkipHooks sets the --no-hooks flag when calling helm template. This prevents
|
||||||
// helm from erroneously rendering test templates.
|
// helm from erroneously rendering test templates.
|
||||||
SkipHooks bool `json:"skipHooks,omitempty" yaml:"skipHooks,omitempty"`
|
SkipHooks bool `json:"skipHooks,omitempty" yaml:"skipHooks,omitempty"`
|
||||||
|
|
||||||
|
// ApiVersions is the kubernetes apiversions used for Capabilities.APIVersions
|
||||||
|
ApiVersions []string `json:"apiVersions,omitempty" yaml:"apiVersions,omitempty"`
|
||||||
|
|
||||||
|
// NameTemplate is for specifying the name template used to name the release.
|
||||||
|
NameTemplate string `json:"nameTemplate,omitempty" yaml:"nameTemplate,omitempty"`
|
||||||
|
|
||||||
|
// SkipTests skips tests from templated output.
|
||||||
|
SkipTests bool `json:"skipTests,omitempty" yaml:"skipTests,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HelmChartArgs contains arguments to helm.
|
// HelmChartArgs contains arguments to helm.
|
||||||
@@ -126,3 +141,45 @@ func makeHelmChartFromHca(old *HelmChartArgs) (c HelmChart) {
|
|||||||
c.ReleaseName = old.ReleaseName
|
c.ReleaseName = old.ReleaseName
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h HelmChart) AsHelmArgs(absChartHome string) []string {
|
||||||
|
args := []string{"template"}
|
||||||
|
if h.ReleaseName != "" {
|
||||||
|
args = append(args, h.ReleaseName)
|
||||||
|
} else {
|
||||||
|
// AFAICT, this doesn't work as intended due to a bug in helm.
|
||||||
|
// See https://github.com/helm/helm/issues/6019
|
||||||
|
// I've tried placing the flag before and after the name argument.
|
||||||
|
args = append(args, "--generate-name")
|
||||||
|
}
|
||||||
|
if h.Name != "" {
|
||||||
|
args = append(args, filepath.Join(absChartHome, h.Name))
|
||||||
|
}
|
||||||
|
if h.Namespace != "" {
|
||||||
|
args = append(args, "--namespace", h.Namespace)
|
||||||
|
}
|
||||||
|
if h.NameTemplate != "" {
|
||||||
|
args = append(args, "--name-template", h.NameTemplate)
|
||||||
|
}
|
||||||
|
|
||||||
|
if h.ValuesFile != "" {
|
||||||
|
args = append(args, "-f", h.ValuesFile)
|
||||||
|
}
|
||||||
|
for _, valuesFile := range h.AdditionalValuesFiles {
|
||||||
|
args = append(args, "-f", valuesFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, apiVer := range h.ApiVersions {
|
||||||
|
args = append(args, "--api-versions", apiVer)
|
||||||
|
}
|
||||||
|
if h.IncludeCRDs {
|
||||||
|
args = append(args, "--include-crds")
|
||||||
|
}
|
||||||
|
if h.SkipTests {
|
||||||
|
args = append(args, "--skip-tests")
|
||||||
|
}
|
||||||
|
if h.SkipHooks {
|
||||||
|
args = append(args, "--no-hooks")
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|||||||
61
api/types/helmchartargs_test.go
Normal file
61
api/types/helmchartargs_test.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// Copyright 2019 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package types_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"sigs.k8s.io/kustomize/api/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAsHelmArgs(t *testing.T) {
|
||||||
|
t.Run("use generate-name", func(t *testing.T) {
|
||||||
|
p := types.HelmChart{
|
||||||
|
Name: "chart-name",
|
||||||
|
Version: "1.0.0",
|
||||||
|
Repo: "https://helm.releases.hashicorp.com",
|
||||||
|
ApiVersions: []string{"foo", "bar"},
|
||||||
|
NameTemplate: "template",
|
||||||
|
SkipTests: true,
|
||||||
|
IncludeCRDs: true,
|
||||||
|
SkipHooks: true,
|
||||||
|
ValuesFile: "values",
|
||||||
|
AdditionalValuesFiles: []string{"values1", "values2"},
|
||||||
|
Namespace: "my-ns",
|
||||||
|
}
|
||||||
|
require.Equal(t, p.AsHelmArgs("/home/charts"),
|
||||||
|
[]string{"template", "--generate-name",
|
||||||
|
"/home/charts/chart-name",
|
||||||
|
"--namespace", "my-ns",
|
||||||
|
"--name-template", "template",
|
||||||
|
"-f", "values",
|
||||||
|
"-f", "values1", "-f", "values2",
|
||||||
|
"--api-versions", "foo", "--api-versions", "bar",
|
||||||
|
"--include-crds",
|
||||||
|
"--skip-tests",
|
||||||
|
"--no-hooks"})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("use release-name", func(t *testing.T) {
|
||||||
|
p := types.HelmChart{
|
||||||
|
Name: "chart-name",
|
||||||
|
Version: "1.0.0",
|
||||||
|
Repo: "https://helm.releases.hashicorp.com",
|
||||||
|
ApiVersions: []string{"foo", "bar"},
|
||||||
|
NameTemplate: "template",
|
||||||
|
ValuesFile: "values",
|
||||||
|
AdditionalValuesFiles: []string{"values1", "values2"},
|
||||||
|
Namespace: "my-ns",
|
||||||
|
ReleaseName: "test",
|
||||||
|
}
|
||||||
|
require.Equal(t, p.AsHelmArgs("/home/charts"),
|
||||||
|
[]string{"template", "test", "/home/charts/chart-name",
|
||||||
|
"--namespace", "my-ns",
|
||||||
|
"--name-template", "template",
|
||||||
|
"-f", "values",
|
||||||
|
"-f", "values1", "-f", "values2",
|
||||||
|
"--api-versions", "foo", "--api-versions", "bar"})
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ require (
|
|||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.1
|
||||||
gopkg.in/inf.v0 v0.9.1
|
gopkg.in/inf.v0 v0.9.1
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -23,7 +23,6 @@ require (
|
|||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/sergi/go-diff v1.1.0 // indirect
|
github.com/sergi/go-diff v1.1.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
|||||||
@@ -60,8 +60,6 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
|
|||||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
@@ -153,7 +151,7 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
|
|||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
|
sigs.k8s.io/kustomize/kyaml v0.14.0 h1:uzH0MzMtYypHW09LbMDk8k/lT/LSsUuCoZIuEGhIBNE=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
|
sigs.k8s.io/kustomize/kyaml v0.14.0/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
|
||||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
"sigs.k8s.io/kustomize/kyaml/openapi"
|
"sigs.k8s.io/kustomize/kyaml/openapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -614,7 +615,7 @@ spec:
|
|||||||
defer openapi.ResetOpenAPI()
|
defer openapi.ResetOpenAPI()
|
||||||
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
||||||
baseDir := t.TempDir()
|
baseDir := t.TempDir()
|
||||||
copyutil.CopyDir(sourceDir, baseDir)
|
assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), sourceDir, baseDir))
|
||||||
runner := commands.GetCatRunner("")
|
runner := commands.GetCatRunner("")
|
||||||
actual := &bytes.Buffer{}
|
actual := &bytes.Buffer{}
|
||||||
runner.Command.SetOut(actual)
|
runner.Command.SetOut(actual)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
"sigs.k8s.io/kustomize/kyaml/openapi"
|
"sigs.k8s.io/kustomize/kyaml/openapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ Deployment: 1
|
|||||||
defer openapi.ResetOpenAPI()
|
defer openapi.ResetOpenAPI()
|
||||||
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
||||||
baseDir := t.TempDir()
|
baseDir := t.TempDir()
|
||||||
copyutil.CopyDir(sourceDir, baseDir)
|
assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), sourceDir, baseDir))
|
||||||
runner := commands.GetCountRunner("")
|
runner := commands.GetCountRunner("")
|
||||||
actual := &bytes.Buffer{}
|
actual := &bytes.Buffer{}
|
||||||
runner.Command.SetOut(actual)
|
runner.Command.SetOut(actual)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestGrepCommand_files verifies grep reads the files and filters them
|
// TestGrepCommand_files verifies grep reads the files and filters them
|
||||||
@@ -396,7 +397,7 @@ spec:
|
|||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
sourceDir := filepath.Join("test", "testdata", test.dataset)
|
||||||
baseDir := t.TempDir()
|
baseDir := t.TempDir()
|
||||||
copyutil.CopyDir(sourceDir, baseDir)
|
assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), sourceDir, baseDir))
|
||||||
runner := commands.GetGrepRunner("")
|
runner := commands.GetGrepRunner("")
|
||||||
actual := &bytes.Buffer{}
|
actual := &bytes.Buffer{}
|
||||||
runner.Command.SetOut(actual)
|
runner.Command.SetOut(actual)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ require (
|
|||||||
github.com/spf13/cobra v1.4.0
|
github.com/spf13/cobra v1.4.0
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.1
|
||||||
sigs.k8s.io/kustomize/api v0.12.1
|
sigs.k8s.io/kustomize/api v0.12.1
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -25,7 +25,6 @@ require (
|
|||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/xlab/treeprint v1.1.0 // indirect
|
github.com/xlab/treeprint v1.1.0 // indirect
|
||||||
@@ -37,3 +36,5 @@ require (
|
|||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
|
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
|
||||||
sigs.k8s.io/yaml v1.3.0 // indirect
|
sigs.k8s.io/yaml v1.3.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace sigs.k8s.io/kustomize/api => ../../api
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
|
|||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
@@ -156,9 +155,7 @@ k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPK
|
|||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
|
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
|
||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||||
sigs.k8s.io/kustomize/api v0.12.1 h1:7YM7gW3kYBwtKvoY216ZzY+8hM+lV53LUayghNRJ0vM=
|
sigs.k8s.io/kustomize/kyaml v0.14.0 h1:uzH0MzMtYypHW09LbMDk8k/lT/LSsUuCoZIuEGhIBNE=
|
||||||
sigs.k8s.io/kustomize/api v0.12.1/go.mod h1:y3JUhimkZkR6sbLNwfJHxvo1TCLwuwm14sCYnkH6S1s=
|
sigs.k8s.io/kustomize/kyaml v0.14.0/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
|
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
|
|
||||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||||
|
|||||||
50
hack/with-unpinned-kust-dev.sh
Executable file
50
hack/with-unpinned-kust-dev.sh
Executable file
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Copyright 2023 The Kubernetes Authors.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
set -x
|
||||||
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
# This script uses 'replace' statements to 'unpin' local modules from module versions go.mod normally
|
||||||
|
# requires, so that the local version will be used instead. With the advent of Workspace mode, we no longer
|
||||||
|
# need to do this in general in between releases. However, some key commands like `go mod tidy` are not
|
||||||
|
# Workspace-aware and thus will fail if API changes between modules exist on master. This script allows us to
|
||||||
|
# test those commands without requiring unpin operations in our release workflow.
|
||||||
|
|
||||||
|
if [[ -z "${1-}" ]] ; then
|
||||||
|
echo "Usage: $0 <cmd>"
|
||||||
|
echo "Example: $0 'go mod tidy -v'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cmd=$1
|
||||||
|
|
||||||
|
# First we read in the list of all kustomize modules and their local locations. The data looks like:
|
||||||
|
# sigs.k8s.io/kustomize/api /Users/you/src/sigs.k8s.io/kustomize/api
|
||||||
|
# sigs.k8s.io/kustomize/cmd/config /Users/you/src/sigs.k8s.io/kustomize/cmd/config
|
||||||
|
IFS=$'\n'
|
||||||
|
modules=($(go list -m -f "{{.Path}} {{.Dir}}"))
|
||||||
|
|
||||||
|
# Next we iterate over the lines, split apart the module name and local absolute path,
|
||||||
|
# and add a relative-path replace statement to the go.mod. A replace statement will be added
|
||||||
|
# for each Kustomize module, whether or not the current module uses it.
|
||||||
|
IFS=" "
|
||||||
|
replace_args=""
|
||||||
|
for module in "${modules[@]}"; do
|
||||||
|
read -a module_data <<< $module
|
||||||
|
replace_path=$(realpath --relative-to=$(pwd) ${module_data[1]})
|
||||||
|
if [ $replace_path == . ] || [[ $replace_path == internal/* ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
replace_args+=" -replace=${module_data[0]}=$replace_path"
|
||||||
|
done
|
||||||
|
|
||||||
|
go mod edit $replace_args
|
||||||
|
|
||||||
|
# Now that the modules are pinned, we run the command passed to this script.
|
||||||
|
bash -c "$cmd"
|
||||||
|
|
||||||
|
# Finally we clean up by dropping the replace statements we added above.
|
||||||
|
go mod edit $(sed 's/-replace/-dropreplace/g' <<< "$replace_args" | sed -E 's/=\.\.[^[:space:]]*//g')
|
||||||
@@ -12,7 +12,6 @@ ADD . /build/
|
|||||||
WORKDIR /build/kustomize
|
WORKDIR /build/kustomize
|
||||||
RUN CGO_ENABLED=0 GO111MODULE=on go build \
|
RUN CGO_ENABLED=0 GO111MODULE=on go build \
|
||||||
-ldflags="-s -X sigs.k8s.io/kustomize/api/provenance.version=${VERSION} \
|
-ldflags="-s -X sigs.k8s.io/kustomize/api/provenance.version=${VERSION} \
|
||||||
-X sigs.k8s.io/kustomize/api/provenance.gitCommit=${COMMIT} \
|
|
||||||
-X sigs.k8s.io/kustomize/api/provenance.buildDate=${DATE}"
|
-X sigs.k8s.io/kustomize/api/provenance.buildDate=${DATE}"
|
||||||
|
|
||||||
# only copy binary
|
# only copy binary
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/kustomize/v4/commands/build"
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/build"
|
||||||
"sigs.k8s.io/kustomize/kustomize/v4/commands/create"
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/create"
|
||||||
"sigs.k8s.io/kustomize/kustomize/v4/commands/edit"
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/edit"
|
||||||
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/localize"
|
||||||
"sigs.k8s.io/kustomize/kustomize/v4/commands/openapi"
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/openapi"
|
||||||
"sigs.k8s.io/kustomize/kustomize/v4/commands/version"
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/version"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
@@ -53,6 +54,7 @@ See https://sigs.k8s.io/kustomize
|
|||||||
create.NewCmdCreate(fSys, pvd.GetResourceFactory()),
|
create.NewCmdCreate(fSys, pvd.GetResourceFactory()),
|
||||||
version.NewCmdVersion(stdOut),
|
version.NewCmdVersion(stdOut),
|
||||||
openapi.NewCmdOpenAPI(stdOut),
|
openapi.NewCmdOpenAPI(stdOut),
|
||||||
|
localize.NewCmdLocalize(fSys, stdOut),
|
||||||
)
|
)
|
||||||
configcobra.AddCommands(c, konfig.ProgramName)
|
configcobra.AddCommands(c, konfig.ProgramName)
|
||||||
|
|
||||||
|
|||||||
98
kustomize/commands/localize/localize.go
Normal file
98
kustomize/commands/localize/localize.go
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
// Copyright 2022 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package localize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
lclzr "sigs.k8s.io/kustomize/api/krusty/localizer"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
|
)
|
||||||
|
|
||||||
|
const numArgs = 2
|
||||||
|
|
||||||
|
type arguments struct {
|
||||||
|
target string
|
||||||
|
dest string
|
||||||
|
}
|
||||||
|
|
||||||
|
type flags struct {
|
||||||
|
scope string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCmdLocalize returns a new localize command.
|
||||||
|
func NewCmdLocalize(fs filesys.FileSystem, writer io.Writer) *cobra.Command {
|
||||||
|
log.SetOutput(writer)
|
||||||
|
var f flags
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "localize [target [destination]]",
|
||||||
|
Short: "[Alpha] Creates localized copy of target kustomization root at destination",
|
||||||
|
Long: `[Alpha] Creates copy of target kustomization directory or
|
||||||
|
versioned URL at destination, where remote references in the original
|
||||||
|
are replaced by local references to the downloaded remote content.
|
||||||
|
|
||||||
|
If target is not specified, the current working directory will be used.
|
||||||
|
Destination is a path to a new directory in an existing directory. If
|
||||||
|
destination is not specified, a new directory will be created in the current
|
||||||
|
working directory.
|
||||||
|
|
||||||
|
For details, see: https://kubectl.docs.kubernetes.io/references/kustomize/cmd/
|
||||||
|
|
||||||
|
Disclaimer:
|
||||||
|
This command does not yet localize helm or KRM plugin fields. This command also
|
||||||
|
alphabetizes kustomization fields in the localized copy.
|
||||||
|
`,
|
||||||
|
Example: `
|
||||||
|
# Localize the current working directory, with default scope and destination
|
||||||
|
kustomize localize
|
||||||
|
|
||||||
|
# Localize some local directory, with scope and default destination
|
||||||
|
kustomize localize /home/path/scope/target --scope /home/path/scope
|
||||||
|
|
||||||
|
# Localize remote at set destination relative to working directory
|
||||||
|
kustomize localize https://github.com/kubernetes-sigs/kustomize//api/krusty/testdata/localize/simple?ref=v4.5.7 path/non-existing-dir
|
||||||
|
`,
|
||||||
|
SilenceUsage: true,
|
||||||
|
Args: cobra.MaximumNArgs(numArgs),
|
||||||
|
RunE: func(cmd *cobra.Command, rawArgs []string) error {
|
||||||
|
args := matchArgs(rawArgs)
|
||||||
|
dst, err := lclzr.Run(fs, args.target, f.scope, args.dest)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err)
|
||||||
|
}
|
||||||
|
successMsg := fmt.Sprintf("SUCCESS: localized %q to directory %s\n", args.target, dst)
|
||||||
|
_, err = writer.Write([]byte(successMsg))
|
||||||
|
return errors.Wrap(err)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// no shorthand to avoid conflation with other flags
|
||||||
|
cmd.Flags().StringVar(&f.scope,
|
||||||
|
"scope",
|
||||||
|
"",
|
||||||
|
`Path to directory inside of which localize is limited to running.
|
||||||
|
Cannot specify for remote targets, as scope is by default the containing repo.
|
||||||
|
If not specified for local target, scope defaults to target.
|
||||||
|
`)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// matchArgs matches user-entered userArgs, which cannot exceed max length, with
|
||||||
|
// arguments.
|
||||||
|
func matchArgs(rawArgs []string) arguments {
|
||||||
|
var args arguments
|
||||||
|
switch len(rawArgs) {
|
||||||
|
case numArgs:
|
||||||
|
args.dest = rawArgs[1]
|
||||||
|
fallthrough
|
||||||
|
case 1:
|
||||||
|
args.target = rawArgs[0]
|
||||||
|
case 0:
|
||||||
|
args.target = filesys.SelfDir
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
153
kustomize/commands/localize/localize_test.go
Normal file
153
kustomize/commands/localize/localize_test.go
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
// Copyright 2022 The Kubernetes Authors.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package localize_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
loctest "sigs.k8s.io/kustomize/api/testutils/localizertest"
|
||||||
|
"sigs.k8s.io/kustomize/kustomize/v4/commands/localize"
|
||||||
|
)
|
||||||
|
|
||||||
|
const deployment = `apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: nginx-deployment
|
||||||
|
labels:
|
||||||
|
app: nginx
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: nginx
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: nginx
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: nginx:1.14.2
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestScopeFlag(t *testing.T) {
|
||||||
|
kustomizations := map[string]string{
|
||||||
|
filepath.Join("target", "kustomization.yaml"): fmt.Sprintf(`resources:
|
||||||
|
- %s
|
||||||
|
`, filepath.Join("..", "base")),
|
||||||
|
filepath.Join("base", "kustomization.yaml"): `resources:
|
||||||
|
- deployment.yaml
|
||||||
|
`,
|
||||||
|
filepath.Join("base", "deployment.yaml"): deployment,
|
||||||
|
}
|
||||||
|
expected, actual, testDir := loctest.PrepareFs(t, []string{
|
||||||
|
"target",
|
||||||
|
"base",
|
||||||
|
}, kustomizations)
|
||||||
|
|
||||||
|
cmd := localize.NewCmdLocalize(actual, new(bytes.Buffer))
|
||||||
|
require.NoError(t, cmd.Flags().Set("scope", testDir.String()))
|
||||||
|
err := cmd.RunE(cmd, []string{
|
||||||
|
testDir.Join("target"),
|
||||||
|
testDir.Join("dst"),
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
loctest.SetupDir(t, expected, testDir.Join("dst"), kustomizations)
|
||||||
|
loctest.CheckFs(t, testDir.String(), expected, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOptionalArgs(t *testing.T) {
|
||||||
|
for name, args := range map[string][]string{
|
||||||
|
"no_target": {},
|
||||||
|
"no_dst": {"."},
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
kust := map[string]string{
|
||||||
|
"kustomization.yaml": `resources:
|
||||||
|
- deployment.yaml
|
||||||
|
`,
|
||||||
|
"deployment.yaml": deployment,
|
||||||
|
}
|
||||||
|
expected, actual, testDir := loctest.PrepareFs(t, []string{
|
||||||
|
"target",
|
||||||
|
}, nil)
|
||||||
|
target := testDir.Join("target")
|
||||||
|
loctest.SetupDir(t, actual, target, kust)
|
||||||
|
loctest.SetWorkingDir(t, target)
|
||||||
|
|
||||||
|
buffy := new(bytes.Buffer)
|
||||||
|
cmd := localize.NewCmdLocalize(actual, buffy)
|
||||||
|
err := cmd.RunE(cmd, args)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
loctest.SetupDir(t, expected, target, kust)
|
||||||
|
dst := filepath.Join(target, "localized-target")
|
||||||
|
loctest.SetupDir(t, expected, dst, kust)
|
||||||
|
loctest.CheckFs(t, testDir.String(), expected, actual)
|
||||||
|
|
||||||
|
successMsg := fmt.Sprintf(`SUCCESS: localized "." to directory %s
|
||||||
|
`, dst)
|
||||||
|
require.Equal(t, successMsg, buffy.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOutput(t *testing.T) {
|
||||||
|
kustomization := map[string]string{
|
||||||
|
"kustomization.yaml": `namePrefix: test-
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
expected, actual, target := loctest.PrepareFs(t, nil, kustomization)
|
||||||
|
|
||||||
|
buffy := new(bytes.Buffer)
|
||||||
|
cmd := localize.NewCmdLocalize(actual, buffy)
|
||||||
|
err := cmd.RunE(cmd, []string{
|
||||||
|
target.String(),
|
||||||
|
target.Join("dst"),
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
loctest.SetupDir(t, expected, target.Join("dst"), kustomization)
|
||||||
|
loctest.CheckFs(t, target.String(), expected, actual)
|
||||||
|
|
||||||
|
successMsg := fmt.Sprintf(`SUCCESS: localized "%s" to directory %s
|
||||||
|
`, target.String(), target.Join("dst"))
|
||||||
|
require.Equal(t, successMsg, buffy.String())
|
||||||
|
|
||||||
|
const msg = "Check that cmd log output is hooked to buffy."
|
||||||
|
log.Print(msg)
|
||||||
|
require.Contains(t, buffy.String(), msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlpha(t *testing.T) {
|
||||||
|
_, actual, _ := loctest.PrepareFs(t, nil, map[string]string{
|
||||||
|
"kustomization.yaml": `namePrefix: test-`,
|
||||||
|
})
|
||||||
|
|
||||||
|
cmd := localize.NewCmdLocalize(actual, new(bytes.Buffer))
|
||||||
|
require.Contains(t, cmd.Short, "[Alpha]")
|
||||||
|
require.Contains(t, cmd.Long, "[Alpha]")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTooManyArgs(t *testing.T) {
|
||||||
|
_, actual, target := loctest.PrepareFs(t, nil, map[string]string{
|
||||||
|
"kustomization.yaml": `namePrefix: test-`,
|
||||||
|
})
|
||||||
|
|
||||||
|
cmd := localize.NewCmdLocalize(actual, new(bytes.Buffer))
|
||||||
|
err := cmd.Args(cmd, []string{
|
||||||
|
target.String(),
|
||||||
|
target.Join("dst"),
|
||||||
|
target.String(),
|
||||||
|
})
|
||||||
|
require.EqualError(t, err, "accepts at most 2 arg(s), received 3")
|
||||||
|
}
|
||||||
@@ -4,30 +4,83 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sigs.k8s.io/kustomize/api/provenance"
|
"sigs.k8s.io/kustomize/api/provenance"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
Short bool
|
||||||
|
Output string
|
||||||
|
Writer io.Writer
|
||||||
|
}
|
||||||
|
|
||||||
// NewCmdVersion makes a new version command.
|
// NewCmdVersion makes a new version command.
|
||||||
func NewCmdVersion(w io.Writer) *cobra.Command {
|
func NewCmdVersion(w io.Writer) *cobra.Command {
|
||||||
var short bool
|
o := NewOptions(w)
|
||||||
|
|
||||||
versionCmd := cobra.Command{
|
versionCmd := cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Prints the kustomize version",
|
Short: "Prints the kustomize version",
|
||||||
Example: `kustomize version`,
|
Example: `kustomize version`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if short {
|
if err := o.Validate(args); err != nil {
|
||||||
fmt.Fprintln(w, provenance.GetProvenance().Short())
|
return err
|
||||||
} else {
|
|
||||||
fmt.Fprintln(w, provenance.GetProvenance().Full())
|
|
||||||
}
|
}
|
||||||
|
if err := o.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
versionCmd.Flags().BoolVar(&short, "short", false, "short form")
|
versionCmd.Flags().BoolVar(&o.Short, "short", false, "short form")
|
||||||
|
_ = versionCmd.Flags().MarkDeprecated("short", "and will be removed in the future.")
|
||||||
|
versionCmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "One of 'yaml' or 'json'.")
|
||||||
return &versionCmd
|
return &versionCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewOptions(w io.Writer) *Options {
|
||||||
|
if w == nil {
|
||||||
|
w = io.Writer(os.Stdout)
|
||||||
|
}
|
||||||
|
return &Options{Writer: w}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Options) Validate(_ []string) error {
|
||||||
|
if o.Short {
|
||||||
|
if o.Output != "" {
|
||||||
|
return fmt.Errorf("--short and --output are mutually exclusive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Options) Run() error {
|
||||||
|
switch o.Output {
|
||||||
|
case "":
|
||||||
|
if o.Short {
|
||||||
|
fmt.Fprintln(o.Writer, provenance.GetProvenance().Short())
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(o.Writer, provenance.GetProvenance().Semver())
|
||||||
|
}
|
||||||
|
case "yaml":
|
||||||
|
marshalled, err := yaml.Marshal(provenance.GetProvenance())
|
||||||
|
if err != nil {
|
||||||
|
return errors.WrapPrefixf(err, "marshalling provenance to yaml")
|
||||||
|
}
|
||||||
|
fmt.Fprintln(o.Writer, string(marshalled))
|
||||||
|
case "json":
|
||||||
|
marshalled, err := json.MarshalIndent(provenance.GetProvenance(), "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return errors.WrapPrefixf(err, "marshalling provenance to json")
|
||||||
|
}
|
||||||
|
fmt.Fprintln(o.Writer, string(marshalled))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,13 +9,12 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.1
|
||||||
golang.org/x/text v0.6.0
|
golang.org/x/text v0.6.0
|
||||||
sigs.k8s.io/kustomize/api v0.12.1
|
sigs.k8s.io/kustomize/api v0.12.1
|
||||||
sigs.k8s.io/kustomize/cmd/config v0.10.9
|
sigs.k8s.io/kustomize/cmd/config v0.11.0
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
|
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
|
||||||
github.com/go-errors/errors v1.4.2 // indirect
|
github.com/go-errors/errors v1.4.2 // indirect
|
||||||
@@ -30,10 +29,7 @@ require (
|
|||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.7 // indirect
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
|
||||||
github.com/olekukonko/tablewriter v0.0.4 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/xlab/treeprint v1.1.0 // indirect
|
github.com/xlab/treeprint v1.1.0 // indirect
|
||||||
@@ -44,5 +40,8 @@ require (
|
|||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 // indirect
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 // indirect
|
||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace sigs.k8s.io/kustomize/api => ../api
|
||||||
|
|
||||||
|
replace sigs.k8s.io/kustomize/cmd/config => ../cmd/config
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
|
|
||||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||||
@@ -19,7 +17,6 @@ github.com/evanphx/json-patch v4.11.0+incompatible h1:glyUF9yIYtMHzn8xaKw5rMhdWc
|
|||||||
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
|
|
||||||
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
|
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
|
||||||
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
|
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
|
||||||
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
|
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
|
||||||
@@ -51,7 +48,6 @@ github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
|
|||||||
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
|
||||||
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
|
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
|
||||||
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.6/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=
|
||||||
@@ -67,14 +63,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
|||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
|
||||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
|
||||||
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
|
||||||
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
|
|
||||||
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
|
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
@@ -82,7 +72,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||||
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
|
||||||
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
|
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
|
||||||
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
|
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
@@ -92,7 +81,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
@@ -167,16 +155,9 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/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-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
|
||||||
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
|
||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 h1:HNSDgDCrr/6Ly3WEGKZftiE7IY19Vz2GdbOCyI4qqhc=
|
sigs.k8s.io/kustomize/kyaml v0.14.0 h1:uzH0MzMtYypHW09LbMDk8k/lT/LSsUuCoZIuEGhIBNE=
|
||||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
sigs.k8s.io/kustomize/kyaml v0.14.0/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
|
||||||
sigs.k8s.io/kustomize/api v0.12.1 h1:7YM7gW3kYBwtKvoY216ZzY+8hM+lV53LUayghNRJ0vM=
|
|
||||||
sigs.k8s.io/kustomize/api v0.12.1/go.mod h1:y3JUhimkZkR6sbLNwfJHxvo1TCLwuwm14sCYnkH6S1s=
|
|
||||||
sigs.k8s.io/kustomize/cmd/config v0.10.9 h1:LV8AUwZPuvqhGfia50uNwsPwNg1xOy9koEf5hyBnYs4=
|
|
||||||
sigs.k8s.io/kustomize/cmd/config v0.10.9/go.mod h1:T0s850zPV3wKfBALA0dyeP/K74jlJcoP8Pr9ZWwE3MQ=
|
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk=
|
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4=
|
|
||||||
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
|
||||||
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
"sigs.k8s.io/kustomize/kyaml/sets"
|
"sigs.k8s.io/kustomize/kyaml/sets"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyDir copies a src directory to a dst directory. CopyDir skips copying the .git directory from the src.
|
// CopyDir copies a src directory to a dst directory. CopyDir skips copying the .git directory from the src.
|
||||||
func CopyDir(src string, dst string) error {
|
func CopyDir(fSys filesys.FileSystem, src string, dst string) error {
|
||||||
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
return errors.Wrap(fSys.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -36,21 +38,21 @@ func CopyDir(src string, dst string) error {
|
|||||||
|
|
||||||
// make directories that don't exist
|
// make directories that don't exist
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
return os.MkdirAll(filepath.Join(dst, copyTo), info.Mode())
|
return errors.Wrap(fSys.MkdirAll(filepath.Join(dst, copyTo)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy file by reading and writing it
|
// copy file by reading and writing it
|
||||||
b, err := os.ReadFile(filepath.Join(src, copyTo))
|
b, err := fSys.ReadFile(filepath.Join(src, copyTo))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err)
|
||||||
}
|
}
|
||||||
err = os.WriteFile(filepath.Join(dst, copyTo), b, info.Mode())
|
err = fSys.WriteFile(filepath.Join(dst, copyTo), b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diff returns a list of files that differ between the source and destination.
|
// Diff returns a list of files that differ between the source and destination.
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
. "sigs.k8s.io/kustomize/kyaml/copyutil"
|
. "sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestDiff_identical verifies identical directories return an empty set
|
// TestDiff_identical verifies identical directories return an empty set
|
||||||
@@ -306,7 +307,7 @@ func TestCopyDir(t *testing.T) {
|
|||||||
|
|
||||||
d := t.TempDir()
|
d := t.TempDir()
|
||||||
|
|
||||||
err = CopyDir(s, d)
|
err = CopyDir(filesys.MakeFsOnDisk(), s, d)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
diff, err := Diff(d, v)
|
diff, err := Diff(d, v)
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/kyaml/testutil"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio/filters"
|
"sigs.k8s.io/kustomize/kyaml/kio/filters"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMerge3_Merge(t *testing.T) {
|
func TestMerge3_Merge(t *testing.T) {
|
||||||
@@ -29,6 +29,7 @@ func TestMerge3_Merge(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
if !assert.NoError(t, copyutil.CopyDir(
|
if !assert.NoError(t, copyutil.CopyDir(
|
||||||
|
filesys.MakeFsOnDisk(),
|
||||||
filepath.Join(datadir, "dataset1-localupdates"),
|
filepath.Join(datadir, "dataset1-localupdates"),
|
||||||
filepath.Join(dir, "dataset1"))) {
|
filepath.Join(dir, "dataset1"))) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@@ -71,6 +72,7 @@ func TestMerge3_Merge_path(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
if !assert.NoError(t, copyutil.CopyDir(
|
if !assert.NoError(t, copyutil.CopyDir(
|
||||||
|
filesys.MakeFsOnDisk(),
|
||||||
filepath.Join(datadir, "dataset1-localupdates"),
|
filepath.Join(datadir, "dataset1-localupdates"),
|
||||||
filepath.Join(dir, "dataset1"))) {
|
filepath.Join(dir, "dataset1"))) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
@@ -112,6 +114,7 @@ func TestMerge3_Merge_fail(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
|
|
||||||
if !assert.NoError(t, copyutil.CopyDir(
|
if !assert.NoError(t, copyutil.CopyDir(
|
||||||
|
filesys.MakeFsOnDisk(),
|
||||||
filepath.Join(datadir, "dataset1-localupdates"),
|
filepath.Join(datadir, "dataset1-localupdates"),
|
||||||
filepath.Join(dir, "dataset1"))) {
|
filepath.Join(dir, "dataset1"))) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
"sigs.k8s.io/kustomize/kyaml/fn/runtime/container"
|
"sigs.k8s.io/kustomize/kyaml/fn/runtime/container"
|
||||||
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
|
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
@@ -1272,7 +1272,7 @@ func setupTest(t *testing.T) string {
|
|||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
if !assert.NoError(t, copyutil.CopyDir(ds, dir)) {
|
if !assert.NoError(t, copyutil.CopyDir(filesys.MakeFsOnDisk(), ds, dir)) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"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/errors"
|
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -92,12 +93,20 @@ func (p *plugin) validateArgs() (err error) {
|
|||||||
p.ChartHome = types.HelmDefaultHome
|
p.ChartHome = types.HelmDefaultHome
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ValuesFile may be consulted by the plugin, so it must
|
// The ValuesFile(s) may be consulted by the plugin, so it must
|
||||||
// be under the loader root (unless root restrictions are
|
// be under the loader root (unless root restrictions are
|
||||||
// disabled).
|
// disabled).
|
||||||
if p.ValuesFile == "" {
|
if p.ValuesFile == "" {
|
||||||
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
|
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
|
||||||
}
|
}
|
||||||
|
for i, file := range p.AdditionalValuesFiles {
|
||||||
|
// use Load() to enforce root restrictions
|
||||||
|
if _, err := p.h.Loader().Load(file); err != nil {
|
||||||
|
return errors.WrapPrefixf(err, "could not load additionalValuesFile")
|
||||||
|
}
|
||||||
|
// the additional values filepaths must be relative to the kust root
|
||||||
|
p.AdditionalValuesFiles[i] = filepath.Join(p.h.Loader().Root(), file)
|
||||||
|
}
|
||||||
|
|
||||||
if err = p.errIfIllegalValuesMerge(); err != nil {
|
if err = p.errIfIllegalValuesMerge(); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -246,49 +255,28 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var stdout []byte
|
var stdout []byte
|
||||||
stdout, err = p.runHelmCommand(p.templateCommand())
|
stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rm, err = p.h.ResmapFactory().NewResMapFromBytes(stdout)
|
rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout)
|
||||||
if err == nil {
|
if resMapErr == nil {
|
||||||
return rm, nil
|
return rm, nil
|
||||||
}
|
}
|
||||||
// try to remove the contents before first "---" because
|
// try to remove the contents before first "---" because
|
||||||
// helm may produce messages to stdout before it
|
// helm may produce messages to stdout before it
|
||||||
stdoutStr := string(stdout)
|
r := &kio.ByteReader{Reader: bytes.NewBufferString(string(stdout)), OmitReaderAnnotations: true}
|
||||||
if idx := strings.Index(stdoutStr, "\n---\n"); idx != -1 {
|
nodes, err := r.Read()
|
||||||
return p.h.ResmapFactory().NewResMapFromBytes([]byte(stdoutStr[idx:]))
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *plugin) templateCommand() []string {
|
if len(nodes) != 0 {
|
||||||
args := []string{"template"}
|
rm, err = p.h.ResmapFactory().NewResMapFromRNodeSlice(nodes)
|
||||||
if p.ReleaseName != "" {
|
if err != nil {
|
||||||
args = append(args, p.ReleaseName)
|
return nil, fmt.Errorf("could not parse rnode slice into resource map: %w\n", err)
|
||||||
|
}
|
||||||
|
return rm, nil
|
||||||
}
|
}
|
||||||
if p.Namespace != "" {
|
return nil, fmt.Errorf("could not parse bytes into resource map: %w\n", resMapErr)
|
||||||
args = append(args, "--namespace", p.Namespace)
|
|
||||||
}
|
|
||||||
args = append(args, filepath.Join(p.absChartHome(), p.Name))
|
|
||||||
if p.ValuesFile != "" {
|
|
||||||
args = append(args, "--values", p.ValuesFile)
|
|
||||||
}
|
|
||||||
if p.ReleaseName == "" {
|
|
||||||
// AFAICT, this doesn't work as intended due to a bug in helm.
|
|
||||||
// See https://github.com/helm/helm/issues/6019
|
|
||||||
// I've tried placing the flag before and after the name argument.
|
|
||||||
args = append(args, "--generate-name")
|
|
||||||
}
|
|
||||||
if p.IncludeCRDs {
|
|
||||||
args = append(args, "--include-crds")
|
|
||||||
}
|
|
||||||
if p.SkipHooks {
|
|
||||||
args = append(args, "--no-hooks")
|
|
||||||
}
|
|
||||||
return args
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *plugin) pullCommand() []string {
|
func (p *plugin) pullCommand() []string {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
github.com/evanphx/json-patch v4.11.0+incompatible
|
github.com/evanphx/json-patch v4.11.0+incompatible
|
||||||
sigs.k8s.io/kustomize/api v0.11.5
|
sigs.k8s.io/kustomize/api v0.11.5
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
github.com/evanphx/json-patch v4.11.0+incompatible
|
github.com/evanphx/json-patch v4.11.0+incompatible
|
||||||
sigs.k8s.io/kustomize/api v0.11.5
|
sigs.k8s.io/kustomize/api v0.11.5
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ go 1.19
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
sigs.k8s.io/kustomize/api v0.11.5
|
sigs.k8s.io/kustomize/api v0.11.5
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ go 1.19
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
sigs.k8s.io/kustomize/api v0.11.5
|
sigs.k8s.io/kustomize/api v0.11.5
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
sigs.k8s.io/yaml v1.3.0
|
sigs.k8s.io/yaml v1.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ go 1.19
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
sigs.k8s.io/kustomize/api v0.11.5
|
sigs.k8s.io/kustomize/api v0.11.5
|
||||||
sigs.k8s.io/kustomize/kyaml v0.13.9
|
sigs.k8s.io/kustomize/kyaml v0.14.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ steps:
|
|||||||
entrypoint: /bin/bash
|
entrypoint: /bin/bash
|
||||||
dir: myClone
|
dir: myClone
|
||||||
secretEnv: ['GITHUB_TOKEN']
|
secretEnv: ['GITHUB_TOKEN']
|
||||||
|
env:
|
||||||
|
- 'GITHUB_USERNAME=KnVerey' # used to make authenticated curl requests to Github in releasing/compile-changelog.sh
|
||||||
args:
|
args:
|
||||||
- releasing/cloudbuild.sh
|
- releasing/cloudbuild.sh
|
||||||
- $TAG_NAME
|
- $TAG_NAME
|
||||||
@@ -59,6 +61,7 @@ timeout: 14m
|
|||||||
# The base64 of that is shown below. It's decrypted by cloud build
|
# The base64 of that is shown below. It's decrypted by cloud build
|
||||||
# and provided back to goreleaser.
|
# and provided back to goreleaser.
|
||||||
# IMPORTANT: make sure the token does not end with a newline when you encrypt it!
|
# IMPORTANT: make sure the token does not end with a newline when you encrypt it!
|
||||||
|
# IMPORTANT: update the GITHUB_USERNAME env var above to match the github user whose token this is
|
||||||
secrets:
|
secrets:
|
||||||
- kmsKeyName: projects/k8s-staging-kustomize/locations/global/keyRings/kust-cloud-key-ring/cryptoKeys/kust-cloud-key-name
|
- kmsKeyName: projects/k8s-staging-kustomize/locations/global/keyRings/kust-cloud-key-ring/cryptoKeys/kust-cloud-key-name
|
||||||
secretEnv:
|
secretEnv:
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ if [[ -z "${1-}" ]] || [[ -z "${2-}" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${GITHUB_USERNAME-}" ]] || [[ -z "${GITHUB_TOKEN-}" ]]; then
|
||||||
|
echo "WARNING: Please set GITHUB_USERNAME and GITHUB_TOKEN to avoid GitHub API rate limits."
|
||||||
|
github_auth_string=""
|
||||||
|
else
|
||||||
|
github_auth_string="-u ${GITHUB_USERNAME}:${GITHUB_TOKEN}"
|
||||||
|
fi
|
||||||
|
|
||||||
module=$1
|
module=$1
|
||||||
fullTag=$2
|
fullTag=$2
|
||||||
changeLogFile="${3:-}"
|
changeLogFile="${3:-}"
|
||||||
@@ -49,10 +56,21 @@ results=""
|
|||||||
for((i=0; i < ${#commits[@]}; i+=batchSize))
|
for((i=0; i < ${#commits[@]}; i+=batchSize))
|
||||||
do
|
do
|
||||||
commitList=$(IFS="+"; echo "${commits[@]:i:batchSize}" | sed 's/ /+/g')
|
commitList=$(IFS="+"; echo "${commits[@]:i:batchSize}" | sed 's/ /+/g')
|
||||||
if newResults=$(curl -sSL "https://api.github.com/search/issues?q=$commitList+repo%3Akubernetes-sigs%2Fkustomize" | jq -r '[ .items[] | { number, title } ]'); then
|
|
||||||
|
if ! newResultsRaw=$(curl -sSL "https://api.github.com/search/issues?q=$commitList+repo%3Akubernetes-sigs%2Fkustomize+is:pull-request" $github_auth_string); then
|
||||||
|
echo "Failed to fetch results for commits (exit code $?): $commitList"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ "${newResultsRaw}" == *"API rate limit exceeded"* ]]; then
|
||||||
|
echo "GitHub API rate limit exceeded. Please set GITHUB_USERNAME and GITHUB_TOKEN to avoid this."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${newResultsRaw}" == *"\"items\":"* ]] ; then
|
||||||
|
newResults=$(echo "$newResultsRaw" | jq -r '[ .items[] | { number, title } ]')
|
||||||
results=$(echo "$results" "$newResults" | jq -s '.[0] + .[1] | unique')
|
results=$(echo "$results" "$newResults" | jq -s '.[0] + .[1] | unique')
|
||||||
else
|
else
|
||||||
echo "Failed to fetch results for commits (exit code $?): $commitList"
|
echo "Request for commits $commitList returned invalid results"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ builds:
|
|||||||
ldflags: >
|
ldflags: >
|
||||||
-s
|
-s
|
||||||
-X sigs.k8s.io/kustomize/api/provenance.version={{.Version}}
|
-X sigs.k8s.io/kustomize/api/provenance.version={{.Version}}
|
||||||
-X sigs.k8s.io/kustomize/api/provenance.gitCommit={{.Commit}}
|
|
||||||
-X sigs.k8s.io/kustomize/api/provenance.buildDate={{.Date}}
|
-X sigs.k8s.io/kustomize/api/provenance.buildDate={{.Date}}
|
||||||
|
|
||||||
goos:
|
goos:
|
||||||
|
|||||||
Reference in New Issue
Block a user