From 532abf77e783a1013416f01e841549386411be11 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Sun, 27 Aug 2023 23:16:55 +0700 Subject: [PATCH 1/6] refactor: fix generate-kustimize-builtin-plugins, add diff checker on generate-kustomize-builtin-plugins, add go work sync on presubmit check, add generate-kustomize-builtin-plugins on presubmit check --- 0 | 1 + Makefile | 12 +++++++++++- Makefile-plugins.mk | 20 +++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 0 diff --git a/0 b/0 new file mode 100644 index 0000000000..6d34a2e5ed --- /dev/null +++ b/0 @@ -0,0 +1 @@ + 1607 diff --git a/Makefile b/Makefile index e50ebf4450..e3a399bc45 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,9 @@ prow-presubmit-check: \ test-go-mod \ build-non-plugin-all \ test-examples-kustomize-against-HEAD \ - test-examples-kustomize-against-latest-release + test-examples-kustomize-against-latest-release \ + workspace-sync \ + generate-kustomize-builtin-plugins .PHONY: license license: $(MYGOBIN)/addlicense @@ -181,7 +183,15 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip ./hack/testExamplesAgainstKustomize.sh v5@$(LATEST_RELEASE) +.PHONY: generate-kustomize-builtin-plugins +generate-kustomize-builtin-plugins: + $(MAKE) -f Makefile-plugin.mk +# Pushes dependencies in the go.work file back to go.mod files of each workspace module. +.PHONY: workspace-sync +workspace sync: + go work sync + # --- Cleanup targets --- .PHONY: clean clean: clean-kustomize-external-go-plugin uninstall-tools diff --git a/Makefile-plugins.mk b/Makefile-plugins.mk index 6cc49b3880..172c708739 100644 --- a/Makefile-plugins.mk +++ b/Makefile-plugins.mk @@ -91,7 +91,25 @@ $(pGen)/%.go: $(MYGOBIN)/pluginator $(MYGOBIN)/goimports # Target is for debugging. .PHONY: generate-kustomize-builtin-plugins -generate-kustomize-builtin-plugins: $(builtinplugins) +generate-kustomize-builtin-plugins: $(builtplugins) + for plugin in $(abspath $(wildcard $(pSrc)/*)); do \ + echo "generating $${plugin} ..."; \ + set -e; \ + cd $${plugin}; \ + go generate pluginator .; \ + done; \ + cd ../../../; \ + make no-diff \ + +.PHONY: no-diff +no-diff: $(builtplugins) + for file in $(abspath $(builtinplugins)); do \ + echo "Checking for diff... $${file}" ; \ + set -e ; \ + if [ "`git diff $${file} | wc -c`" -gt 0 ]; then\ + echo "Error(1): diff found on $${file}"; exit 1; \ + fi \ + done .PHONY: build-kustomize-external-go-plugin build-kustomize-external-go-plugin: From d78fe665a727da4da8e02b7be015fcbf5aaaf92b Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Wed, 30 Aug 2023 19:09:36 +0700 Subject: [PATCH 2/6] add commentaries, change command order on presubmit-check --- Makefile | 10 +++------- Makefile-plugins.mk | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e3a399bc45..d7a328ee7e 100644 --- a/Makefile +++ b/Makefile @@ -108,13 +108,13 @@ verify-kustomize-repo: \ .PHONY: prow-presubmit-check prow-presubmit-check: \ install-tools \ + workspace-sync \ + generate-kustomize-builtin-plugins \ test-unit-kustomize-plugins \ test-go-mod \ build-non-plugin-all \ test-examples-kustomize-against-HEAD \ - test-examples-kustomize-against-latest-release \ - workspace-sync \ - generate-kustomize-builtin-plugins + test-examples-kustomize-against-latest-release .PHONY: license license: $(MYGOBIN)/addlicense @@ -183,10 +183,6 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip ./hack/testExamplesAgainstKustomize.sh v5@$(LATEST_RELEASE) -.PHONY: generate-kustomize-builtin-plugins -generate-kustomize-builtin-plugins: - $(MAKE) -f Makefile-plugin.mk - # Pushes dependencies in the go.work file back to go.mod files of each workspace module. .PHONY: workspace-sync workspace sync: diff --git a/Makefile-plugins.mk b/Makefile-plugins.mk index 172c708739..7b45708830 100644 --- a/Makefile-plugins.mk +++ b/Makefile-plugins.mk @@ -101,6 +101,7 @@ generate-kustomize-builtin-plugins: $(builtplugins) cd ../../../; \ make no-diff \ +# Check for diff, if diff is found, throw error code 1 (subject to change based on discussion) .PHONY: no-diff no-diff: $(builtplugins) for file in $(abspath $(builtinplugins)); do \ From 8f283499e98b39cd73adb13b6af1715a08585225 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Thu, 31 Aug 2023 15:17:06 +0700 Subject: [PATCH 3/6] add go mod tidy before workspace sync --- 0 | 1 - Makefile | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 0 diff --git a/0 b/0 deleted file mode 100644 index 6d34a2e5ed..0000000000 --- a/0 +++ /dev/null @@ -1 +0,0 @@ - 1607 diff --git a/Makefile b/Makefile index d7a328ee7e..b671a26880 100644 --- a/Makefile +++ b/Makefile @@ -186,6 +186,7 @@ test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip # Pushes dependencies in the go.work file back to go.mod files of each workspace module. .PHONY: workspace-sync workspace sync: + go mod tidy go work sync # --- Cleanup targets --- From a90c19d5775a58b203d5a8753e160727176fc4b0 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Sun, 17 Sep 2023 00:23:32 +0700 Subject: [PATCH 4/6] Edit commentaries and ensure pluginator logic does not create diff --- Makefile-plugins.mk | 4 ++-- cmd/pluginator/internal/builtinplugin/builtinplugin.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile-plugins.mk b/Makefile-plugins.mk index 7b45708830..b0c4e144e4 100644 --- a/Makefile-plugins.mk +++ b/Makefile-plugins.mk @@ -89,7 +89,7 @@ $(pGen)/%.go: $(MYGOBIN)/pluginator $(MYGOBIN)/goimports $(MYGOBIN)/goimports -w $*.go \ ) -# Target is for debugging. +# Generate builtin plugins .PHONY: generate-kustomize-builtin-plugins generate-kustomize-builtin-plugins: $(builtplugins) for plugin in $(abspath $(wildcard $(pSrc)/*)); do \ @@ -101,7 +101,7 @@ generate-kustomize-builtin-plugins: $(builtplugins) cd ../../../; \ make no-diff \ -# Check for diff, if diff is found, throw error code 1 (subject to change based on discussion) +# Check for diff, if diff is found, throw error code 1 .PHONY: no-diff no-diff: $(builtplugins) for file in $(abspath $(builtinplugins)); do \ diff --git a/cmd/pluginator/internal/builtinplugin/builtinplugin.go b/cmd/pluginator/internal/builtinplugin/builtinplugin.go index e6d66b8b0f..af97000d28 100644 --- a/cmd/pluginator/internal/builtinplugin/builtinplugin.go +++ b/cmd/pluginator/internal/builtinplugin/builtinplugin.go @@ -62,7 +62,6 @@ func ConvertToBuiltInPlugin() (retErr error) { w.write( fmt.Sprintf( "// pluginator %s\n", provenance.GetProvenance().Short())) - w.write("\n") w.write("package " + packageForGeneratedCode) pType := unknown @@ -73,6 +72,8 @@ func ConvertToBuiltInPlugin() (retErr error) { continue } if strings.HasPrefix(l, "var "+konfig.PluginSymbol+" plugin") { + // Hack to skip leading new line + scanner.Scan() continue } if strings.Contains(l, " Transform(") { @@ -93,7 +94,7 @@ func ConvertToBuiltInPlugin() (retErr error) { } w.write("") w.write("func New" + root + "Plugin() resmap." + pType.String() + "Plugin {") - w.write(" return &" + root + "Plugin{}") + w.write(" return &" + root + "Plugin{}") w.write("}") return nil From 9e101ee97fadfa043fdbff4e55ab74eb661e6c6b Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Mon, 18 Sep 2023 23:17:11 +0700 Subject: [PATCH 5/6] use doGoMod.sh forr go mod tidy --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b671a26880..ec77220d4a 100644 --- a/Makefile +++ b/Makefile @@ -186,8 +186,8 @@ test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip # Pushes dependencies in the go.work file back to go.mod files of each workspace module. .PHONY: workspace-sync workspace sync: - go mod tidy go work sync + ./hack/doGoMod.sh tidy # --- Cleanup targets --- .PHONY: clean From d91ea65f5a9fc200346016d78ac3d7d006b8d1f9 Mon Sep 17 00:00:00 2001 From: Kurnianto Trilaksono Date: Thu, 28 Sep 2023 21:49:57 +0700 Subject: [PATCH 6/6] separate generate plugins and check diff step --- Makefile | 3 ++- Makefile-plugins.mk | 11 +++++------ plugin/builtin/patchtransformer/go.mod | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ec77220d4a..20749393be 100644 --- a/Makefile +++ b/Makefile @@ -110,6 +110,7 @@ prow-presubmit-check: \ install-tools \ workspace-sync \ generate-kustomize-builtin-plugins \ + builtin-plugins-diff \ test-unit-kustomize-plugins \ test-go-mod \ build-non-plugin-all \ @@ -185,7 +186,7 @@ test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip # Pushes dependencies in the go.work file back to go.mod files of each workspace module. .PHONY: workspace-sync -workspace sync: +workspace-sync: go work sync ./hack/doGoMod.sh tidy diff --git a/Makefile-plugins.mk b/Makefile-plugins.mk index b0c4e144e4..a1edf91bdc 100644 --- a/Makefile-plugins.mk +++ b/Makefile-plugins.mk @@ -97,13 +97,12 @@ generate-kustomize-builtin-plugins: $(builtplugins) set -e; \ cd $${plugin}; \ go generate pluginator .; \ - done; \ - cd ../../../; \ - make no-diff \ + done -# Check for diff, if diff is found, throw error code 1 -.PHONY: no-diff -no-diff: $(builtplugins) +# Check for diff by comparing current revision of generated plugins on HEAD and newly generated plugins on local branch, +# If diff is found, throw error code 1 +.PHONY: builtin-plugins-diff +builtin-plugins-diff: $(builtplugins) for file in $(abspath $(builtinplugins)); do \ echo "Checking for diff... $${file}" ; \ set -e ; \ diff --git a/plugin/builtin/patchtransformer/go.mod b/plugin/builtin/patchtransformer/go.mod index d4f313b023..c182bdb28a 100644 --- a/plugin/builtin/patchtransformer/go.mod +++ b/plugin/builtin/patchtransformer/go.mod @@ -3,6 +3,7 @@ module sigs.k8s.io/kustomize/plugin/builtin/patchtransformer go 1.20 require ( + github.com/stretchr/testify v1.8.1 gopkg.in/evanphx/json-patch.v5 v5.6.0 sigs.k8s.io/kustomize/api v0.14.0 sigs.k8s.io/kustomize/kyaml v0.14.3 @@ -26,7 +27,6 @@ require ( github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.8.1 // indirect github.com/xlab/treeprint v1.2.0 // indirect go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect golang.org/x/sys v0.8.0 // indirect