From 6cfea18c506061e7fcf1e984f3cf3b1b6b7b8e82 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Sun, 19 Jun 2022 08:29:44 +0100 Subject: [PATCH] :warning: (kustomize/v1,go/v3): upgrade kustomize 3.x to 4x and add test to ensure backwords compability --- Makefile | 1 + pkg/plugins/common/kustomize/v1/plugin.go | 2 +- .../test_kustomize_compatibilit_3x.sh | 68 +++++++++++++++++++ testdata/project-v3-addon/Makefile | 2 +- testdata/project-v3-config/Makefile | 2 +- testdata/project-v3-multigroup/Makefile | 2 +- testdata/project-v3/Makefile | 2 +- 7 files changed, 74 insertions(+), 5 deletions(-) create mode 100755 test/testdata/test_kustomize_compatibilit_3x.sh diff --git a/Makefile b/Makefile index dec18746694..6df78e7181b 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,7 @@ check-testdata: ## Run the script to ensure that the testdata is updated .PHONY: test-testdata test-testdata: ## Run the tests of the testdata directory ./test/testdata/test.sh + ./test/test_kustomize_compatibilit_3x.sh #todo(remove the test-legacy whne the go/v2 be removed from kubebuilder) diff --git a/pkg/plugins/common/kustomize/v1/plugin.go b/pkg/plugins/common/kustomize/v1/plugin.go index 749811a6685..2c784b06048 100644 --- a/pkg/plugins/common/kustomize/v1/plugin.go +++ b/pkg/plugins/common/kustomize/v1/plugin.go @@ -24,7 +24,7 @@ import ( ) // KustomizeVersion is the kubernetes-sigs/kustomize version to be used in the project -const KustomizeVersion = "v3.8.7" +const KustomizeVersion = "v4.5.5" const pluginName = "kustomize.common." + plugins.DefaultNameQualifier diff --git a/test/testdata/test_kustomize_compatibilit_3x.sh b/test/testdata/test_kustomize_compatibilit_3x.sh new file mode 100755 index 00000000000..414652e9984 --- /dev/null +++ b/test/testdata/test_kustomize_compatibilit_3x.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +# Copyright 2022 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The go/v3 stable plugin with kustomize/v1 was upgraded +# to move forward from its version 3.X to 4.X. +# However, we need to ensure the backwords compability +# and we cannot change the scaffolds mainly of create api and +# webhook commands to use the new features provide with kustomize 4.X +# in order to not introduce a breaking change for thoso who scaffold +# the projects with Kubebuilder CLI 3.X when they will use new versions +# of the tool. So, this test is for we ensure and does not +# allow maintainers break the stable plugin. +# +# Changes on the syntax for kustomize v4 must be addressed +# ONLY in the new plugin version kustomize/v2 instead. +# +# For further information see the doc about Plugin Versioning + +source "$(dirname "$0")/../common.sh" + +# Executes the test of the testdata directories +function test_bk_with_projects { + rm -f "$(command -v controller-gen)" + rm -f "$(command -v kustomize)" + + header_text "Performing tests in dir $1" + pushd "$(dirname "$0")/../../testdata/$1" + + make kustomize + + header_text "Remove the kustomize bin if exists" + rm -rf "bin/kustomize" + + header_text "Installing kustomize version v3.8.7" + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s -- 3.8.7 "./bin" + ./bin/kustomize version + + header_text "Testing kustomize build manifests with 3.x to ensure backwords compability" + ./bin/kustomize build "config/crd" + ./bin/kustomize build "config/default" + ./bin/kustomize build "config/webhook" + ./bin/kustomize build "config/certmanager" + + popd + header_text "No changes on the scaffold were done that breaks those who scaffold the projects with Kubebuilder 3.x and go/v3" +} + +build_kb + +# Test compatibility of the scaffolds done with project v3 and kustomize v3.x +# IMPORTANT: Do not remove the test if it fails when you do changes in the scaffolds +# This test was done with the purpose to ensure that we will not change +# the kustomize/v1 scaffolds in a way that it no longer work with 3.x +test_bk_with_projects project-v3 +test_bk_with_projects project-v3-multigroup diff --git a/testdata/project-v3-addon/Makefile b/testdata/project-v3-addon/Makefile index 2bc5e8c7c94..05520d8715b 100644 --- a/testdata/project-v3-addon/Makefile +++ b/testdata/project-v3-addon/Makefile @@ -113,7 +113,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 +KUSTOMIZE_VERSION ?= v4.5.5 CONTROLLER_TOOLS_VERSION ?= v0.9.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" diff --git a/testdata/project-v3-config/Makefile b/testdata/project-v3-config/Makefile index 2bc5e8c7c94..05520d8715b 100644 --- a/testdata/project-v3-config/Makefile +++ b/testdata/project-v3-config/Makefile @@ -113,7 +113,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 +KUSTOMIZE_VERSION ?= v4.5.5 CONTROLLER_TOOLS_VERSION ?= v0.9.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" diff --git a/testdata/project-v3-multigroup/Makefile b/testdata/project-v3-multigroup/Makefile index 2bc5e8c7c94..05520d8715b 100644 --- a/testdata/project-v3-multigroup/Makefile +++ b/testdata/project-v3-multigroup/Makefile @@ -113,7 +113,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 +KUSTOMIZE_VERSION ?= v4.5.5 CONTROLLER_TOOLS_VERSION ?= v0.9.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" diff --git a/testdata/project-v3/Makefile b/testdata/project-v3/Makefile index 2bc5e8c7c94..05520d8715b 100644 --- a/testdata/project-v3/Makefile +++ b/testdata/project-v3/Makefile @@ -113,7 +113,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 +KUSTOMIZE_VERSION ?= v4.5.5 CONTROLLER_TOOLS_VERSION ?= v0.9.0 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"