From 7f9f6140ffba39f50a9c24623705cbb3f4c32257 Mon Sep 17 00:00:00 2001 From: Katrina Verey Date: Wed, 23 Nov 2022 20:34:38 -0500 Subject: [PATCH] Get rid of statik and fix failing tests --- Makefile-tools.mk | 3 -- cmd/pluginator/Makefile | 16 +++------ cmd/pluginator/go.mod | 1 - cmd/pluginator/go.sum | 2 -- .../internal/krmfunction/converter.go | 15 ++++----- .../internal/krmfunction/converter_test.go | 33 +++++++++++-------- .../krmfunction/funcwrapper/statik.go | 14 -------- .../krmfunction/funcwrappersrc/go.mod.src | 8 ++--- 8 files changed, 34 insertions(+), 58 deletions(-) delete mode 100644 cmd/pluginator/internal/krmfunction/funcwrapper/statik.go diff --git a/Makefile-tools.mk b/Makefile-tools.mk index 8bc5fb5d8..45a678950 100644 --- a/Makefile-tools.mk +++ b/Makefile-tools.mk @@ -47,9 +47,6 @@ $(MYGOBIN)/mdtogo: $(MYGOBIN)/addlicense: go install github.com/google/addlicense@latest -$(MYGOBIN)/statik: - go install github.com/rakyll/statik@latest - $(MYGOBIN)/goreleaser: go install github.com/goreleaser/goreleaser@v0.179.0 # https://github.com/kubernetes-sigs/kustomize/issues/4542 diff --git a/cmd/pluginator/Makefile b/cmd/pluginator/Makefile index e15fbb018..74ab6dbc1 100644 --- a/cmd/pluginator/Makefile +++ b/cmd/pluginator/Makefile @@ -1,4 +1,4 @@ -.PHONY: statik test all clean generate run +.PHONY: test all clean generate run FUNC_WRAPPER_SRC_DIR = funcwrappersrc FUNC_WRAPPER_DST_DIR = funcwrapper @@ -7,22 +7,16 @@ include ../../Makefile-modules.mk all: test build -test: generate +test: go test -v ./... -generate: $(MYGOBIN)/statik - ( \ - cd internal/krmfunction; \ - $(MYGOBIN)/statik -src=$(FUNC_WRAPPER_SRC_DIR) -f -p $(FUNC_WRAPPER_DST_DIR) -include=main.go,go.mod.src \ - ) - -build: generate +build: go build -o $(MYGOBIN) main.go -install: generate +install: go install . -run: generate +run: go run . $(ARGS) clean: diff --git a/cmd/pluginator/go.mod b/cmd/pluginator/go.mod index 9284b9080..109e79c0b 100644 --- a/cmd/pluginator/go.mod +++ b/cmd/pluginator/go.mod @@ -3,7 +3,6 @@ module sigs.k8s.io/kustomize/cmd/pluginator/v2 go 1.19 require ( - github.com/rakyll/statik v0.1.7 github.com/spf13/cobra v1.4.0 github.com/stretchr/testify v1.8.0 sigs.k8s.io/kustomize/api v0.12.1 diff --git a/cmd/pluginator/go.sum b/cmd/pluginator/go.sum index 117dbb82f..500c6d0e2 100644 --- a/cmd/pluginator/go.sum +++ b/cmd/pluginator/go.sum @@ -93,8 +93,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= -github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= diff --git a/cmd/pluginator/internal/krmfunction/converter.go b/cmd/pluginator/internal/krmfunction/converter.go index 57c8c419c..3fe1a9539 100644 --- a/cmd/pluginator/internal/krmfunction/converter.go +++ b/cmd/pluginator/internal/krmfunction/converter.go @@ -6,17 +6,18 @@ package krmfunction import ( "bufio" "bytes" + "embed" "fmt" "io" "os" "path/filepath" "strings" - - "github.com/rakyll/statik/fs" - // load embedded func wrapper - _ "sigs.k8s.io/kustomize/cmd/pluginator/v2/internal/krmfunction/funcwrapper" ) +//go:embed funcwrappersrc/go.mod.src +//go:embed funcwrappersrc/main.go +var fs embed.FS + // Converter is a converter to convert the // plugin file to KRM function type Converter struct { @@ -122,11 +123,7 @@ func (c *Converter) prepareWrapper(content string) string { // readEmbeddedFile read the file from embedded files with filename // name. Return the file content if it's successful. func (c *Converter) readEmbeddedFile(name string) (string, error) { - statikFS, err := fs.New() - if err != nil { - return "", err - } - r, err := statikFS.Open("/" + name) + r, err := fs.Open("funcwrappersrc/" + name) if err != nil { return "", err } diff --git a/cmd/pluginator/internal/krmfunction/converter_test.go b/cmd/pluginator/internal/krmfunction/converter_test.go index bd783927e..f767eecea 100644 --- a/cmd/pluginator/internal/krmfunction/converter_test.go +++ b/cmd/pluginator/internal/krmfunction/converter_test.go @@ -47,7 +47,7 @@ func (p *plugin) Transform(rm resmap.ResMap) error { return nil } for _, r := range rm.Resources() { - if r.IsEmpty() { + if r.IsNilOrEmpty() { // Don't mutate empty objects? continue } @@ -97,23 +97,26 @@ 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 - ob := bytes.NewBuffer([]byte{}) - cmd.Stdout = ob - eb := bytes.NewBuffer([]byte{}) - cmd.Stderr = eb - cmd.Dir = dir - err := cmd.Run() - if !assert.NoErrorf(t, err, "Stdout:\n%s\nStderr:\n%s\n", ob.String(), eb.String()) { - t.FailNow() + prepareCmd := func(name string, arg ...string) (*exec.Cmd, *bytes.Buffer, *bytes.Buffer) { + ob := bytes.NewBuffer([]byte{}) + eb := bytes.NewBuffer([]byte{}) + cmd := exec.Command(name, arg...) + cmd.Stdout = ob + cmd.Stderr = eb + cmd.Dir = dir + return cmd, ob, eb } + cmd, ob, eb := prepareCmd("go", "mod", "tidy") + require.NoErrorf(t, cmd.Run(), "Stdout:\n%s\nStderr:\n%s\n", ob.String(), eb.String()) + + cmd, ob, eb = prepareCmd("go", "run", ".") + cmd.Stdin = bytes.NewReader(input) + require.NoErrorf(t, cmd.Run(), "Stdout:\n%s\nStderr:\n%s\n", ob.String(), eb.String()) + return ob.Bytes() } func TestTransformerConverter(t *testing.T) { - t.Skip("TODO: fix this test, which was not running in CI and does not pass") dir := t.TempDir() err := os.WriteFile(filepath.Join(dir, "Plugin.go"), @@ -211,7 +214,6 @@ items: [] } func TestGeneratorConverter(t *testing.T) { - t.Skip("TODO: fix this test, which was not running in CI and does not pass") dir := t.TempDir() err := os.WriteFile(filepath.Join(dir, "Plugin.go"), @@ -231,6 +233,9 @@ items: kind: ConfigMap metadata: name: staging + annotations: + internal.config.kubernetes.io/generatorBehavior: unspecified + internal.config.kubernetes.io/needsHashSuffix: enabled functionConfig: apiVersion: foo-corp.com/v1 kind: FulfillmentCenter diff --git a/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go b/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go deleted file mode 100644 index 9382ea6d5..000000000 --- a/cmd/pluginator/internal/krmfunction/funcwrapper/statik.go +++ /dev/null @@ -1,14 +0,0 @@ -// Code generated by statik. DO NOT EDIT. - -package funcwrapper - -import ( - "github.com/rakyll/statik/fs" -) - - -func init() { - data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\xa8\x89LU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00 \x00go.mod.srcUT\x05\x00\x01\xad\xf5Fct\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\xe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8drI\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\x00\xa8\x89LU`;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\xad\xf5FcPK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\xa8\x89LUP\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\xad\xf5FcPK\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/cmd/pluginator/internal/krmfunction/funcwrappersrc/go.mod.src b/cmd/pluginator/internal/krmfunction/funcwrappersrc/go.mod.src index 7c5a68f7a..0c5b0f482 100644 --- a/cmd/pluginator/internal/krmfunction/funcwrappersrc/go.mod.src +++ b/cmd/pluginator/internal/krmfunction/funcwrappersrc/go.mod.src @@ -1,11 +1,11 @@ module main -go 1.15 +go 1.19 require ( - github.com/spf13/cobra v1.0.0 - sigs.k8s.io/kustomize/api v0.6.4 - sigs.k8s.io/kustomize/kyaml v0.9.3 + github.com/spf13/cobra v1.4.0 + sigs.k8s.io/kustomize/api v0.12.1 + sigs.k8s.io/kustomize/kyaml v0.13.9 sigs.k8s.io/yaml v1.2.0 )