diff --git a/Makefile b/Makefile index dec18746694..ac552269583 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/testdata/test_bk_compatibility_with_3x.sh #todo(remove the test-legacy whne the go/v2 be removed from kubebuilder) diff --git a/pkg/plugins/common/kustomize/v1/init.go b/pkg/plugins/common/kustomize/v1/init.go index 620ba6383a5..479cfcfac19 100644 --- a/pkg/plugins/common/kustomize/v1/init.go +++ b/pkg/plugins/common/kustomize/v1/init.go @@ -20,10 +20,8 @@ import ( "fmt" "os" "path/filepath" - "runtime" "strings" - log "github.com/sirupsen/logrus" "github.com/spf13/pflag" "sigs.k8s.io/kubebuilder/v3/pkg/config" @@ -35,11 +33,6 @@ import ( var _ plugin.InitSubcommand = &initSubcommand{} -// Verify if the local environment is supported by this plugin -var supportedArchs = []string{"linux/amd64", - "linux/arm64", - "darwin/amd64"} - type initSubcommand struct { config config.Config @@ -54,12 +47,9 @@ func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta * - a "PROJECT" file that stores project configuration - several YAML files for project deployment under the "config" directory - NOTE: The kustomize/v1 plugin used to do this scaffold uses the v3 release (%s). -Therefore, darwin/arm64 is not supported since Kustomize does not provide v3 -binaries for this architecture. The currently supported architectures are %q. -More info: https://github.com/kubernetes-sigs/kustomize/issues/4612. - -`, KustomizeVersion, supportedArchs) + NOTE: The kustomize/v1 plugin used to do this scaffold uses the v4 release (%s). +However, its default scaffolds and files should still be backwards compatible with 3.x. +`, KustomizeVersion) subcmdMeta.Examples = fmt.Sprintf(` # Initialize a common project with your domain and name in copyright %[1]s init --plugins common/v3 --domain example.org @@ -108,37 +98,6 @@ func (p *initSubcommand) InjectConfig(c config.Config) error { return nil } -func (p *initSubcommand) PreScaffold(machinery.Filesystem) error { - arch := runtime.GOARCH - // It probably will never return x86_64. However, we are here checking the support for the binaries - // So that, x86_64 means getting the Linux/amd64 binary. Then, we just keep this line to ensure - // that it complies with the same code implementation that we have in the targets. In case someone - // call the command inform the GOARCH=x86_64 then, we will properly handle the scenario - // since it will work successfully and will instal the Linux/amd64 binary via the Makefile target. - arch = strings.Replace(arch, "x86_64", "amd64", -1) - localPlatform := fmt.Sprintf("%s/%s", strings.TrimSpace(runtime.GOOS), strings.TrimSpace(arch)) - - if !hasSupportFor(localPlatform) { - log.Warnf("the platform of this environment (%s) is not suppported by kustomize v3 (%s) which is "+ - "used in this scaffold. You will be unable to download a binary for the kustomize version supported "+ - "and used by this plugin. The currently supported platforms are: %q", - localPlatform, - KustomizeVersion, - supportedArchs) - } - - return nil -} - -func hasSupportFor(localPlatform string) bool { - for _, value := range supportedArchs { - if value == localPlatform { - return true - } - } - return false -} - func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error { scaffolder := scaffolds.NewInitScaffolder(p.config) scaffolder.InjectFS(fs) 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/e2e/v3/plugin_cluster_test.go b/test/e2e/v3/plugin_cluster_test.go index 85ff1778c5b..21ee7b0c763 100644 --- a/test/e2e/v3/plugin_cluster_test.go +++ b/test/e2e/v3/plugin_cluster_test.go @@ -25,8 +25,6 @@ import ( "strings" "time" - "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util" - //nolint:golint //nolint:revive . "github.com/onsi/ginkgo" @@ -35,6 +33,8 @@ import ( //nolint:revive . "github.com/onsi/gomega" + "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util" + kustomizecommonv1 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/common/kustomize/v1" "sigs.k8s.io/kubebuilder/v3/test/e2e/utils" ) @@ -120,6 +120,24 @@ var _ = Describe("kubebuilder", func() { kbc.UninstallCertManager(false) }) + It("should generate a runnable project go/v3 using kustomize 3.x", func() { + // Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist. + if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 { + Skip(fmt.Sprintf("cluster version %s does not support v1 CRDs or webhooks", + srvVer.GitVersion)) + } + + GenerateV3(kbc, "v1", false) + + // replace the version to 3x + makefile := filepath.Join(kbc.Dir, "Makefile") + if err := util.ReplaceInFile(makefile, kustomizecommonv1.KustomizeVersion, `v3.8.7`); err != nil { + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + } + + Run(kbc) + }) + It("should generate a runnable project go/v3 with v1 CRDs and Webhooks", func() { // Skip if cluster version < 1.16, when v1 CRDs and webhooks did not exist. if srvVer := kbc.K8sVersion.ServerVersion; srvVer.GetMajorInt() <= 1 && srvVer.GetMinorInt() < 16 { diff --git a/test/testdata/test_bk_compatibility_with_3x.sh b/test/testdata/test_bk_compatibility_with_3x.sh new file mode 100755 index 00000000000..819c4d2a978 --- /dev/null +++ b/test/testdata/test_bk_compatibility_with_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 backwards 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"