From 401cf9579c67d9c5b1a022fb551c4d8ae32324cc Mon Sep 17 00:00:00 2001 From: yugo kobayashi Date: Thu, 22 Sep 2022 12:56:15 +0000 Subject: [PATCH 1/2] update golangci-lint v1.49.0 --- .golangci.yml | 8 ++-- Makefile-tools.mk | 4 +- api/krusty/namespaces_test.go | 2 +- api/resmap/reswrangler_test.go | 2 +- api/types/helmchartargs.go | 2 +- cmd/config/internal/commands/cmdxargs.go | 2 +- cmd/config/internal/commands/e2e/e2e_test.go | 6 +-- cmd/config/internal/commands/grep.go | 3 +- .../krmfunction/funcwrapper/statik.go | 2 +- kyaml/filesys/fsnode_test.go | 2 +- kyaml/filesys/util.go | 42 +++++++++---------- kyaml/fn/framework/function_definition.go | 2 +- kyaml/fn/runtime/exec/exec.go | 2 +- kyaml/fn/runtime/runtimeutil/functiontypes.go | 7 +++- kyaml/runfn/runfn_test.go | 4 +- 15 files changed, 49 insertions(+), 41 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4def368bba..c25b1f02a2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,7 +14,6 @@ linters: - bodyclose - contextcheck # - cyclop - - deadcode - depguard - dogsled - dupl @@ -71,7 +70,6 @@ linters: - rowserrcheck - sqlclosecheck - staticcheck - - structcheck # - stylecheck - tagliatelle - tenv @@ -82,12 +80,16 @@ linters: - unconvert - unparam - unused - - varcheck # - varnamelen - wastedassign - whitespace - wrapcheck # - wsl + - asasalint + - usestdlibvars + - interfacebloat + - logrlint + - reassign linters-settings: dupl: diff --git a/Makefile-tools.mk b/Makefile-tools.mk index 351f0465c3..d336d48da1 100644 --- a/Makefile-tools.mk +++ b/Makefile-tools.mk @@ -1,6 +1,8 @@ # Copyright 2022 The Kubernetes Authors. # SPDX-License-Identifier: Apache-2.0 +GOLANGCI_LINT_VERSION=v1.49.0 + MYGOBIN = $(shell go env GOBIN) ifeq ($(MYGOBIN),) MYGOBIN = $(shell go env GOPATH)/bin @@ -28,7 +30,7 @@ uninstall-out-of-tree-tools: rm -f $(MYGOBIN)/stringer $(MYGOBIN)/golangci-lint: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) $(MYGOBIN)/mdrip: go install github.com/monopole/mdrip@v1.0.2 diff --git a/api/krusty/namespaces_test.go b/api/krusty/namespaces_test.go index 58dbb86864..b8d971a722 100644 --- a/api/krusty/namespaces_test.go +++ b/api/krusty/namespaces_test.go @@ -692,7 +692,7 @@ resources: th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput) } -// nolint:gosec +//nolint:gosec const namespaceNeedInVarMyAppWithNamespace string = ` resources: - elasticsearch-dev-service.yaml diff --git a/api/resmap/reswrangler_test.go b/api/resmap/reswrangler_test.go index d254ad9f5a..d576560868 100644 --- a/api/resmap/reswrangler_test.go +++ b/api/resmap/reswrangler_test.go @@ -301,7 +301,7 @@ func TestGetMatchingResourcesByCurrentId(t *testing.T) { t.Fatalf("Expected single map entry but got %v", result) } - // nolint:goconst + //nolint:goconst tests := []struct { name string matcher IdMatcher diff --git a/api/types/helmchartargs.go b/api/types/helmchartargs.go index 05d5404621..9c1c06aacf 100644 --- a/api/types/helmchartargs.go +++ b/api/types/helmchartargs.go @@ -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"` // nolint: tagliatelle + IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"` //nolint: tagliatelle } // HelmChartArgs contains arguments to helm. diff --git a/cmd/config/internal/commands/cmdxargs.go b/cmd/config/internal/commands/cmdxargs.go index 31d9a5f1db..135cc0de21 100644 --- a/cmd/config/internal/commands/cmdxargs.go +++ b/cmd/config/internal/commands/cmdxargs.go @@ -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]) // nolint: gosec + run := exec.Command(r.Args[0]) //nolint: gosec if len(r.Args) > 1 { r.Args = r.Args[cmdIndex+1:] diff --git a/cmd/config/internal/commands/e2e/e2e_test.go b/cmd/config/internal/commands/e2e/e2e_test.go index 45b54d7e9b..cce6e2de60 100644 --- a/cmd/config/internal/commands/e2e/e2e_test.go +++ b/cmd/config/internal/commands/e2e/e2e_test.go @@ -719,7 +719,7 @@ metadata: } args := append([]string{"fn", "run", "."}, tt.args(binDir)...) - cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...) // nolint: gosec + cmd := exec.Command(filepath.Join(binDir, kyamlBin), args...) //nolint: gosec cmd.Dir = dir var stdErr, stdOut bytes.Buffer cmd.Stdout = &stdOut @@ -761,7 +761,7 @@ func build() string { panic(err) } - build := exec.Command("go", "build", "-o", // nolint: gosec + build := exec.Command("go", "build", "-o", //nolint: gosec filepath.Join(binDir, e2econtainerconfigBin)) build.Dir = "e2econtainerconfig" build.Stdout = os.Stdout @@ -773,7 +773,7 @@ func build() string { panic(err) } - build = exec.Command("go", "build", "-o", filepath.Join(binDir, kyamlBin)) // nolint: gosec + 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 diff --git a/cmd/config/internal/commands/grep.go b/cmd/config/internal/commands/grep.go index 82846ac7bb..54659f5100 100644 --- a/cmd/config/internal/commands/grep.go +++ b/cmd/config/internal/commands/grep.go @@ -1,6 +1,5 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -// package commands import ( @@ -100,7 +99,7 @@ func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error { r.Value = last[1] } - r.Path = append(parts[:len(parts)-1], last[0]) // nolint:gocritic + r.Path = append(parts[:len(parts)-1], last[0]) //nolint:gocritic return nil } diff --git a/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go b/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go index 30d93ff364..0473a714f2 100644 --- a/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go +++ b/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go @@ -8,7 +8,7 @@ import ( func init() { - data := "PK\x03\x04\x14\x00\x08\x00\x08\x00H\x08\x1aU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00 \x00go.mod.srcUT\x05\x00\x01\x98\x1b\x08ct\xca\xb1\x0e\xc2 \x10\x06\xe0\xb9\xf7\x14\x8c\xba\xfc\x80U\xa3\x8fC+\xe2\x85\xe2U\xae4\xd1\xa77\xc6\xc9\xc1\xf9\xfb\x8a\\\xda\x14M |'Jb<\xfc\x81\xa8\xc6G\xe3\x1a\xcd\x86\xba\xc4\xcb\xad\x0d\x18\xa5X\x9d\xaf\xbe\xb7\xa3\x0c5\x98\xd5\xc3\xc1Q\xa7\x9c\x14\xf9\xa4`\xb1\xb9\xe9\"\x85_\xd1\x86\x99\xcd\xeap\xc4\xfe\xdf\xc8\xcfP\xa6\xcf9\xa3\xff=_\xf0\xd8\xc1\xd1\x96\xe8\x1d\x00\x00\xff\xffPK\x07\x08`;Y\xf4u\x00\x00\x00\xa1\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00l\xab\xc2T\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00 \x00main.goUT\x05\x00\x01<+\x99b\x94R\xc1n\xe36\x10=\x93_1\xd5\xa1\xa0\n\x87\xda\xfaT\xec\xc2\x87\xc5z\xbd]4 \x8c$\x08\n\x14=\xd0\xd2H&L\x91\xc4\x90\x8a\xe3\x16\xfe\xf7\x82\x92\xec\xd8i\x12d\xaf\xe4\x9b\xf7\xe6\xbdyE\x01_\x9c\xdf\x91n\xd6\x11\xa6\x1f\xa6S\xb8[#\xfc\xd1\xad\x90,F\x0c\xf0\xb9\x8bk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xc8>C\x91\xa5\xa1,\x97\xfd\x9c\xbc\x8d\xa4m#\xde'\xc8\x19K\x88\xd9X\xa1\xb1;\xe2\xec\xa2\x13\xf8\xeb\xef\xd5.\xa28\xee\x96\xbf\x8f\xbc\xc7\xc4 \xb8M\xdf\xc1AA\x8c\xe5\xb8#eC\xed\xa8E\x1aN\x9b\x7fJ\xc0\x9egX)>a\xc4p\x85$\xfb\x92\xee\xb9p\xaf\xbc\x074\x01A\xd7\xd0\xbc\xb2\xc07\xb4H\xa9z\xff\x93?=\xf9\x0c\x9a\x03\x12\xc5\x8f\xe8\xf3\xa1;\xcfj\x00\xfd=\xaf\x92\x7fw\xd2\x97\x9c\x1f9\xac6\x9c\xeds~\xd09\xeb\xf6\xd7G,\xbb\x88\xe2\xe7c\xf7'i \xff\xf4|\xa5\xba\x8drI\xdaFc\x05\x12%~\x17\xe4\xd7G\x1d\xc5\xaf9g{\xbe\xe7\xff\x05\x00\x00\xff\xffPK\x07\x08P\xaa\x84\xd0\x8f\x02\x00\x00\xaa\x05\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00H\x08\x1aU`;Y\xf4u\x00\x00\x00\xa1\x00\x00\x00\n\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00go.mod.srcUT\x05\x00\x01\x98\x1b\x08cPK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00l\xab\xc2TP\xaa\x84\xd0\x8f\x02\x00\x00\xaa\x05\x00\x00\x07\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\x81\xb6\x00\x00\x00main.goUT\x05\x00\x01<+\x99bPK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x7f\x00\x00\x00\x83\x03\x00\x00\x00\x00" + data := "PK\x03\x04\x14\x00\x08\x00\x08\x00qa6U\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00 \x00go.mod.srcUT\x05\x00\x01\xf7P,ct\xca\xb1\x0e\xc2 \x10\x06\xe0\xb9\xf7\x14\x8c\xba\xfc\x80U\xa3\x8fC+\xe2\x85\xe2U\xae4\xd1\xa77\xc6\xc9\xc1\xf9\xfb\x8a\\\xda\x14M |'Jb<\xfc\x81\xa8\xc6G\xe3\x1a\xcd\x86\xba\xc4\xcb\xad\x0d\x18\xa5X\x9d\xaf\xbe\xb7\xa3\x0c5\x98\xd5\xc3\xc1Q\xa7\x9c\x14\xf9\xa4`\xb1\xb9\xe9\"\x85_\xd1\x86\x99\xcd\xeap\xc4\xfe\xdf\xc8\xcfP\xa6\xcf9\xa3\xff=_\xf0\xd8\xc1\xd1\x96\xe8\x1d\x00\x00\xff\xffPK\x07\x08`;Y\xf4u\x00\x00\x00\xa1\x00\x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00qa6U\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00 \x00main.goUT\x05\x00\x01\xf7P,c\x94R\xc1n\xe36\x10=\x93_1\xd5\xa1\xa0\n\x87\xda\xfaT\xec\xc2\x87\xc5z\xbd]4 \x8c$\x08\n\x14=\xd0\xd2H&L\x91\xc4\x90\x8a\xe3\x16\xfe\xf7\x82\x92\xec\xd8i\x12d\xaf\xe4\x9b\xf7\xe6\xbdyE\x01_\x9c\xdf\x91n\xd6\x11\xa6\x1f\xa6S\xb8[#\xfc\xd1\xad\x90,F\x0c\xf0\xb9\x8bkGA\xf2\xa2\x80\xdb\xe5\xfc\xcf\x8bK]\xa2\x0dx\xf1\xbdB\x1bu\xad\x91>\xc2g\xaf\xca5^L\xe5\x07\x9epwk\x1d\xa0\xd6\x06a\xab\x8d\x81\x15\x82'Wb\x08X\x81\xb2\x15`\xbb\xc2\xaa\xc2\n\xa2\x03o\xbaF[\x15\x1dI\xce\xbd*7\xaaA\xa8;[nIy\x8f\x14\xa8\xe4\\\xb7\xdeQ\x04\xc1YV\xb71\xe3,s!\xe3\x9ceA7An~\x0bR\xbbb\xd3\x85\xe8Z\xfd\x0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x8f\xe8\xf3\xa1;\xcfj\x00\xfd=\xaf\x92\x7fw\xd2\x97\x9c\x1f9\xac6\x9c\xeds~\xd09\xeb\xf6\xd7G,\xbb\x88\xe2\xe7c\xf7'i \xff\xf4|\xa5\xba\x8drI\xdaFc\x05\x12%~\x17\xe4\xd7G\x1d\xc5\xaf9g{\xbe\xe7\xff\x05\x00\x00\xff\xffPK\x07\x08P\xaa\x84\xd0\x8f\x02\x00\x00\xaa\x05\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00qa6U`;Y\xf4u\x00\x00\x00\xa1\x00\x00\x00\n\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00go.mod.srcUT\x05\x00\x01\xf7P,cPK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00qa6UP\xaa\x84\xd0\x8f\x02\x00\x00\xaa\x05\x00\x00\x07\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\xb6\x00\x00\x00main.goUT\x05\x00\x01\xf7P,cPK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x7f\x00\x00\x00\x83\x03\x00\x00\x00\x00" fs.Register(data) } \ No newline at end of file diff --git a/kyaml/filesys/fsnode_test.go b/kyaml/filesys/fsnode_test.go index 233c5b6e1f..d41306ed6b 100644 --- a/kyaml/filesys/fsnode_test.go +++ b/kyaml/filesys/fsnode_test.go @@ -903,7 +903,7 @@ func TestFileOps(t *testing.T) { defer f.Close() for { - buf := make([]byte, rand.Intn(10)) // nolint:gosec + buf := make([]byte, rand.Intn(10)) //nolint:gosec n, err := f.Read(buf) if err != nil && err != io.EOF { t.Fatalf("unexpected error: %v", err) diff --git a/kyaml/filesys/util.go b/kyaml/filesys/util.go index fdbe5e2c70..b5ee3dd876 100644 --- a/kyaml/filesys/util.go +++ b/kyaml/filesys/util.go @@ -74,30 +74,30 @@ func PathJoin(incoming []string) string { // // E.g. if part == 'PEACH' // -// OLD : NEW : POS -// -------------------------------------------------------- -// {empty} : PEACH : irrelevant -// / : /PEACH : irrelevant -// pie : PEACH/pie : 0 (or negative) -// /pie : /PEACH/pie : 0 (or negative) -// raw : raw/PEACH : 1 (or larger) -// /raw : /raw/PEACH : 1 (or larger) -// a/nice/warm/pie : a/nice/warm/PEACH/pie : 3 -// /a/nice/warm/pie : /a/nice/warm/PEACH/pie : 3 +// OLD : NEW : POS +// -------------------------------------------------------- +// {empty} : PEACH : irrelevant +// / : /PEACH : irrelevant +// pie : PEACH/pie : 0 (or negative) +// /pie : /PEACH/pie : 0 (or negative) +// raw : raw/PEACH : 1 (or larger) +// /raw : /raw/PEACH : 1 (or larger) +// a/nice/warm/pie : a/nice/warm/PEACH/pie : 3 +// /a/nice/warm/pie : /a/nice/warm/PEACH/pie : 3 // // * An empty part results in no change. // -// * Absolute paths get their leading '/' stripped, treated like -// relative paths, and the leading '/' is re-added on output. -// The meaning of pos is intentionally the same in either absolute or -// relative paths; if it weren't, this function could convert absolute -// paths to relative paths, which is not desirable. +// - Absolute paths get their leading '/' stripped, treated like +// relative paths, and the leading '/' is re-added on output. +// The meaning of pos is intentionally the same in either absolute or +// relative paths; if it weren't, this function could convert absolute +// paths to relative paths, which is not desirable. // -// * For robustness (liberal input, conservative output) Pos values that -// that are too small (large) to index the split filepath result in a -// prefix (postfix) rather than an error. Use extreme position values -// to assure a prefix or postfix (e.g. 0 will always prefix, and -// 9999 will presumably always postfix). +// - For robustness (liberal input, conservative output) Pos values that +// that are too small (large) to index the split filepath result in a +// prefix (postfix) rather than an error. Use extreme position values +// to assure a prefix or postfix (e.g. 0 will always prefix, and +// 9999 will presumably always postfix). func InsertPathPart(path string, pos int, part string) string { if part == "" { return path @@ -121,7 +121,7 @@ func InsertPathPart(path string, pos int, part string) string { result := make([]string, len(parts)+1) copy(result, parts[0:pos]) result[pos] = part - return PathJoin(append(result, parts[pos:]...)) // nolint: makezero + return PathJoin(append(result, parts[pos:]...)) //nolint: makezero } func IsHiddenFilePath(pattern string) bool { diff --git a/kyaml/fn/framework/function_definition.go b/kyaml/fn/framework/function_definition.go index 6832198965..eb930adbb6 100644 --- a/kyaml/fn/framework/function_definition.go +++ b/kyaml/fn/framework/function_definition.go @@ -82,7 +82,7 @@ type KRMFunctionVersion struct { type KRMFunctionValidation struct { // OpenAPIV3Schema is the OpenAPI v3 schema for an instance of the KRM function. - OpenAPIV3Schema *spec.Schema `yaml:"openAPIV3Schema,omitempty" json:"openAPIV3Schema,omitempty"` // nolint: tagliatelle + OpenAPIV3Schema *spec.Schema `yaml:"openAPIV3Schema,omitempty" json:"openAPIV3Schema,omitempty"` //nolint: tagliatelle } type KRMFunctionNames struct { diff --git a/kyaml/fn/runtime/exec/exec.go b/kyaml/fn/runtime/exec/exec.go index e9546820fc..8bb3fe12e6 100644 --- a/kyaml/fn/runtime/exec/exec.go +++ b/kyaml/fn/runtime/exec/exec.go @@ -34,7 +34,7 @@ func (c *Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) { } func (c *Filter) Run(reader io.Reader, writer io.Writer) error { - cmd := exec.Command(c.Path, c.Args...) // nolint:gosec + cmd := exec.Command(c.Path, c.Args...) //nolint:gosec cmd.Stdin = reader cmd.Stdout = writer cmd.Stderr = os.Stderr diff --git a/kyaml/fn/runtime/runtimeutil/functiontypes.go b/kyaml/fn/runtime/runtimeutil/functiontypes.go index de3ee90490..c25ba4a6a0 100644 --- a/kyaml/fn/runtime/runtimeutil/functiontypes.go +++ b/kyaml/fn/runtime/runtimeutil/functiontypes.go @@ -204,7 +204,7 @@ func (s *StorageMount) String() string { func GetFunctionSpec(n *yaml.RNode) (*FunctionSpec, error) { meta, err := n.GetMeta() if err != nil { - return nil, nil + return nil, fmt.Errorf("failed to get ResourceMeta: %w", err) } fn, err := getFunctionSpecFromAnnotation(n, meta) @@ -237,7 +237,10 @@ func getFunctionSpecFromAnnotation(n *yaml.RNode, meta yaml.ResourceMeta) (*Func } } n, err := n.Pipe(yaml.Lookup("metadata", "configFn")) - if err != nil || yaml.IsMissingOrNull(n) { + if err != nil { + return nil, fmt.Errorf("failed to LookUp configFn: %w", err) + } + if yaml.IsMissingOrNull(n) { return nil, nil } s, err := n.String() diff --git a/kyaml/runfn/runfn_test.go b/kyaml/runfn/runfn_test.go index 0ea0779df5..ad7f6c9e21 100644 --- a/kyaml/runfn/runfn_test.go +++ b/kyaml/runfn/runfn_test.go @@ -281,7 +281,8 @@ metadata: out: []string{"gcr.io/example.com/image:v1.0.0"}, }, - {name: "no function spec", + { + name: "no function spec", in: []f{ { explicitFunction: true, @@ -290,6 +291,7 @@ foo: bar `, }, }, + error: "failed to get FunctionSpec: failed to get ResourceMeta: missing Resource metadata", }, // Test From 6ce230f2b2163f19b41edb54cfd3c0218ba8c1c7 Mon Sep 17 00:00:00 2001 From: yugo kobayashi Date: Fri, 23 Sep 2022 07:14:21 +0000 Subject: [PATCH 2/2] fix testcases on runfn_test.go --- kyaml/fn/runtime/runtimeutil/functiontypes.go | 2 +- kyaml/runfn/runfn_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kyaml/fn/runtime/runtimeutil/functiontypes.go b/kyaml/fn/runtime/runtimeutil/functiontypes.go index c25ba4a6a0..f0448ea28d 100644 --- a/kyaml/fn/runtime/runtimeutil/functiontypes.go +++ b/kyaml/fn/runtime/runtimeutil/functiontypes.go @@ -238,7 +238,7 @@ func getFunctionSpecFromAnnotation(n *yaml.RNode, meta yaml.ResourceMeta) (*Func } n, err := n.Pipe(yaml.Lookup("metadata", "configFn")) if err != nil { - return nil, fmt.Errorf("failed to LookUp configFn: %w", err) + return nil, fmt.Errorf("failed to look up metadata.configFn: %w", err) } if yaml.IsMissingOrNull(n) { return nil, nil diff --git a/kyaml/runfn/runfn_test.go b/kyaml/runfn/runfn_test.go index ad7f6c9e21..dbd2d6f0af 100644 --- a/kyaml/runfn/runfn_test.go +++ b/kyaml/runfn/runfn_test.go @@ -287,6 +287,21 @@ metadata: { explicitFunction: true, value: ` +apiVersion: example.com/v1alpha1 +kind: ExampleFunction +metadata: + annotations: + foo: bar +`, + }, + }, + }, + { + name: "invalid input object", + in: []f{ + { + explicitFunction: true, + value: ` foo: bar `, },