mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 10:15:22 +00:00
Merge pull request #4560 from KnVerey/go1.18-tools
Update and re-enable linters
This commit is contained in:
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@@ -20,7 +20,9 @@ jobs:
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Lint
|
||||
run: ./hack/kyaml-pre-commit.sh
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
run:
|
||||
deadline: 5m
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
# - dogsled
|
||||
- dupl
|
||||
# - errcheck
|
||||
# - funlen
|
||||
# - gochecknoinits
|
||||
- goconst
|
||||
# - gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
- golint
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- lll
|
||||
- misspell
|
||||
- nakedret
|
||||
# - scopelint
|
||||
- staticcheck
|
||||
- structcheck
|
||||
# stylecheck demands that acronyms not be treated as words
|
||||
# in camelCase, so JsonOp become JSONOp, etc. Yuck.
|
||||
# - stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
# - whitespace
|
||||
|
||||
linters-settings:
|
||||
dupl:
|
||||
threshold: 400
|
||||
lll:
|
||||
line-length: 170
|
||||
gocyclo:
|
||||
min-complexity: 15
|
||||
golint:
|
||||
min-confidence: 0.85
|
||||
123
.golangci.yml
Normal file
123
.golangci.yml
Normal file
@@ -0,0 +1,123 @@
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
run:
|
||||
deadline: 5m
|
||||
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
disable-all: true
|
||||
enable:
|
||||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
- contextcheck
|
||||
# - cyclop
|
||||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
- dupl
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errname
|
||||
- errorlint
|
||||
- exhaustive
|
||||
# - exhaustivestruct
|
||||
- exportloopref
|
||||
# - forbidigo
|
||||
- forcetypeassert
|
||||
# - funlen
|
||||
# - gci
|
||||
- gochecknoglobals
|
||||
- gochecknoinits
|
||||
# - gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
# - godot
|
||||
# - godox
|
||||
- goerr113
|
||||
- gofmt
|
||||
# - gofumpt
|
||||
- goheader
|
||||
- goimports
|
||||
- gomnd
|
||||
- gomoddirectives
|
||||
- gomodguard
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- gosimple
|
||||
- govet
|
||||
# - ifshort # too many false positives
|
||||
- importas
|
||||
- ineffassign
|
||||
# - ireturn
|
||||
- lll
|
||||
- makezero
|
||||
- misspell
|
||||
- nakedret
|
||||
- nestif
|
||||
- nilerr
|
||||
# - nilnil
|
||||
# - nlreturn
|
||||
# - noctx
|
||||
- nolintlint
|
||||
# - paralleltest
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- revive
|
||||
- rowserrcheck
|
||||
- sqlclosecheck
|
||||
- staticcheck
|
||||
- structcheck
|
||||
# - stylecheck
|
||||
- tagliatelle
|
||||
- tenv
|
||||
- testpackage
|
||||
- thelper
|
||||
- tparallel
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
# - varnamelen
|
||||
- wastedassign
|
||||
- whitespace
|
||||
- wrapcheck
|
||||
# - wsl
|
||||
|
||||
linters-settings:
|
||||
dupl:
|
||||
threshold: 400
|
||||
lll:
|
||||
line-length: 170
|
||||
gocyclo:
|
||||
min-complexity: 30
|
||||
revive:
|
||||
rules:
|
||||
- name: var-naming
|
||||
arguments:
|
||||
- [ "ID", "API", "JSON" ] # AllowList
|
||||
- [ ] # DenyList
|
||||
gomoddirectives:
|
||||
replace-local: true
|
||||
gosec:
|
||||
config:
|
||||
G306: "0644"
|
||||
gomnd:
|
||||
ignored-functions:
|
||||
- ioutil.WriteFile
|
||||
|
||||
issues:
|
||||
new-from-rev: c94b5d8f2 # enables us to enforce a larger set of linters for new code than pass on existing code
|
||||
max-same-issues: 0
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- revive
|
||||
text: "don't use leading"
|
||||
- linters:
|
||||
- staticcheck
|
||||
text: "SA1019: kioutil.Legacy"
|
||||
15
Makefile
15
Makefile
@@ -55,17 +55,17 @@ verify-kustomize-e2e: test-examples-e2e-kustomize
|
||||
# This installs what kustomize wants to use.
|
||||
$(MYGOBIN)/golangci-lint-kustomize:
|
||||
rm -f $(CURDIR)/hack/golangci-lint
|
||||
GOBIN=$(CURDIR)/hack go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.8
|
||||
GOBIN=$(CURDIR)/hack go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
|
||||
mv $(CURDIR)/hack/golangci-lint $(MYGOBIN)/golangci-lint-kustomize
|
||||
|
||||
$(MYGOBIN)/mdrip:
|
||||
go install github.com/monopole/mdrip@v1.0.2
|
||||
|
||||
$(MYGOBIN)/stringer:
|
||||
go get golang.org/x/tools/cmd/stringer
|
||||
go install golang.org/x/tools/cmd/stringer@latest
|
||||
|
||||
$(MYGOBIN)/goimports:
|
||||
go get golang.org/x/tools/cmd/goimports
|
||||
go install golang.org/x/tools/cmd/goimports@latest
|
||||
|
||||
# Build from local source.
|
||||
$(MYGOBIN)/gorepomod:
|
||||
@@ -203,13 +203,16 @@ clean-kustomize-external-go-plugin:
|
||||
.PHONY: lint-kustomize
|
||||
lint-kustomize: $(MYGOBIN)/golangci-lint-kustomize $(builtinplugins)
|
||||
cd api; $(MYGOBIN)/golangci-lint-kustomize \
|
||||
-c ../.golangci-kustomize.yml \
|
||||
-c ../.golangci.yml \
|
||||
--path-prefix api \
|
||||
run ./...
|
||||
cd kustomize; $(MYGOBIN)/golangci-lint-kustomize \
|
||||
-c ../.golangci-kustomize.yml \
|
||||
-c ../.golangci.yml \
|
||||
--path-prefix kustomize \
|
||||
run ./...
|
||||
cd cmd/pluginator; $(MYGOBIN)/golangci-lint-kustomize \
|
||||
-c ../../.golangci-kustomize.yml \
|
||||
-c ../../.golangci.yml \
|
||||
--path-prefix cmd/pluginator \
|
||||
run ./...
|
||||
|
||||
# Used to add non-default compilation flags when experimenting with
|
||||
|
||||
@@ -285,7 +285,7 @@ spec:
|
||||
t.Run(tn, func(t *testing.T) {
|
||||
filter := tc.filter
|
||||
filter.WithMutationTracker(tc.setEntryCallback)
|
||||
filter.FsSlice = append(annosFs, tc.fsslice...)
|
||||
filter.FsSlice = append(annosFs, tc.fsslice...) //nolint:gocritic
|
||||
if !assert.Equal(t,
|
||||
strings.TrimSpace(tc.expectedOutput),
|
||||
strings.TrimSpace(filtertest_test.RunFilter(t, tc.input, filter))) {
|
||||
|
||||
@@ -43,7 +43,7 @@ metadata:
|
||||
f.IAMPolicyGenerator.KubernetesService.Name)
|
||||
|
||||
if f.IAMPolicyGenerator.Namespace != "" {
|
||||
input = input + fmt.Sprintf("\n namespace: %s", f.IAMPolicyGenerator.Namespace)
|
||||
input += fmt.Sprintf("\n namespace: %s", f.IAMPolicyGenerator.Namespace)
|
||||
}
|
||||
|
||||
sa, err := yaml.Parse(input)
|
||||
|
||||
@@ -6,6 +6,7 @@ package imagetag
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/api/internal/utils"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
@@ -81,9 +82,7 @@ func (f findFieldsFilter) walk(node *yaml.RNode) error {
|
||||
return nil
|
||||
})
|
||||
case yaml.SequenceNode:
|
||||
return node.VisitElements(func(n *yaml.RNode) error {
|
||||
return f.walk(n)
|
||||
})
|
||||
return errors.Wrap(node.VisitElements(f.walk))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,13 +36,14 @@ func (u imageTagUpdater) SetImageValue(rn *yaml.RNode) error {
|
||||
}
|
||||
|
||||
// overriding tag or digest will replace both original tag and digest values
|
||||
if u.ImageTag.NewTag != "" && u.ImageTag.Digest != "" {
|
||||
switch {
|
||||
case u.ImageTag.NewTag != "" && u.ImageTag.Digest != "":
|
||||
tag = u.ImageTag.NewTag
|
||||
digest = u.ImageTag.Digest
|
||||
} else if u.ImageTag.NewTag != "" {
|
||||
case u.ImageTag.NewTag != "":
|
||||
tag = u.ImageTag.NewTag
|
||||
digest = ""
|
||||
} else if u.ImageTag.Digest != "" {
|
||||
case u.ImageTag.Digest != "":
|
||||
tag = ""
|
||||
digest = u.ImageTag.Digest
|
||||
}
|
||||
|
||||
@@ -139,7 +139,6 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, gvk resid.Gvk) error {
|
||||
}
|
||||
|
||||
return ns.trackableSetter.SetEntry("", ns.Namespace, yaml.NodeTagString)(node)
|
||||
|
||||
})
|
||||
|
||||
return err
|
||||
|
||||
@@ -406,7 +406,7 @@ func TestNamespace_Filter(t *testing.T) {
|
||||
test := tests[i]
|
||||
test.filter.WithMutationTracker(test.mutationTracker)
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
test.filter.FsSlice = append(config.NameSpace, test.fsslice...)
|
||||
test.filter.FsSlice = append(config.NameSpace, test.fsslice...) //nolint:gocritic
|
||||
if !assert.Equal(t,
|
||||
strings.TrimSpace(test.expected),
|
||||
strings.TrimSpace(
|
||||
|
||||
@@ -17,7 +17,6 @@ var makeMf = func(theMap map[string]interface{}) MappingFunc {
|
||||
}
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
|
||||
testCases := map[string]struct {
|
||||
input string
|
||||
expected string
|
||||
|
||||
@@ -20,11 +20,11 @@ type Filter struct {
|
||||
|
||||
// Filter replaces values of targets with values from sources
|
||||
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
for _, r := range f.Replacements {
|
||||
for i, r := range f.Replacements {
|
||||
if r.Source == nil || r.Targets == nil {
|
||||
return nil, fmt.Errorf("replacements must specify a source and at least one target")
|
||||
}
|
||||
value, err := getReplacement(nodes, &r)
|
||||
value, err := getReplacement(nodes, &f.Replacements[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,8 +60,8 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targets []*types.T
|
||||
}
|
||||
|
||||
// filter targets by matching resource IDs
|
||||
for _, id := range ids {
|
||||
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, &id) {
|
||||
for i, id := range ids {
|
||||
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, &ids[i]) {
|
||||
err := applyToNode(n, value, t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -604,8 +604,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
|
||||
@@ -341,6 +341,7 @@ data:
|
||||
// The return value indicates whether we should skip the rest of the test case
|
||||
// due to the error result.
|
||||
func SkipRest(t *testing.T, desc string, err error, contains string) bool {
|
||||
t.Helper()
|
||||
if err != nil {
|
||||
if len(contains) == 0 {
|
||||
t.Errorf("case %q, expect nil error but got %q", desc, err.Error())
|
||||
|
||||
@@ -113,7 +113,6 @@ func debug(fMap filterMap) {
|
||||
// 'spec/scaleTargetRef/name' field. Return a filter that can do that.
|
||||
func (t *nameReferenceTransformer) determineFilters(
|
||||
resources []*resource.Resource) (fMap filterMap) {
|
||||
|
||||
// We cache the resource OrgId values because they don't change and otherwise are very visible in a memory pprof
|
||||
resourceOrgIds := make([]resid.ResId, len(resources))
|
||||
for i, resource := range resources {
|
||||
|
||||
@@ -107,7 +107,6 @@ func (ra *ResAccumulator) findVarValueFromResources(v types.Var) (interface{}, e
|
||||
for _, res := range ra.resMap.Resources() {
|
||||
for _, varName := range res.GetRefVarNames() {
|
||||
if varName == v.Name {
|
||||
//nolint: staticcheck
|
||||
s, err := res.GetFieldValue(v.FieldRef.FieldPath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf(
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func makeResAccumulator(t *testing.T) *ResAccumulator {
|
||||
t.Helper()
|
||||
ra := MakeEmptyAccumulator()
|
||||
err := ra.MergeConfig(builtinconfig.MakeDefaultConfig())
|
||||
if err != nil {
|
||||
@@ -133,6 +134,7 @@ func TestResolveVarsOneUnused(t *testing.T) {
|
||||
}
|
||||
|
||||
func expectLog(t *testing.T, log bytes.Buffer, expect string) {
|
||||
t.Helper()
|
||||
if !strings.Contains(log.String(), expect) {
|
||||
t.Fatalf("expected log containing '%s', got '%s'", expect, log.String())
|
||||
}
|
||||
|
||||
@@ -78,15 +78,15 @@ func (x *RepoSpec) Cleaner(fSys filesys.FileSystem) func() error {
|
||||
return func() error { return fSys.RemoveAll(x.Dir.String()) }
|
||||
}
|
||||
|
||||
// NewRepoSpecFromUrl parses git-like urls.
|
||||
// NewRepoSpecFromURL parses git-like urls.
|
||||
// From strings like git@github.com:someOrg/someRepo.git or
|
||||
// https://github.com/someOrg/someRepo?ref=someHash, extract
|
||||
// the parts.
|
||||
func NewRepoSpecFromUrl(n string) (*RepoSpec, error) {
|
||||
func NewRepoSpecFromURL(n string) (*RepoSpec, error) {
|
||||
if filepath.IsAbs(n) {
|
||||
return nil, fmt.Errorf("uri looks like abs path: %s", n)
|
||||
}
|
||||
host, orgRepo, path, gitRef, gitSubmodules, suffix, gitTimeout := parseGitUrl(n)
|
||||
host, orgRepo, path, gitRef, gitSubmodules, suffix, gitTimeout := parseGitURL(n)
|
||||
if orgRepo == "" {
|
||||
return nil, fmt.Errorf("url lacks orgRepo: %s", n)
|
||||
}
|
||||
@@ -108,9 +108,8 @@ const (
|
||||
// From strings like git@github.com:someOrg/someRepo.git or
|
||||
// https://github.com/someOrg/someRepo?ref=someHash, extract
|
||||
// the parts.
|
||||
func parseGitUrl(n string) (
|
||||
func parseGitURL(n string) (
|
||||
host string, orgRepo string, path string, gitRef string, gitSubmodules bool, gitSuff string, gitTimeout time.Duration) {
|
||||
|
||||
if strings.Contains(n, gitDelimiter) {
|
||||
index := strings.Index(n, gitDelimiter)
|
||||
// Adding _git/ to host
|
||||
@@ -229,7 +228,7 @@ func parseHostSpec(n string) (string, string) {
|
||||
if strings.HasSuffix(host, p) {
|
||||
i := strings.Index(n, "/")
|
||||
if i > -1 {
|
||||
host = host + n[0:i+1]
|
||||
host += n[0 : i+1]
|
||||
n = n[i+1:]
|
||||
}
|
||||
break
|
||||
|
||||
@@ -37,7 +37,7 @@ var hostNamesRawAndNormalized = [][]string{
|
||||
{"git@github.com/", "git@github.com:"},
|
||||
}
|
||||
|
||||
func makeUrl(hostFmt, orgRepo, path, href string) string {
|
||||
func makeURL(hostFmt, orgRepo, path, href string) string {
|
||||
if len(path) > 0 {
|
||||
orgRepo = filepath.Join(orgRepo, path)
|
||||
}
|
||||
@@ -56,8 +56,8 @@ func TestNewRepoSpecFromUrl(t *testing.T) {
|
||||
for _, orgRepo := range orgRepos {
|
||||
for _, pathName := range pathNames {
|
||||
for _, hrefArg := range hrefArgs {
|
||||
uri := makeUrl(hostRaw, orgRepo, pathName, hrefArg)
|
||||
rs, err := NewRepoSpecFromUrl(uri)
|
||||
uri := makeURL(hostRaw, orgRepo, pathName, hrefArg)
|
||||
rs, err := NewRepoSpecFromURL(uri)
|
||||
if err != nil {
|
||||
t.Errorf("problem %v", err)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ var badData = [][]string{
|
||||
|
||||
func TestNewRepoSpecFromUrlErrors(t *testing.T) {
|
||||
for _, tuple := range badData {
|
||||
_, err := NewRepoSpecFromUrl(tuple[0])
|
||||
_, err := NewRepoSpecFromURL(tuple[0])
|
||||
if err == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func TestNewRepoSpecFromUrl_CloneSpecs(t *testing.T) {
|
||||
}
|
||||
for tn, tc := range testcases {
|
||||
t.Run(tn, func(t *testing.T) {
|
||||
rs, err := NewRepoSpecFromUrl(tc.input)
|
||||
rs, err := NewRepoSpecFromURL(tc.input)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.cloneSpec, rs.CloneSpec(), "cloneSpec mismatch")
|
||||
assert.Equal(t, tc.absPath, rs.AbsPath(), "absPath mismatch")
|
||||
|
||||
@@ -36,7 +36,7 @@ const (
|
||||
|
||||
var stringToBuiltinPluginTypeMap map[string]BuiltinPluginType
|
||||
|
||||
func init() {
|
||||
func init() { //nolint:gochecknoinits
|
||||
stringToBuiltinPluginTypeMap = makeStringToBuiltinPluginTypeMap()
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,6 @@ metadata:
|
||||
`
|
||||
if expected != string(p.Cfg()) {
|
||||
t.Fatalf("expected cfg '%s', got '%s'", expected, string(p.Cfg()))
|
||||
|
||||
}
|
||||
if len(p.Args()) != 6 {
|
||||
t.Fatalf("unexpected arg len %d, %#v", len(p.Args()), p.Args())
|
||||
|
||||
@@ -105,10 +105,10 @@ func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {
|
||||
"TrUe",
|
||||
"potato",
|
||||
}
|
||||
for i, c := range cases {
|
||||
for i := range cases {
|
||||
name := fmt.Sprintf("test%d", i)
|
||||
in := resmap.New()
|
||||
err := in.Append(makeConfigMap(rf, name, "", &c))
|
||||
err := in.Append(makeConfigMap(rf, name, "", &cases[i]))
|
||||
require.NoError(t, err)
|
||||
_, err = UpdateResourceOptions(in)
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -20,6 +20,7 @@ func makeAndLoadKustTarget(
|
||||
t *testing.T,
|
||||
fSys filesys.FileSystem,
|
||||
root string) *target.KustTarget {
|
||||
t.Helper()
|
||||
kt := makeKustTargetWithRf(t, fSys, root, provider.NewDefaultDepProvider())
|
||||
if err := kt.Load(); err != nil {
|
||||
t.Fatalf("Unexpected load error %v", err)
|
||||
@@ -32,6 +33,7 @@ func makeKustTargetWithRf(
|
||||
fSys filesys.FileSystem,
|
||||
root string,
|
||||
pvd *provider.DepProvider) *target.KustTarget {
|
||||
t.Helper()
|
||||
ldr, err := fLdr.NewLoader(fLdr.RestrictionRootOnly, root, fSys)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -179,9 +179,11 @@ func TestDefaultAbsPluginHomeNoXdgJustHomeDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func setenv(t *testing.T, key, value string) {
|
||||
t.Helper()
|
||||
require.NoError(t, os.Setenv(key, value))
|
||||
}
|
||||
|
||||
func unsetenv(t *testing.T, key string) {
|
||||
t.Helper()
|
||||
require.NoError(t, os.Unsetenv(key))
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ spec:
|
||||
`)
|
||||
}
|
||||
|
||||
//test for https://github.com/kubernetes-sigs/kustomize/issues/3812#issuecomment-862339267
|
||||
// test for https://github.com/kubernetes-sigs/kustomize/issues/3812#issuecomment-862339267
|
||||
func TestBasicIO3812(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK(".", `
|
||||
|
||||
@@ -460,7 +460,6 @@ metadata:
|
||||
}
|
||||
|
||||
func TestConfigMapGeneratorMergeNamePrefix(t *testing.T) {
|
||||
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("base", `
|
||||
configMapGenerator:
|
||||
|
||||
@@ -34,7 +34,7 @@ const container = `{ "image": "my-image", "livenessProbe": { "httpGet" : {"path"
|
||||
const patchJsonAddProbe = `[{"op": "replace", "path": "/spec/template/spec/containers/0", "value": ` +
|
||||
container + `}]`
|
||||
|
||||
const patchDnsPolicy = `
|
||||
const patchDNSPolicy = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
@@ -44,7 +44,7 @@ spec:
|
||||
spec:
|
||||
dnsPolicy: ClusterFirst
|
||||
`
|
||||
const patchJsonDnsPolicy = `[{"op": "add", "path": "/spec/template/spec/dnsPolicy", "value": "ClusterFirst"}]`
|
||||
const patchJsonDNSPolicy = `[{"op": "add", "path": "/spec/template/spec/dnsPolicy", "value": "ClusterFirst"}]`
|
||||
|
||||
const patchRestartPolicy = `
|
||||
apiVersion: apps/v1
|
||||
@@ -96,7 +96,7 @@ resources:
|
||||
patchesStrategicMerge:
|
||||
- dep-patch.yaml
|
||||
`)
|
||||
th.WriteF("dns/dep-patch.yaml", patchDnsPolicy)
|
||||
th.WriteF("dns/dep-patch.yaml", patchDNSPolicy)
|
||||
}
|
||||
|
||||
func writeRestartOverlay(th kusttest_test.Harness) {
|
||||
@@ -209,7 +209,7 @@ patchesStrategicMerge:
|
||||
- patchRestartPolicy.yaml
|
||||
`)
|
||||
th.WriteF("composite/patchRestartPolicy.yaml", patchRestartPolicy)
|
||||
th.WriteF("composite/patchDnsPolicy.yaml", patchDnsPolicy)
|
||||
th.WriteF("composite/patchDnsPolicy.yaml", patchDNSPolicy)
|
||||
th.WriteF("composite/patchAddProbe.yaml", patchAddProbe)
|
||||
|
||||
m := th.Run("composite", th.MakeDefaultOptions())
|
||||
@@ -220,7 +220,7 @@ func definePatchDirStructure(th kusttest_test.Harness) {
|
||||
writeDeploymentBase(th)
|
||||
|
||||
th.WriteF("patches/patchRestartPolicy.yaml", patchRestartPolicy)
|
||||
th.WriteF("patches/patchDnsPolicy.yaml", patchDnsPolicy)
|
||||
th.WriteF("patches/patchDnsPolicy.yaml", patchDNSPolicy)
|
||||
th.WriteF("patches/patchAddProbe.yaml", patchAddProbe)
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ func TestIssue1251_Plugins_Local(t *testing.T) {
|
||||
writeDeploymentBase(th.Harness)
|
||||
|
||||
writeJsonTransformerPluginConfig(
|
||||
th, "composite", "addDnsPolicy", patchJsonDnsPolicy)
|
||||
th, "composite", "addDnsPolicy", patchJsonDNSPolicy)
|
||||
writeJsonTransformerPluginConfig(
|
||||
th, "composite", "addRestartPolicy", patchJsonRestartPolicy)
|
||||
writeJsonTransformerPluginConfig(
|
||||
@@ -417,7 +417,7 @@ resources:
|
||||
- addProbeConfig.yaml
|
||||
`)
|
||||
writeJsonTransformerPluginConfig(
|
||||
th, "patches", "addDnsPolicy", patchJsonDnsPolicy)
|
||||
th, "patches", "addDnsPolicy", patchJsonDNSPolicy)
|
||||
writeJsonTransformerPluginConfig(
|
||||
th, "patches", "addRestartPolicy", patchJsonRestartPolicy)
|
||||
writeJsonTransformerPluginConfig(
|
||||
@@ -441,7 +441,7 @@ resources:
|
||||
- addDnsPolicyConfig.yaml
|
||||
`)
|
||||
writeJsonTransformerPluginConfig(
|
||||
th, "patches/addDnsPolicy", "addDnsPolicy", patchJsonDnsPolicy)
|
||||
th, "patches/addDnsPolicy", "addDnsPolicy", patchJsonDNSPolicy)
|
||||
|
||||
th.WriteK("patches/addRestartPolicy", `
|
||||
resources:
|
||||
|
||||
@@ -82,21 +82,19 @@ metadata:
|
||||
secret := findSecret(m, "")
|
||||
if secret == nil {
|
||||
t.Errorf("Expected to find a Secret")
|
||||
}
|
||||
if secret.GetName() != "foo-secret-bar-82c2g5f8f6" {
|
||||
} else if secret.GetName() != "foo-secret-bar-82c2g5f8f6" {
|
||||
t.Errorf("unexpected secret resource name: %s", secret.GetName())
|
||||
}
|
||||
|
||||
th.WriteK("/whatever",
|
||||
strings.Replace(kustomizationContent,
|
||||
strings.ReplaceAll(kustomizationContent,
|
||||
"disableNameSuffixHash: false",
|
||||
"disableNameSuffixHash: true", -1))
|
||||
"disableNameSuffixHash: true"))
|
||||
m = th.Run("/whatever", th.MakeDefaultOptions())
|
||||
secret = findSecret(m, "")
|
||||
if secret == nil {
|
||||
t.Errorf("Expected to find a Secret")
|
||||
}
|
||||
if secret.GetName() != "foo-secret-bar" { // No hash at end.
|
||||
} else if secret.GetName() != "foo-secret-bar" { // No hash at end.
|
||||
t.Errorf("unexpected secret resource name: %s", secret.GetName())
|
||||
}
|
||||
}
|
||||
@@ -131,16 +129,14 @@ secretGenerator:
|
||||
secret := findSecret(m, "nohash")
|
||||
if secret == nil {
|
||||
t.Errorf("Expected to find a Secret")
|
||||
}
|
||||
if secret.GetName() != "nohash" {
|
||||
} else if secret.GetName() != "nohash" {
|
||||
t.Errorf("unexpected secret resource name: %s", secret.GetName())
|
||||
}
|
||||
|
||||
secret = findSecret(m, "yeshash")
|
||||
if secret == nil {
|
||||
t.Errorf("Expected to find a Secret")
|
||||
}
|
||||
if secret.GetName() != "yeshash-82c2g5f8f6" {
|
||||
} else if secret.GetName() != "yeshash-82c2g5f8f6" {
|
||||
t.Errorf("unexpected secret resource name: %s", secret.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +214,7 @@ spec:
|
||||
}
|
||||
|
||||
func skipIfNoDocker(t *testing.T) {
|
||||
t.Helper()
|
||||
if _, err := exec.LookPath("docker"); err != nil {
|
||||
t.Skip("skipping because docker binary wasn't found in PATH")
|
||||
}
|
||||
|
||||
@@ -692,6 +692,7 @@ resources:
|
||||
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
||||
}
|
||||
|
||||
// nolint:gosec
|
||||
const namespaceNeedInVarMyAppWithNamespace string = `
|
||||
resources:
|
||||
- elasticsearch-dev-service.yaml
|
||||
|
||||
@@ -67,6 +67,7 @@ metadata:
|
||||
}
|
||||
|
||||
func makeTmpDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
base, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("err %v", err)
|
||||
|
||||
@@ -172,6 +172,5 @@ spec:
|
||||
// containers:
|
||||
// - image: image-canary-a
|
||||
// name: container-a
|
||||
//`)
|
||||
|
||||
// `)
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
|
||||
return nil, fmt.Errorf("new root cannot be empty")
|
||||
}
|
||||
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(path)
|
||||
repoSpec, err := git.NewRepoSpecFromURL(path)
|
||||
if err == nil {
|
||||
// Treat this as git repo clone request.
|
||||
if err = fl.errIfRepoCycle(repoSpec); err != nil {
|
||||
@@ -315,7 +315,7 @@ func (fl *fileLoader) Load(path string) ([]byte, error) {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
_, err := git.NewRepoSpecFromUrl(path)
|
||||
_, err := git.NewRepoSpecFromURL(path)
|
||||
if err == nil {
|
||||
return nil, errors.New("URL is a git repository")
|
||||
}
|
||||
|
||||
@@ -240,6 +240,7 @@ func commonSetupForLoaderRestrictionTest() (string, filesys.FileSystem, error) {
|
||||
// in or below the loader root.
|
||||
func doSanityChecksAndDropIntoBase(
|
||||
t *testing.T, l ifc.Loader) ifc.Loader {
|
||||
t.Helper()
|
||||
data, err := l.Load(path.Join("base", "okayData"))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -347,7 +348,7 @@ func splitOnNthSlash(v string, n int) (string, string) {
|
||||
if k < 0 {
|
||||
break
|
||||
}
|
||||
left = left + v[:k+1]
|
||||
left += v[:k+1]
|
||||
v = v[k+1:]
|
||||
}
|
||||
return left[:len(left)-1], v
|
||||
@@ -367,9 +368,9 @@ func TestSplit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewLoaderAtGitClone(t *testing.T) {
|
||||
rootUrl := "github.com/someOrg/someRepo"
|
||||
rootURL := "github.com/someOrg/someRepo"
|
||||
pathInRepo := "foo/base"
|
||||
url := rootUrl + "/" + pathInRepo
|
||||
url := rootURL + "/" + pathInRepo
|
||||
coRoot := "/tmp"
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
fSys.MkdirAll(coRoot)
|
||||
@@ -381,7 +382,7 @@ func TestNewLoaderAtGitClone(t *testing.T) {
|
||||
whatever
|
||||
`))
|
||||
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(url)
|
||||
repoSpec, err := git.NewRepoSpecFromURL(url)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v\n", err)
|
||||
}
|
||||
@@ -398,13 +399,13 @@ whatever
|
||||
if _, err = l.New(url); err == nil {
|
||||
t.Fatalf("expected cycle error 1")
|
||||
}
|
||||
if _, err = l.New(rootUrl + "/" + "foo"); err == nil {
|
||||
if _, err = l.New(rootURL + "/" + "foo"); err == nil {
|
||||
t.Fatalf("expected cycle error 2")
|
||||
}
|
||||
|
||||
pathInRepo = "foo/overlay"
|
||||
fSys.MkdirAll(coRoot + "/" + pathInRepo)
|
||||
url = rootUrl + "/" + pathInRepo
|
||||
url = rootURL + "/" + pathInRepo
|
||||
l2, err := l.New(url)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
@@ -459,7 +460,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
|
||||
// exist in its own repository, so presumably the
|
||||
// remote K would be deliberately designed to phish
|
||||
// for local K's.
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(
|
||||
repoSpec, err := git.NewRepoSpecFromURL(
|
||||
"github.com/someOrg/someRepo/foo/overlay")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v\n", err)
|
||||
@@ -533,7 +534,7 @@ func TestRepoDirectCycleDetection(t *testing.T) {
|
||||
RestrictionRootOnly, root, fSys, nil,
|
||||
git.DoNothingCloner(filesys.ConfirmedDir(cloneRoot)))
|
||||
p1 := "github.com/someOrg/someRepo/foo"
|
||||
rs1, err := git.NewRepoSpecFromUrl(p1)
|
||||
rs1, err := git.NewRepoSpecFromURL(p1)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
func NewLoader(
|
||||
lr LoadRestrictorFunc,
|
||||
target string, fSys filesys.FileSystem) (ifc.Loader, error) {
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(target)
|
||||
repoSpec, err := git.NewRepoSpecFromURL(target)
|
||||
if err == nil {
|
||||
// The target qualifies as a remote git target.
|
||||
return newLoaderAtGitClone(
|
||||
|
||||
@@ -78,8 +78,8 @@ func (rmF *Factory) NewResMapFromBytes(b []byte) (ResMap, error) {
|
||||
func (rmF *Factory) NewResMapFromConfigMapArgs(
|
||||
kvLdr ifc.KvLoader, argList []types.ConfigMapArgs) (ResMap, error) {
|
||||
var resources []*resource.Resource
|
||||
for _, args := range argList {
|
||||
res, err := rmF.resF.MakeConfigMap(kvLdr, &args)
|
||||
for i := range argList {
|
||||
res, err := rmF.resF.MakeConfigMap(kvLdr, &argList[i])
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NewResMapFromConfigMapArgs")
|
||||
}
|
||||
@@ -103,8 +103,8 @@ func (rmF *Factory) FromConfigMapArgs(
|
||||
func (rmF *Factory) NewResMapFromSecretArgs(
|
||||
kvLdr ifc.KvLoader, argsList []types.SecretArgs) (ResMap, error) {
|
||||
var resources []*resource.Resource
|
||||
for _, args := range argsList {
|
||||
res, err := rmF.resF.MakeSecret(kvLdr, &args)
|
||||
for i := range argsList {
|
||||
res, err := rmF.resF.MakeSecret(kvLdr, &argsList[i])
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "NewResMapFromSecretArgs")
|
||||
}
|
||||
|
||||
@@ -429,7 +429,6 @@ func getNamespacesForRoleBinding(r *resource.Resource) (map[string]bool, error)
|
||||
if r.GetKind() != "RoleBinding" {
|
||||
return result, nil
|
||||
}
|
||||
//nolint staticcheck
|
||||
subjects, err := r.GetSlice("subjects")
|
||||
if err != nil || subjects == nil {
|
||||
return result, nil
|
||||
@@ -442,7 +441,7 @@ func getNamespacesForRoleBinding(r *resource.Resource) (map[string]bool, error)
|
||||
if n, ok3 := ns.(string); ok3 {
|
||||
result[n] = true
|
||||
} else {
|
||||
return nil, errors.New(fmt.Sprintf("Invalid Input: namespace is blank for resource %q\n", r.CurId()))
|
||||
return nil, errors.Errorf("Invalid Input: namespace is blank for resource %q\n", r.CurId())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,14 @@ var origin2 = &resource.Origin{
|
||||
}
|
||||
|
||||
func doAppend(t *testing.T, w ResMap, r *resource.Resource) {
|
||||
t.Helper()
|
||||
err := w.Append(r)
|
||||
if err != nil {
|
||||
t.Fatalf("append error: %v", err)
|
||||
}
|
||||
}
|
||||
func doRemove(t *testing.T, w ResMap, id resid.ResId) {
|
||||
t.Helper()
|
||||
err := w.Remove(id)
|
||||
if err != nil {
|
||||
t.Fatalf("remove error: %v", err)
|
||||
@@ -116,7 +118,7 @@ func TestAppendRemove(t *testing.T) {
|
||||
doAppend(t, w2, makeCm(2))
|
||||
doAppend(t, w2, makeCm(4))
|
||||
doAppend(t, w2, makeCm(6))
|
||||
if !reflect.DeepEqual(w1, w1) {
|
||||
if !reflect.DeepEqual(w1, w2) {
|
||||
w1.Debug("w1")
|
||||
w2.Debug("w2")
|
||||
t.Fatalf("mismatch")
|
||||
@@ -431,7 +433,6 @@ func TestGetMatchingResourcesByAnyId(t *testing.T) {
|
||||
m := resmaptest_test.NewRmBuilder(t, rf).
|
||||
AddR(r1).AddR(r2).AddR(r3).AddR(r4).AddR(r5).ResMap()
|
||||
|
||||
// nolint:goconst
|
||||
tests := []struct {
|
||||
name string
|
||||
matcher IdMatcher
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func setupRMForPatchTargets(t *testing.T) ResMap {
|
||||
t.Helper()
|
||||
result, err := rmF.NewResMapFromBytes([]byte(`
|
||||
apiVersion: group1/v1
|
||||
kind: Kind1
|
||||
|
||||
@@ -50,7 +50,7 @@ func (origin *Origin) Copy() Origin {
|
||||
// Append returns a copy of origin with a path appended to it
|
||||
func (origin *Origin) Append(path string) *Origin {
|
||||
originCopy := origin.Copy()
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(path)
|
||||
repoSpec, err := git.NewRepoSpecFromURL(path)
|
||||
if err == nil {
|
||||
originCopy.Repo = repoSpec.Host + repoSpec.OrgRepo
|
||||
absPath := repoSpec.AbsPath()
|
||||
|
||||
@@ -26,7 +26,6 @@ type Resource struct {
|
||||
refVarNames []string
|
||||
}
|
||||
|
||||
// nolint
|
||||
var BuildAnnotations = []string{
|
||||
utils.BuildAnnotationPreviousKinds,
|
||||
utils.BuildAnnotationPreviousNames,
|
||||
|
||||
@@ -32,6 +32,7 @@ func run(input string, f kio.Filter) (string, error) {
|
||||
|
||||
// RunFilter runs filter and panic if there is error
|
||||
func RunFilter(t *testing.T, input string, f kio.Filter) string {
|
||||
t.Helper()
|
||||
output, err := run(input, f)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
@@ -41,6 +42,7 @@ func RunFilter(t *testing.T, input string, f kio.Filter) string {
|
||||
|
||||
// RunFilterE runs filter and return error if there is
|
||||
func RunFilterE(t *testing.T, input string, f kio.Filter) (string, error) {
|
||||
t.Helper()
|
||||
output, err := run(input, f)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -22,11 +22,13 @@ type Harness struct {
|
||||
}
|
||||
|
||||
func MakeHarness(t *testing.T) Harness {
|
||||
t.Helper()
|
||||
return MakeHarnessWithFs(t, filesys.MakeFsInMemory())
|
||||
}
|
||||
|
||||
func MakeHarnessWithFs(
|
||||
t *testing.T, fSys filesys.FileSystem) Harness {
|
||||
t.Helper()
|
||||
return Harness{
|
||||
t: t,
|
||||
fSys: fSys,
|
||||
|
||||
@@ -47,6 +47,7 @@ type HarnessEnhanced struct {
|
||||
}
|
||||
|
||||
func MakeEnhancedHarness(t *testing.T) *HarnessEnhanced {
|
||||
t.Helper()
|
||||
r := makeBaseEnhancedHarness(t)
|
||||
r.Harness = MakeHarnessWithFs(t, filesys.MakeFsInMemory())
|
||||
// Point the Harness's file loader to the root ('/')
|
||||
@@ -56,6 +57,7 @@ func MakeEnhancedHarness(t *testing.T) *HarnessEnhanced {
|
||||
}
|
||||
|
||||
func MakeEnhancedHarnessWithTmpRoot(t *testing.T) *HarnessEnhanced {
|
||||
t.Helper()
|
||||
r := makeBaseEnhancedHarness(t)
|
||||
fSys := filesys.MakeFsOnDisk()
|
||||
r.Harness = MakeHarnessWithFs(t, fSys)
|
||||
@@ -72,6 +74,7 @@ func MakeEnhancedHarnessWithTmpRoot(t *testing.T) *HarnessEnhanced {
|
||||
}
|
||||
|
||||
func makeBaseEnhancedHarness(t *testing.T) *HarnessEnhanced {
|
||||
t.Helper()
|
||||
rf := resmap.NewFactory(
|
||||
provider.NewDefaultDepProvider().GetResourceFactory())
|
||||
return &HarnessEnhanced{
|
||||
|
||||
@@ -26,6 +26,7 @@ func AssertActualEqualsExpectedWithTweak(
|
||||
t *testing.T,
|
||||
m resmap.ResMap,
|
||||
tweaker func([]byte) []byte, expected string) {
|
||||
t.Helper()
|
||||
if m == nil {
|
||||
t.Fatalf("Map should not be nil.")
|
||||
}
|
||||
@@ -49,13 +50,14 @@ func AssertActualEqualsExpectedWithTweak(
|
||||
// Pretty printing of file differences.
|
||||
func reportDiffAndFail(
|
||||
t *testing.T, actual []byte, expected string) {
|
||||
t.Helper()
|
||||
sE, maxLen := convertToArray(expected)
|
||||
sA, _ := convertToArray(string(actual))
|
||||
fmt.Println("===== ACTUAL BEGIN ========================================")
|
||||
fmt.Print(string(actual))
|
||||
fmt.Println("===== ACTUAL END ==========================================")
|
||||
format := fmt.Sprintf("%%s %%-%ds %%s\n", maxLen+4)
|
||||
limit := 0
|
||||
var limit int
|
||||
if len(sE) < len(sA) {
|
||||
limit = len(sE)
|
||||
} else {
|
||||
|
||||
@@ -25,6 +25,7 @@ type pluginTestEnv struct {
|
||||
|
||||
// newPluginTestEnv returns a new instance of pluginTestEnv.
|
||||
func newPluginTestEnv(t *testing.T) *pluginTestEnv {
|
||||
t.Helper()
|
||||
return &pluginTestEnv{t: t}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,18 +20,22 @@ type rmBuilder struct {
|
||||
}
|
||||
|
||||
func NewSeededRmBuilder(t *testing.T, rf *resource.Factory, m resmap.ResMap) *rmBuilder {
|
||||
t.Helper()
|
||||
return &rmBuilder{t: t, rf: rf, m: m}
|
||||
}
|
||||
|
||||
func NewRmBuilder(t *testing.T, rf *resource.Factory) *rmBuilder {
|
||||
t.Helper()
|
||||
return NewSeededRmBuilder(t, rf, resmap.New())
|
||||
}
|
||||
|
||||
func NewRmBuilderDefault(t *testing.T) *rmBuilder {
|
||||
t.Helper()
|
||||
return NewSeededRmBuilderDefault(t, resmap.New())
|
||||
}
|
||||
|
||||
func NewSeededRmBuilderDefault(t *testing.T, m resmap.ResMap) *rmBuilder {
|
||||
t.Helper()
|
||||
return NewSeededRmBuilder(
|
||||
t, provider.NewDefaultDepProvider().GetResourceFactory(), m)
|
||||
}
|
||||
|
||||
@@ -22,11 +22,13 @@ const SAD = "i'm not happy Bob, NOT HAPPY"
|
||||
|
||||
// MakeHappyMapValidator makes a fakeValidator that always passes.
|
||||
func MakeHappyMapValidator(t *testing.T) *fakeValidator {
|
||||
t.Helper()
|
||||
return &fakeValidator{happy: true, t: t}
|
||||
}
|
||||
|
||||
// MakeSadMapValidator makes a fakeValidator that always fails.
|
||||
func MakeSadMapValidator(t *testing.T) *fakeValidator {
|
||||
t.Helper()
|
||||
return &fakeValidator{happy: false, t: t}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ type HelmChart struct {
|
||||
|
||||
// IncludeCRDs specifies if Helm should also generate CustomResourceDefinitions.
|
||||
// Defaults to 'false'.
|
||||
IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"`
|
||||
IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` // nolint: tagliatelle
|
||||
}
|
||||
|
||||
// HelmChartArgs contains arguments to helm.
|
||||
@@ -96,8 +96,8 @@ type HelmChartArgs struct {
|
||||
// per-chart params and global chart-independent parameters.
|
||||
func SplitHelmParameters(
|
||||
oldArgs []HelmChartArgs) (charts []HelmChart, globals HelmGlobals) {
|
||||
for _, old := range oldArgs {
|
||||
charts = append(charts, makeHelmChartFromHca(&old))
|
||||
for i, old := range oldArgs {
|
||||
charts = append(charts, makeHelmChartFromHca(&oldArgs[i]))
|
||||
if old.HelmHome != "" {
|
||||
// last non-empty wins
|
||||
globals.ConfigHome = old.HelmHome
|
||||
|
||||
@@ -192,14 +192,14 @@ func (k *Kustomization) FixKustomizationPostUnmarshalling() {
|
||||
for i, g := range k.ConfigMapGenerator {
|
||||
if g.EnvSource != "" {
|
||||
k.ConfigMapGenerator[i].EnvSources =
|
||||
append(g.EnvSources, g.EnvSource)
|
||||
append(g.EnvSources, g.EnvSource) //nolint:gocritic
|
||||
k.ConfigMapGenerator[i].EnvSource = ""
|
||||
}
|
||||
}
|
||||
for i, g := range k.SecretGenerator {
|
||||
if g.EnvSource != "" {
|
||||
k.SecretGenerator[i].EnvSources =
|
||||
append(g.EnvSources, g.EnvSource)
|
||||
append(g.EnvSources, g.EnvSource) //nolint:gocritic
|
||||
k.SecretGenerator[i].EnvSource = ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
run:
|
||||
deadline: 5m
|
||||
|
||||
linters:
|
||||
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
# - dogsled
|
||||
- dupl
|
||||
# - errcheck
|
||||
# - funlen
|
||||
# - gochecknoinits
|
||||
# - goconst
|
||||
# - gocritic
|
||||
# - gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
# - golint
|
||||
# - gosec
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
# - lll
|
||||
- misspell
|
||||
- nakedret
|
||||
# - scopelint
|
||||
- staticcheck
|
||||
- structcheck
|
||||
# - stylecheck
|
||||
- typecheck
|
||||
- unconvert
|
||||
# - unparam
|
||||
- unused
|
||||
- varcheck
|
||||
# - whitespace
|
||||
|
||||
|
||||
linters-settings:
|
||||
dupl:
|
||||
threshold: 400
|
||||
lll:
|
||||
line-length: 170
|
||||
gocyclo:
|
||||
min-complexity: 30
|
||||
golint:
|
||||
min-confidence: 0.85
|
||||
@@ -12,7 +12,7 @@ $(GOBIN)/addlicense:
|
||||
go get github.com/google/addlicense
|
||||
|
||||
$(GOBIN)/golangci-lint:
|
||||
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.19.1
|
||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
|
||||
|
||||
$(GOBIN)/k8scopy:
|
||||
( cd ../k8scopy; go install . )
|
||||
@@ -36,7 +36,9 @@ clean:
|
||||
lint: $(GOBIN)/golangci-lint
|
||||
$(GOBIN)/golangci-lint \
|
||||
--skip-dirs $(k8sGenDir) \
|
||||
run ./...
|
||||
run ./... \
|
||||
--path-prefix=cmd/config \
|
||||
-c ../../.golangci.yml
|
||||
|
||||
license: $(GOBIN)/addlicense
|
||||
$(GOBIN)/addlicense \
|
||||
|
||||
@@ -611,8 +611,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -142,7 +142,6 @@ func (r *AnnotateRunner) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -88,6 +88,7 @@ func TestAnnotateCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func initTestDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
d, err := ioutil.TempDir("", "kustomize-annotate-test")
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
@@ -601,12 +602,12 @@ added annotations in the package
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Contains(t, actualNormalized, expectedNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -166,7 +166,6 @@ func (r *CatRunner) catFilters() []kio.Filter {
|
||||
return fltrs
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (r *CatRunner) out(w io.Writer) ([]kio.Writer, error) {
|
||||
var outputs []kio.Writer
|
||||
var functionConfig *yaml.RNode
|
||||
|
||||
@@ -654,12 +654,12 @@ spec:
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Equal(t, expectedNormalized, actualNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -753,12 +753,12 @@ spec:
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1)
|
||||
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(out.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(out.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
if !assert.Contains(t, actualNormalized, expectedNormalized) {
|
||||
t.FailNow()
|
||||
@@ -863,12 +863,12 @@ setter with name "namespace" already exists, if you want to modify it, please de
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Contains(t, actualNormalized, expectedNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -393,12 +393,12 @@ spec:
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1)
|
||||
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(out.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(out.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
if !assert.Contains(t, actualNormalized, expectedNormalized) {
|
||||
t.FailNow()
|
||||
@@ -500,12 +500,12 @@ created substitution "image-tag"`,
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(expectedNormalized)) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -340,12 +340,12 @@ kind: Deployment
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNorm := strings.Replace(
|
||||
strings.Replace(out.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNorm := strings.ReplaceAll(
|
||||
strings.ReplaceAll(out.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expectedOut, "\\", "/", -1)
|
||||
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expectedOut, "\\", "/")
|
||||
|
||||
if !assert.Contains(t, strings.TrimSpace(actualNorm), expectedNormalized) {
|
||||
t.FailNow()
|
||||
@@ -427,7 +427,7 @@ deleted setter "namespace"
|
||||
t.FailNow()
|
||||
}
|
||||
copyutil.CopyDir(sourceDir, baseDir)
|
||||
//defer os.RemoveAll(baseDir)
|
||||
// defer os.RemoveAll(baseDir)
|
||||
runner := commands.NewDeleteSetterRunner("")
|
||||
actual := &bytes.Buffer{}
|
||||
runner.Command.SetOut(actual)
|
||||
@@ -438,12 +438,12 @@ deleted setter "namespace"
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Equal(t, expectedNormalized, actualNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -467,11 +467,11 @@ spec:
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNorm := strings.Replace(
|
||||
strings.Replace(out.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
expectedOut := strings.Replace(test.out, "${baseDir}", baseDir, -1)
|
||||
expectedNorm := strings.Replace(expectedOut, "\\", "/", -1)
|
||||
actualNorm := strings.ReplaceAll(
|
||||
strings.ReplaceAll(out.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
expectedOut := strings.ReplaceAll(test.out, "${baseDir}", baseDir)
|
||||
expectedNorm := strings.ReplaceAll(expectedOut, "\\", "/")
|
||||
|
||||
if !assert.Contains(t, strings.TrimSpace(actualNorm), expectedNorm) {
|
||||
t.FailNow()
|
||||
@@ -544,7 +544,7 @@ deleted substitution "image-tag"
|
||||
t.FailNow()
|
||||
}
|
||||
copyutil.CopyDir(sourceDir, baseDir)
|
||||
//defer os.RemoveAll(baseDir)
|
||||
// defer os.RemoveAll(baseDir)
|
||||
runner := commands.NewDeleteSubstitutionRunner("")
|
||||
actual := &bytes.Buffer{}
|
||||
runner.Command.SetOut(actual)
|
||||
@@ -555,12 +555,12 @@ deleted substitution "image-tag"
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Equal(t, expectedNormalized, actualNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ test/testdata/dataset-with-setters/mysql/
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(actual.String(), "\\", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(actual.String(), "\\", "/")
|
||||
|
||||
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(test.expected)) {
|
||||
t.FailNow()
|
||||
|
||||
@@ -1129,14 +1129,14 @@ set 1 field(s) of setter "namespace" to value "otherspace"
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(
|
||||
strings.Replace(expected, "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(expected, "\\", "/"),
|
||||
"//", "/")
|
||||
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(expectedNormalized)) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (r *XArgsRunner) runE(c *cobra.Command, _ []string) error {
|
||||
return fmt.Errorf("must specify -- before command")
|
||||
}
|
||||
r.Args = r.Args[cmdIndex:]
|
||||
run := exec.Command(r.Args[0])
|
||||
run := exec.Command(r.Args[0]) // nolint: gosec
|
||||
|
||||
if len(r.Args) > 1 {
|
||||
r.Args = r.Args[cmdIndex+1:]
|
||||
|
||||
@@ -137,12 +137,12 @@ Deployment: 1
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Equal(t, expectedNormalized, actualNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestRunE2e(t *testing.T) {
|
||||
name: "exec_function_no_args",
|
||||
args: func(d string) []string {
|
||||
return []string{
|
||||
"--enable-exec", "--exec-path", filepath.Join(d, "e2econtainerconfig"),
|
||||
"--enable-exec", "--exec-path", filepath.Join(d, e2eConfigDir),
|
||||
}
|
||||
},
|
||||
files: func(d string) map[string]string {
|
||||
@@ -720,7 +720,7 @@ metadata:
|
||||
}
|
||||
|
||||
args := append([]string{"fn", "run", "."}, tt.args(binDir)...)
|
||||
cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...)
|
||||
cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...) // nolint: gosec
|
||||
cmd.Dir = dir
|
||||
var stdErr, stdOut bytes.Buffer
|
||||
cmd.Stdout = &stdOut
|
||||
@@ -751,6 +751,8 @@ metadata:
|
||||
var buildOnce sync.Once
|
||||
var binDir string
|
||||
|
||||
const e2eConfigDir = "e2econtainerconfig"
|
||||
|
||||
func build() string {
|
||||
// only build the binaries once
|
||||
buildOnce.Do(func() {
|
||||
@@ -760,7 +762,7 @@ func build() string {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
build := exec.Command("go", "build", "-o",
|
||||
build := exec.Command("go", "build", "-o", // nolint: gosec
|
||||
filepath.Join(binDir, e2econtainerconfigBin))
|
||||
build.Dir = "e2econtainerconfig"
|
||||
build.Stdout = os.Stdout
|
||||
@@ -772,7 +774,7 @@ func build() string {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin))
|
||||
build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin)) // nolint: gosec
|
||||
build.Dir = filepath.Join("..", "..", "..", "kubectl-krm")
|
||||
build.Stdout = os.Stdout
|
||||
build.Stderr = os.Stderr
|
||||
@@ -786,7 +788,7 @@ func build() string {
|
||||
}
|
||||
build = exec.Command(
|
||||
"docker", "build", ".", "-t", "gcr.io/kustomize-functions/e2econtainerconfig")
|
||||
build.Dir = "e2econtainerconfig"
|
||||
build.Dir = e2eConfigDir
|
||||
build.Stdout = os.Stdout
|
||||
build.Stderr = os.Stderr
|
||||
err = build.Run()
|
||||
@@ -803,9 +805,9 @@ var (
|
||||
kyamlBin string
|
||||
)
|
||||
|
||||
func init() {
|
||||
func init() { //nolint: gochecknoinits
|
||||
kyamlBin = "kubectl-krm"
|
||||
e2econtainerconfigBin = "e2econtainerconfig"
|
||||
e2econtainerconfigBin = e2eConfigDir
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
kyamlBin = "kubectl-krm.exe"
|
||||
|
||||
@@ -17,9 +17,13 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
d := build()
|
||||
defer os.RemoveAll(d)
|
||||
os.Exit(m.Run())
|
||||
var code int
|
||||
func() {
|
||||
d := build()
|
||||
defer os.RemoveAll(d)
|
||||
code = m.Run()
|
||||
}()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
type test struct {
|
||||
@@ -32,6 +36,7 @@ type test struct {
|
||||
}
|
||||
|
||||
func runTests(t *testing.T, tests []test) {
|
||||
t.Helper()
|
||||
dir := build()
|
||||
bin := filepath.Join(dir, kyamlBin)
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ func (r *FmtRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func (r *FmtRunner) runE(c *cobra.Command, args []string) error {
|
||||
|
||||
// format stdin if there are no args
|
||||
if len(args) == 0 {
|
||||
rw := &kio.ByteReadWriter{
|
||||
|
||||
@@ -232,12 +232,12 @@ formatted resource files in the package
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Contains(t, strings.TrimSpace(actualNormalized), strings.TrimSpace(expectedNormalized)) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -73,19 +73,20 @@ func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
var last []string
|
||||
if strings.Contains(parts[len(parts)-1], ">=") {
|
||||
switch {
|
||||
case strings.Contains(parts[len(parts)-1], ">="):
|
||||
last = strings.Split(parts[len(parts)-1], ">=")
|
||||
r.MatchType = filters.GreaterThanEq
|
||||
} else if strings.Contains(parts[len(parts)-1], "<=") {
|
||||
case strings.Contains(parts[len(parts)-1], "<="):
|
||||
last = strings.Split(parts[len(parts)-1], "<=")
|
||||
r.MatchType = filters.LessThanEq
|
||||
} else if strings.Contains(parts[len(parts)-1], ">") {
|
||||
case strings.Contains(parts[len(parts)-1], ">"):
|
||||
last = strings.Split(parts[len(parts)-1], ">")
|
||||
r.MatchType = filters.GreaterThan
|
||||
} else if strings.Contains(parts[len(parts)-1], "<") {
|
||||
case strings.Contains(parts[len(parts)-1], "<"):
|
||||
last = strings.Split(parts[len(parts)-1], "<")
|
||||
r.MatchType = filters.LessThan
|
||||
} else {
|
||||
default:
|
||||
last = strings.Split(parts[len(parts)-1], "=")
|
||||
r.MatchType = filters.Regexp
|
||||
}
|
||||
@@ -99,7 +100,7 @@ func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
r.Value = last[1]
|
||||
}
|
||||
|
||||
r.Path = append(parts[:len(parts)-1], last[0])
|
||||
r.Path = append(parts[:len(parts)-1], last[0]) // nolint:gocritic
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -136,7 +137,6 @@ func (r *GrepRunner) runE(c *cobra.Command, args []string) error {
|
||||
fmt.Fprintf(c.OutOrStdout(), "%s", res)
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (r *GrepRunner) ExecuteCmd(w io.Writer, pkgPath string) error {
|
||||
|
||||
@@ -416,12 +416,12 @@ spec:
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expected, "${baseDir}", baseDir, -1)
|
||||
expectedNormalized := strings.Replace(expected, "\\", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expected, "${baseDir}", baseDir)
|
||||
expectedNormalized := strings.ReplaceAll(expected, "\\", "/")
|
||||
if !assert.Equal(t, expectedNormalized, actualNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ spec:
|
||||
return
|
||||
}
|
||||
|
||||
expected_dir, err := ioutil.TempDir("", "test-data-expected")
|
||||
defer os.RemoveAll(expected_dir)
|
||||
expectedDir, err := ioutil.TempDir("", "test-data-expected")
|
||||
defer os.RemoveAll(expectedDir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(expected_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
err = ioutil.WriteFile(filepath.Join(expectedDir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
@@ -111,13 +111,13 @@ spec:
|
||||
return
|
||||
}
|
||||
|
||||
updated_dir, err := ioutil.TempDir("", "test-data-updated")
|
||||
defer os.RemoveAll(updated_dir)
|
||||
updatedDir, err := ioutil.TempDir("", "test-data-updated")
|
||||
defer os.RemoveAll(updatedDir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(updated_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
err = ioutil.WriteFile(filepath.Join(updatedDir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
@@ -158,13 +158,13 @@ spec:
|
||||
return
|
||||
}
|
||||
|
||||
dest_dir, err := ioutil.TempDir("", "test-data-dest")
|
||||
defer os.RemoveAll(dest_dir)
|
||||
destDir, err := ioutil.TempDir("", "test-data-dest")
|
||||
defer os.RemoveAll(destDir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(dest_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
err = ioutil.WriteFile(filepath.Join(destDir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
@@ -212,15 +212,15 @@ spec:
|
||||
"--ancestor",
|
||||
datadir,
|
||||
"--from",
|
||||
updated_dir,
|
||||
updatedDir,
|
||||
"--to",
|
||||
dest_dir,
|
||||
destDir,
|
||||
})
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
return
|
||||
}
|
||||
|
||||
diffs, err := copyutil.Diff(dest_dir, expected_dir)
|
||||
diffs, err := copyutil.Diff(destDir, expectedDir)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -47,7 +47,8 @@ func GetRunFnRunner(name string) *RunFnRunner {
|
||||
"run this image as a function instead of discovering them.")
|
||||
// NOTE: exec plugins execute arbitrary code -- never change the default value of this flag!!!
|
||||
r.Command.Flags().BoolVar(
|
||||
&r.EnableExec, "enable-exec", false /*do not change!*/, "enable support for exec functions -- note: exec functions run arbitrary code -- do not use for untrusted configs!!! (Alpha)")
|
||||
&r.EnableExec, "enable-exec", false, /*do not change!*/
|
||||
"enable support for exec functions -- note: exec functions run arbitrary code -- do not use for untrusted configs!!! (Alpha)")
|
||||
r.Command.Flags().StringVar(
|
||||
&r.ExecPath, "exec-path", "", "run an executable as a function. (Alpha)")
|
||||
r.Command.Flags().BoolVar(
|
||||
@@ -111,87 +112,47 @@ func (r *RunFnRunner) runE(c *cobra.Command, args []string) error {
|
||||
|
||||
// getContainerFunctions parses the commandline flags and arguments into explicit
|
||||
// Functions to run.
|
||||
func (r *RunFnRunner) getContainerFunctions(c *cobra.Command, dataItems []string) (
|
||||
func (r *RunFnRunner) getContainerFunctions(dataItems []string) (
|
||||
[]*yaml.RNode, error) {
|
||||
|
||||
if r.Image == "" && r.StarPath == "" && r.ExecPath == "" && r.StarURL == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var fn *yaml.RNode
|
||||
var err error
|
||||
|
||||
if r.Image != "" {
|
||||
// create the function spec to set as an annotation
|
||||
fn, err = yaml.Parse(`container: {}`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO: add support network, volumes, etc based on flag values
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("container"),
|
||||
yaml.SetField("image", yaml.NewScalarRNode(r.Image)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.Network {
|
||||
n := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "true",
|
||||
Tag: yaml.NodeTagBool,
|
||||
}
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("container"),
|
||||
yaml.SetField("network", yaml.NewRNode(n)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else if r.EnableStar && (r.StarPath != "" || r.StarURL != "") {
|
||||
// create the function spec to set as an annotation
|
||||
fn, err = yaml.Parse(`starlark: {}`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if r.StarPath != "" {
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("path", yaml.NewScalarRNode(r.StarPath)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if r.StarURL != "" {
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("url", yaml.NewScalarRNode(r.StarURL)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("name", yaml.NewScalarRNode(r.StarName)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
} else if r.EnableExec && r.ExecPath != "" {
|
||||
// create the function spec to set as an annotation
|
||||
fn, err = yaml.Parse(`exec: {}`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("exec"),
|
||||
yaml.SetField("path", yaml.NewScalarRNode(r.ExecPath)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := buildFnConfigResource(dataItems)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create the function spec to set as an annotation
|
||||
var fnAnnotation *yaml.RNode
|
||||
switch {
|
||||
case r.Image != "":
|
||||
fnAnnotation, err = fnAnnotationForImage(r.Image, r.Network)
|
||||
case r.EnableStar && (r.StarPath != "" || r.StarURL != ""):
|
||||
fnAnnotation, err = fnAnnotationForStar(r.StarPath, r.StarURL, r.StarName)
|
||||
case r.EnableExec && r.ExecPath != "":
|
||||
fnAnnotation, err = fnAnnotationForExec(r.ExecPath)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set the function annotation on the function config, so that it is parsed by RunFns
|
||||
value, err := fnAnnotation.String()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
err = res.PipeE(
|
||||
yaml.LookupCreate(yaml.MappingNode, "metadata", "annotations"),
|
||||
yaml.SetField(runtimeutil.FunctionAnnotationKey, yaml.NewScalarRNode(value)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
|
||||
return []*yaml.RNode{res}, nil
|
||||
}
|
||||
|
||||
func buildFnConfigResource(dataItems []string) (*yaml.RNode, error) {
|
||||
// create the function config
|
||||
rc, err := yaml.Parse(`
|
||||
metadata:
|
||||
@@ -202,19 +163,6 @@ data: {}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// set the function annotation on the function config so it
|
||||
// is parsed by RunFns
|
||||
value, err := fn.String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = rc.PipeE(
|
||||
yaml.LookupCreate(yaml.MappingNode, "metadata", "annotations"),
|
||||
yaml.SetField(runtimeutil.FunctionAnnotationKey, yaml.NewScalarRNode(value)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// default the function config kind to ConfigMap, this may be overridden
|
||||
var kind = "ConfigMap"
|
||||
var version = "v1"
|
||||
@@ -252,7 +200,81 @@ data: {}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []*yaml.RNode{rc}, nil
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func fnAnnotationForExec(path string) (*yaml.RNode, error) {
|
||||
fn, err := yaml.Parse(`exec: {}`)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("exec"),
|
||||
yaml.SetField("path", yaml.NewScalarRNode(path)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
return fn, nil
|
||||
}
|
||||
|
||||
func fnAnnotationForStar(path string, url string, name string) (*yaml.RNode, error) {
|
||||
fn, err := yaml.Parse(`starlark: {}`)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
|
||||
if path != "" {
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("path", yaml.NewScalarRNode(path)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
if url != "" {
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("url", yaml.NewScalarRNode(url)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("starlark"),
|
||||
yaml.SetField("name", yaml.NewScalarRNode(name)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
return fn, nil
|
||||
}
|
||||
|
||||
func fnAnnotationForImage(image string, enableNetwork bool) (*yaml.RNode, error) {
|
||||
fn, err := yaml.Parse(`container: {}`)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
// TODO: add support network, volumes, etc based on flag values
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("container"),
|
||||
yaml.SetField("image", yaml.NewScalarRNode(image)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
if enableNetwork {
|
||||
n := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "true",
|
||||
Tag: yaml.NodeTagBool,
|
||||
}
|
||||
err = fn.PipeE(
|
||||
yaml.Lookup("container"),
|
||||
yaml.SetField("network", yaml.NewRNode(n)))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err)
|
||||
}
|
||||
}
|
||||
return fn, nil
|
||||
}
|
||||
|
||||
func toStorageMounts(mounts []string) []runtimeutil.StorageMount {
|
||||
@@ -286,7 +308,7 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
return errors.Errorf("0 or 1 arguments supported, function arguments go after '--'")
|
||||
}
|
||||
|
||||
fns, err := r.getContainerFunctions(c, dataItems)
|
||||
fns, err := r.getContainerFunctions(dataItems)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -412,7 +412,6 @@ apiVersion: v1
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ See discussion in https://github.com/kubernetes-sigs/kustomize/issues/3953.`)
|
||||
return err
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (r *SinkRunner) runE(c *cobra.Command, args []string) error {
|
||||
var outputs []kio.Writer
|
||||
if len(args) == 1 {
|
||||
|
||||
@@ -202,8 +202,22 @@ func TestSourceCommandJSON(t *testing.T) {
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f1.json'}}, "spec": {"replicas": 1}}
|
||||
- {"apiVersion": "v1", "kind": "Abstraction", "metadata": {"name": "foo", "annotations": {"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n", "config.kubernetes.io/local-config": "true", config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f2.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f2.json'}}, "spec": {"replicas": 3}}
|
||||
- {"kind": "Deployment", `+
|
||||
`"metadata": {`+
|
||||
`"labels": {"app": "nginx2"}, `+
|
||||
`"name": "foo", `+
|
||||
`"annotations": {`+
|
||||
`"app": "nginx2", `+
|
||||
`config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f1.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f1.json'}}, `+
|
||||
`"spec": {"replicas": 1}}
|
||||
- {"apiVersion": "v1", "kind": "Abstraction", `+
|
||||
`"metadata": {`+
|
||||
`"name": "foo", `+
|
||||
`"annotations": {`+
|
||||
`"config.kubernetes.io/function": "container:\n image: gcr.io/example/reconciler:v1\n", `+
|
||||
`"config.kubernetes.io/local-config": "true", `+
|
||||
`config.kubernetes.io/index: '0', config.kubernetes.io/path: 'f2.json', internal.config.kubernetes.io/index: '0', internal.config.kubernetes.io/path: 'f2.json'}}, `+
|
||||
`"spec": {"replicas": 3}}
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
@@ -312,7 +326,14 @@ func TestSourceCommandJSON_Stdin(t *testing.T) {
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- {"kind": "Deployment", "metadata": {"labels": {"app": "nginx2"}, "name": "foo", "annotations": {"app": "nginx2", config.kubernetes.io/index: '0', internal.config.kubernetes.io/index: '0'}}, "spec": {"replicas": 1}}
|
||||
- {"kind": "Deployment", `+
|
||||
`"metadata": {`+
|
||||
`"labels": {"app": "nginx2"}, `+
|
||||
`"name": "foo", `+
|
||||
`"annotations": {`+
|
||||
`"app": "nginx2", `+
|
||||
`config.kubernetes.io/index: '0', internal.config.kubernetes.io/index: '0'}}, `+
|
||||
`"spec": {"replicas": 1}}
|
||||
`, out.String()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ var StackOnError bool
|
||||
const cmdName = "kustomize fn"
|
||||
|
||||
// FixDocs replaces instances of old with new in the docs for c
|
||||
func FixDocs(new string, c *cobra.Command) {
|
||||
c.Use = strings.ReplaceAll(c.Use, cmdName, new)
|
||||
c.Short = strings.ReplaceAll(c.Short, cmdName, new)
|
||||
c.Long = strings.ReplaceAll(c.Long, cmdName, new)
|
||||
c.Example = strings.ReplaceAll(c.Example, cmdName, new)
|
||||
func FixDocs(newStr string, c *cobra.Command) {
|
||||
c.Use = strings.ReplaceAll(c.Use, cmdName, newStr)
|
||||
c.Short = strings.ReplaceAll(c.Short, cmdName, newStr)
|
||||
c.Long = strings.ReplaceAll(c.Long, cmdName, newStr)
|
||||
c.Example = strings.ReplaceAll(c.Example, cmdName, newStr)
|
||||
}
|
||||
|
||||
// containsString returns true if slice contains s
|
||||
|
||||
@@ -98,14 +98,14 @@ ${baseDir}/subpkg2/subpkg3/
|
||||
}
|
||||
|
||||
// normalize path format for windows
|
||||
actualNormalized := strings.Replace(
|
||||
strings.Replace(actual.String(), "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
actualNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(actual.String(), "\\", "/"),
|
||||
"//", "/")
|
||||
|
||||
expected := strings.Replace(test.expectedOut, "${baseDir}", dir+"/", -1)
|
||||
expectedNormalized := strings.Replace(
|
||||
strings.Replace(expected, "\\", "/", -1),
|
||||
"//", "/", -1)
|
||||
expected := strings.ReplaceAll(test.expectedOut, "${baseDir}", dir+"/")
|
||||
expectedNormalized := strings.ReplaceAll(
|
||||
strings.ReplaceAll(expected, "\\", "/"),
|
||||
"//", "/")
|
||||
if !assert.Equal(t, expectedNormalized, actualNormalized) {
|
||||
t.FailNow()
|
||||
}
|
||||
@@ -141,27 +141,27 @@ func createTestDirStructure(dir string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg1", "Krmfile"), []byte(""), 0777)
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg1", "Krmfile"), []byte(""), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2", "Krmfile"), []byte(""), 0777)
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2", "Krmfile"), []byte(""), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2/subpkg3", "Krmfile"), []byte(""), 0777)
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg2/subpkg3", "Krmfile"), []byte(""), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "error.txt"), []byte(""), 0777)
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "error.txt"), []byte(""), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "Krmfile"), []byte(""), 0777)
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "subpkg4", "Krmfile"), []byte(""), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "Krmfile"), []byte(""), 0777)
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "Krmfile"), []byte(""), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -612,8 +612,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
|
||||
@@ -105,7 +105,7 @@ func (c *Converter) prepareWrapper(content string) string {
|
||||
}
|
||||
// assign to plugin variable
|
||||
if strings.TrimSpace(line) == "var plugin resmap.Configurable" {
|
||||
line = line + `
|
||||
line += `
|
||||
// KustomizePlugin is a global variable defined in every plugin
|
||||
plugin = &KustomizePlugin
|
||||
`
|
||||
|
||||
@@ -9,9 +9,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func makeTempDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
s, err := ioutil.TempDir("", "pluginator-*")
|
||||
assert.NoError(t, err)
|
||||
return s
|
||||
@@ -99,6 +101,7 @@ items:
|
||||
}
|
||||
|
||||
func runKrmFunction(t *testing.T, input []byte, dir string) []byte {
|
||||
t.Helper()
|
||||
cmd := exec.Command("go", "run", ".")
|
||||
ib := bytes.NewReader(input)
|
||||
cmd.Stdin = ib
|
||||
@@ -118,13 +121,14 @@ func TestTransformerConverter(t *testing.T) {
|
||||
dir := makeTempDir(t)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(dir, "Plugin.go"),
|
||||
err := ioutil.WriteFile(filepath.Join(dir, "Plugin.go"),
|
||||
getTransformerCode(), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := NewConverter(filepath.Join(dir, "output"),
|
||||
filepath.Join(dir, "Plugin.go"))
|
||||
|
||||
err := c.Convert()
|
||||
err = c.Convert()
|
||||
assert.NoError(t, err)
|
||||
|
||||
output := runKrmFunction(t, getTransformerInputResource(), filepath.Join(dir, "output"))
|
||||
@@ -215,13 +219,14 @@ func TestGeneratorConverter(t *testing.T) {
|
||||
dir := makeTempDir(t)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(dir, "Plugin.go"),
|
||||
err := ioutil.WriteFile(filepath.Join(dir, "Plugin.go"),
|
||||
getGeneratorCode(), 0644)
|
||||
require.NoError(t, err)
|
||||
|
||||
c := NewConverter(filepath.Join(dir, "output"),
|
||||
filepath.Join(dir, "Plugin.go"))
|
||||
|
||||
err := c.Convert()
|
||||
err = c.Convert()
|
||||
assert.NoError(t, err)
|
||||
output := runKrmFunction(t, getGeneratorInputResource(), filepath.Join(dir, "output"))
|
||||
assert.Equal(t, `apiVersion: config.kubernetes.io/v1
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
//nolint
|
||||
package funcwrappersrc
|
||||
|
||||
import (
|
||||
|
||||
@@ -22,7 +22,7 @@ rm -f $MYGOBIN/kustomize
|
||||
if [ "$version" == "HEAD" ]; then
|
||||
(cd kustomize; go install .)
|
||||
else
|
||||
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/${version}
|
||||
GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/${version}
|
||||
fi
|
||||
|
||||
# TODO: change the label?
|
||||
|
||||
@@ -243,10 +243,8 @@ func TestValidation(t *testing.T) {
|
||||
t.Errorf("%s: Expected error %s, but got %v",
|
||||
n, tc.erMsg, err)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("%s: unknown error: %v", n, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Errorf("%s: unknown error: %v", n, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
var factory = provider.NewDefaultDepProvider().GetResourceFactory()
|
||||
|
||||
func readKustomizationFS(t *testing.T, fSys filesys.FileSystem) *types.Kustomization {
|
||||
t.Helper()
|
||||
kf, err := kustfile.NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected new error %v", err)
|
||||
|
||||
@@ -68,7 +68,6 @@ func (o *addBaseOptions) RunAddBase(fSys filesys.FileSystem) error {
|
||||
return fmt.Errorf("base %s already in kustomization file", path)
|
||||
}
|
||||
m.Resources = append(m.Resources, path)
|
||||
|
||||
}
|
||||
|
||||
return mf.Write(m)
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func makeKustomization(t *testing.T) *types.Kustomization {
|
||||
t.Helper()
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
testutils_test.WriteTestKustomization(fSys)
|
||||
kf, err := kustfile.NewKustomizationFile(fSys)
|
||||
|
||||
@@ -78,11 +78,9 @@ func filesTouchedByKustomize(k *types.Kustomization, filepath string, fSys files
|
||||
}
|
||||
result = append(result, paths...)
|
||||
}
|
||||
|
||||
}
|
||||
// read the resource as a file
|
||||
result = append(result, path.Join(filepath, r))
|
||||
|
||||
}
|
||||
|
||||
// aggregate all of the paths from the `patches` field
|
||||
@@ -149,7 +147,6 @@ func findVarName(node *kyaml.RNode, varName string, path []string) ([]string, []
|
||||
var options []*types.FieldOptions
|
||||
|
||||
switch node.YNode().Kind {
|
||||
|
||||
case kyaml.SequenceNode:
|
||||
elements, err := node.Elements()
|
||||
if err != nil {
|
||||
@@ -237,7 +234,6 @@ func constructFieldOptions(value string, varString string) ([]*types.FieldOption
|
||||
|
||||
func constructTargets(file string, node *kyaml.RNode, fieldPaths []string,
|
||||
options []*types.FieldOptions) ([]*types.TargetSelector, error) {
|
||||
|
||||
if len(fieldPaths) != len(options) {
|
||||
// this should never happen
|
||||
return nil, fmt.Errorf("internal error: length of fieldPaths != length of fieldOptions")
|
||||
@@ -287,7 +283,6 @@ func constructTargets(file string, node *kyaml.RNode, fieldPaths []string,
|
||||
// resources may have different IDs than the patch
|
||||
func writePatchTargets(patch types.Patch, node *kyaml.RNode, fieldPaths []string,
|
||||
options []*types.FieldOptions) ([]*types.TargetSelector, error) {
|
||||
|
||||
var result []*types.TargetSelector
|
||||
selector := patch.Target.Copy()
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ Fixed fields:
|
||||
patchesJson6902 -> patches
|
||||
commonLabels -> labels
|
||||
vars -> replacements`)
|
||||
|
||||
} else {
|
||||
fmt.Fprintln(w, `
|
||||
Fixed fields:
|
||||
|
||||
@@ -27,6 +27,7 @@ func makeKustomizationFS() filesys.FileSystem {
|
||||
}
|
||||
|
||||
func readKustomizationFS(t *testing.T, fSys filesys.FileSystem) *types.Kustomization {
|
||||
t.Helper()
|
||||
kf, err := kustfile.NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected new error %v", err)
|
||||
@@ -39,6 +40,7 @@ func readKustomizationFS(t *testing.T, fSys filesys.FileSystem) *types.Kustomiza
|
||||
}
|
||||
|
||||
func makeKustomization(t *testing.T) *types.Kustomization {
|
||||
t.Helper()
|
||||
fSys := makeKustomizationFS()
|
||||
return readKustomizationFS(t, fSys)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ func (o *removeResourceOptions) Validate(args []string) error {
|
||||
|
||||
// RunRemoveResource runs Resource command (do real work).
|
||||
func (o *removeResourceOptions) RunRemoveResource(fSys filesys.FileSystem) error {
|
||||
|
||||
mf, err := kustfile.NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -43,6 +43,7 @@ type Case struct {
|
||||
// collection Name (e.g. transformers or resources) and newRemoveCmdToTest function.
|
||||
func ExecuteTestCases(t *testing.T, testCases []Case, collectionName string,
|
||||
newRemoveCmdToTest func(filesys.FileSystem) *cobra.Command) {
|
||||
t.Helper()
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Description, func(t *testing.T) {
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
|
||||
@@ -17,6 +17,7 @@ const invalidAnnotationKey string = "invalid annotation key: see the syntax and
|
||||
"https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/"
|
||||
|
||||
func makeAnnotationKustomization(t *testing.T) *types.Kustomization {
|
||||
t.Helper()
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
testutils_test.WriteTestKustomization(fSys)
|
||||
kf, err := kustfile.NewKustomizationFile(fSys)
|
||||
|
||||
@@ -105,7 +105,6 @@ func (o *setImageOptions) Validate(args []string) error {
|
||||
o.imageMap = make(map[string]types.Image)
|
||||
|
||||
for _, arg := range args {
|
||||
|
||||
img, err := parse(arg)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -129,7 +128,6 @@ func (o *setImageOptions) RunSetImage(fSys filesys.FileSystem) error {
|
||||
// append only new images from kustomize file
|
||||
for _, im := range m.Images {
|
||||
if argIm, ok := o.imageMap[im.Name]; ok {
|
||||
|
||||
// Reuse the existing new name when asterisk new name is passed
|
||||
if argIm.NewName == preserveSeparator {
|
||||
argIm = replaceNewName(argIm, im.NewName)
|
||||
@@ -155,7 +153,6 @@ func (o *setImageOptions) RunSetImage(fSys filesys.FileSystem) error {
|
||||
|
||||
var images []types.Image
|
||||
for _, v := range o.imageMap {
|
||||
|
||||
if v.NewName == preserveSeparator {
|
||||
v = replaceNewName(v, "")
|
||||
}
|
||||
@@ -207,7 +204,6 @@ func replaceDigest(image types.Image, digest string) types.Image {
|
||||
}
|
||||
|
||||
func parse(arg string) (types.Image, error) {
|
||||
|
||||
// matches if there is an image name to overwrite
|
||||
// <image>=<new-image><:|@><new-tag>
|
||||
if s := strings.Split(arg, separator); len(s) == 2 {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func makeKustomization(t *testing.T) *types.Kustomization {
|
||||
t.Helper()
|
||||
fSys := filesys.MakeFsInMemory()
|
||||
testutils_test.WriteTestKustomization(fSys)
|
||||
kf, err := kustfile.NewKustomizationFile(fSys)
|
||||
|
||||
@@ -69,7 +69,6 @@ func (o *setReplicasOptions) Validate(args []string) error {
|
||||
o.replicasMap = make(map[string]types.Replica)
|
||||
|
||||
for _, arg := range args {
|
||||
|
||||
replica, err := parseReplicasArg(arg)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -113,7 +112,6 @@ func (o *setReplicasOptions) RunSetReplicas(fSys filesys.FileSystem) error {
|
||||
}
|
||||
|
||||
func parseReplicasArg(arg string) (types.Replica, error) {
|
||||
|
||||
// matches a name and a replica count
|
||||
// <name>=<count>
|
||||
if s := strings.Split(arg, replicasSeparator); len(s) == 2 {
|
||||
|
||||
@@ -11,8 +11,9 @@ import (
|
||||
"log"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/language"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
"sigs.k8s.io/kustomize/api/types"
|
||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||
@@ -116,7 +117,7 @@ type kustomizationFile struct {
|
||||
}
|
||||
|
||||
// NewKustomizationFile returns a new instance.
|
||||
func NewKustomizationFile(fSys filesys.FileSystem) (*kustomizationFile, error) { // nolint
|
||||
func NewKustomizationFile(fSys filesys.FileSystem) (*kustomizationFile, error) {
|
||||
mf := &kustomizationFile{fSys: fSys}
|
||||
err := mf.validate()
|
||||
if err != nil {
|
||||
@@ -291,7 +292,8 @@ func findMatchedField(line []byte) (bool, string) {
|
||||
// an empty []byte is returned.
|
||||
func marshalField(field string, kustomization *types.Kustomization) ([]byte, error) {
|
||||
r := reflect.ValueOf(*kustomization)
|
||||
v := r.FieldByName(strings.Title(field))
|
||||
titleCaser := cases.Title(language.English, cases.NoLower)
|
||||
v := r.FieldByName(titleCaser.String(field))
|
||||
|
||||
if !v.IsValid() || isEmpty(v) {
|
||||
return []byte{}, nil
|
||||
@@ -299,7 +301,7 @@ func marshalField(field string, kustomization *types.Kustomization) ([]byte, err
|
||||
|
||||
k := &types.Kustomization{}
|
||||
kr := reflect.ValueOf(k)
|
||||
kv := kr.Elem().FieldByName(strings.Title(field))
|
||||
kv := kr.Elem().FieldByName(titleCaser.String(field))
|
||||
kv.Set(v)
|
||||
|
||||
return yaml.Marshal(k)
|
||||
|
||||
@@ -72,13 +72,14 @@ func ConvertSliceToMap(inputs []string, kind string) (map[string]string, error)
|
||||
result := make(map[string]string)
|
||||
for _, input := range inputs {
|
||||
c := strings.Index(input, ":")
|
||||
if c == 0 {
|
||||
switch {
|
||||
case c == 0:
|
||||
// key is not passed
|
||||
return nil, fmt.Errorf("invalid %s: '%s' (%s)", kind, input, "need k:v pair where v may be quoted")
|
||||
} else if c < 0 {
|
||||
case c < 0:
|
||||
// only key passed
|
||||
result[input] = ""
|
||||
} else {
|
||||
default:
|
||||
// both key and value passed
|
||||
key := input[:c]
|
||||
value := trimQuotes(input[c+1:])
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
// NewCmdOpenAPI makes a new openapi command.
|
||||
func NewCmdOpenAPI(w io.Writer) *cobra.Command {
|
||||
|
||||
openApiCmd := &cobra.Command{
|
||||
Use: "openapi",
|
||||
Short: "Commands for interacting with the OpenAPI data",
|
||||
|
||||
@@ -8,6 +8,7 @@ require (
|
||||
github.com/spf13/cobra v1.4.0
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.7.0
|
||||
golang.org/x/text v0.3.7
|
||||
sigs.k8s.io/kustomize/api v0.11.4
|
||||
sigs.k8s.io/kustomize/cmd/config v0.10.6
|
||||
sigs.k8s.io/kustomize/kyaml v0.13.6
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user