diff --git a/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md b/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md
index cae361c45ca..7ce8757ae47 100644
--- a/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md
+++ b/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md
@@ -16,11 +16,17 @@ The recommended upgrade approach is to follow the [Migration Guide go/v3 to go/v
## Migration from project config version "go/v3" to "go/v4"
-Update `PROJECT` file layout which stores the information about the resources are use to enable plugins to make useful decisions when scaffolding.
+Update the `PROJECT` file layout which stores information about the resources that are used to enable plugins make
+useful decisions while scaffolding. The `layout` field indicates the scaffolding and the primary plugin version in use.
-Furthermore, the `PROJECT` file itself is now versioned. The `version` field corresponds to the version of the `PROJECT` file itself, while the `layout` field indicates the scaffolding and the primary plugin version in use.
+### Steps to migrate
+
+#### Migrate the layout version into the PROJECT file
+
+The following steps describe the manual changes required to bring the project configuration file (`PROJECT`).
+These change will add the information that Kubebuilder would add when generating the file. This file can be found in the root directory.
-Update:
+Update the PROJECT file by replacing:
```yaml
layout:
@@ -35,16 +41,120 @@ layout:
```
-### Steps to migrate
+#### Changes the layout
-- Update the `main.go` with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/main.go`).
-- Update the Makefile with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/Makefile`)
-- Update the `go.mod` with the changes which can be found in the samples under `testdata` for the release tag used. (see for example `testdata/project-v4/go.mod`). Then, run
-`go mod tidy` to ensure that you get the latest dependencies and your Golang code has no breaking changes.
-- Update the manifest under `config/` directory with all changes performed in the default scaffold done with `go/v4-alpha` plugin. (see for example `testdata/project-v4/config/`) to get all changes in the
-default scaffolds to be applied on your project
-- Create `config/samples/kustomization.yaml` with all CR samples specified. (see for example `testdata/project-v4/config/samples/kustomization.yaml`)
-- Replace the import `admissionv1beta1 "k8s.io/api/admission/v1beta1"` with `admissionv1 "k8s.io/api/admission/v1"` in the webhook test files
+##### Now, let's perform the layout changes to comply within:
+
+- The directory `apis` was renamed to `api` to follow the standard
+- The `controller(s)` directory has been moved under a new directory called `internal` and renamed to singular as well `controller`
+- The `main.go` previously scaffolded in the root directory has been moved under a new directory called `cmd`
+
+Therefore, you can check the changes in the layout results into:
+
+```sh
+...
+├── cmd
+│ └── main.go
+├── internal
+│ └── controller
+└── api
+```
+
+##### In this way, you will need to:
+
+- Create a new directory `cmd` and move the `main.go` under it.
+- If your project support multi-group the APIs are scaffold under a directory called `apis`. Rename this directory to `api`
+- Move the `controllers` directory under the `internal` and rename it for `controller`
+- Now ensure that the imports will be updated accordingly by:
+ - Update the `main.go` imports to look for the new path of your controllers under the `pkg` directory
+ - Update all controllers imports to look for the new path of your apis under the `pkg` directory
+
+**Then, let's update the scaffolds paths**
+
+- Update the Dockerfile to ensure that you will have:
+
+```
+COPY cmd/main.go cmd/main.go
+COPY api/ api/
+COPY internal/controller/ internal/controller/
+```
+
+Then, replace:
+
+```
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+
+```
+
+With:
+
+```
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
+```
+
+- Update the Makefile targets to build and run the manager by replacing:
+
+```
+.PHONY: build
+build: manifests generate fmt vet ## Build manager binary.
+ go build -o bin/manager main.go
+
+.PHONY: run
+run: manifests generate fmt vet ## Run a controller from your host.
+ go run ./main.go
+```
+
+With:
+
+```
+.PHONY: build
+build: manifests generate fmt vet ## Build manager binary.
+ go build -o bin/manager cmd/main.go
+
+.PHONY: run
+run: manifests generate fmt vet ## Run a controller from your host.
+ go run ./cmd/main.go
+```
+
+- Update the `internal/controller/suite_test.go` to set the path for the `CRDDirectoryPaths`:
+
+Replace:
+
+```
+CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
+```
+
+With:
+
+```
+CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+```
+
+Note that if your project has multiple groups (`multigroup:true`) then the above update should result into `"..", "..", "..",` instead of `"..",".."`
+
+#### Now, let's update the PATHs in the PROJECT file accordingly
+
+The PROJECT tracks the paths of all APIs used in your project. Ensure that they now point to `pkg/api/...` as the following example:
+
+Before update:
+ group: crew
+ kind: Captain
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4/api/crew/v1
+```
+
+After Update:
+
+```
+ group: crew
+ kind: Captain
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4/apis/crew/v1
+```
+
+### Update kustomize manifests with the changes made so far
+
+- Update the manifest under `config/` directory with all changes performed in the default scaffold done with `go/v4-alpha` plugin. (see for example `testdata/project-v4/config/`) to get all changes in the
+ default scaffolds to be applied on your project
+- Create `config/samples/kustomization.yaml` with all Custom Resources samples specified into `config/samples`. _(see for example `testdata/project-v4/config/samples/kustomization.yaml`)_
`config/` directory with changes into the scaffold files
@@ -52,17 +162,30 @@ default scaffolds to be applied on your project
Note that under the `config/` directory you will find scaffolding changes since using
`go/v4-alpha` you will ensure that you are no longer using Kustomize v3x.
-You can mainly compare the `config/` directory from the samples scaffolded under the `testdata`directory by
+You can mainly compare the `config/` directory from the samples scaffolded under the `testdata`directory by
checking the differences between the `testdata/project-v3/config/` with `testdata/project-v4/config/` which
are samples created with the same commands with the only difference being versions.
However, note that if you create your project with Kubebuilder CLI 3.0.0, its scaffolds
-might change to accommodate changes up to the latest releases using `go/v3` which are not considered
-breaking for users and/or are forced by the changes introduced in the dependencies
-used by the project such as [controller-runtime][controller-runtime] and [controller-tools][controller-tools].
+might change to accommodate changes up to the latest releases using `go/v3` which are not considered
+breaking for users and/or are forced by the changes introduced in the dependencies
+used by the project such as [controller-runtime][controller-runtime] and [controller-tools][controller-tools].
+### If you have webhooks:
+
+Replace the import `admissionv1beta1 "k8s.io/api/admission/v1beta1"` with `admissionv1 "k8s.io/api/admission/v1"` in the webhook test files
+
+### Makefile updates
+
+Update the Makefile with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/Makefile`)
+
+### Update the dependencies
+
+Update the `go.mod` with the changes which can be found in the samples under `testdata` for the release tag used. (see for example `testdata/project-v4/go.mod`). Then, run
+`go mod tidy` to ensure that you get the latest dependencies and your Golang code has no breaking changes.
+
### Verification
In the steps above, you updated your project manually with the goal of ensuring that it follows
diff --git a/docs/book/src/migration/v3vsv4.md b/docs/book/src/migration/v3vsv4.md
index 1cd0e39031f..b579ed191b3 100644
--- a/docs/book/src/migration/v3vsv4.md
+++ b/docs/book/src/migration/v3vsv4.md
@@ -20,6 +20,8 @@ The details of all changes (breaking or otherwise) can be found in:
- no longer scaffold webhook test files with `"k8s.io/api/admission/v1beta1"` the k8s API which is no longer served since k8s `1.25`. By default
webhooks test files are scaffolding using `"k8s.io/api/admission/v1"` which is support from k8s `1.20`
- no longer provide backwards compatible support with k8s versions < `1.16`
+- change the layout to accommodate the community request to follow the [Standard Go Project Layout][standard-go-project]
+by moving the api(s) under a new directory called `pkg`, controller(s) under a new directory called `internal` and the `main.go` under a new directory named `cmd`
TL;DR of the New `go/v4-alpha` Plugin
@@ -86,3 +88,4 @@ This way is more complex, susceptible to errors, and success cannot be assured.
[go/v4-doc]: ./../plugins/go-v4-plugin.md
[migration-guide-gov3-to-gov4]: migration_guide_gov3_to_gov4.md
[manually-upgrade]: manually_migration_guide_gov3_to_gov4.md
+[standard-go-project]: https://github.com/golang-standards/project-layout
\ No newline at end of file
diff --git a/docs/book/src/plugins/go-v4-plugin.md b/docs/book/src/plugins/go-v4-plugin.md
index 4b2fb1fa6d5..d6c1f334225 100644
--- a/docs/book/src/plugins/go-v4-plugin.md
+++ b/docs/book/src/plugins/go-v4-plugin.md
@@ -1,7 +1,7 @@
# go/v4-alpha (go.kubebuilder.io/v4-alpha)
Kubebuilder will scaffold using the `go/v4-alpha` plugin only if specified when initializing the project.
-This plugin is a composition of the plugins ` kustomize.common.kubebuilder.io/v2-alpha` and `base.go.kubebuilder.io/v4`.
+This plugin is a composition of the plugins ` kustomize.common.kubebuilder.io/v2-alpha` and `base.go.kubebuilder.io/v4-alpha`.
It scaffolds a project template that helps in constructing sets of [controllers][controller-runtime].
It scaffolds boilerplate code to create and design controllers.
@@ -24,6 +24,8 @@ under the [testdata][testdata] directory on the root directory of the Kubebuilde
- If you are looking to have your project update with the latest version available
- if you are not targeting k8s versions < `1.16` and `1.20` if you are using webhooks
- If you are looking to work on with scaffolds which are compatible with k8s `1.25+`
+- If you are looking for the new layout following the [Standard Go Project Layout][standard-go-project] where
+the "api(s)" are scaffold under the `pkg/` directory, "controller(s)" under `internal`, and the `main.go` under `cmd`
@@ -61,4 +63,5 @@ kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io
[testdata]: https://github.com/kubernetes-sigs/kubebuilder/tree/master/testdata
[plugins-main]: https://github.com/kubernetes-sigs/kubebuilder/blob/master/cmd/main.go
[kustomize-plugin]: ../plugins/kustomize-v2-alpha.md
-[kustomize]: https://github.com/kubernetes-sigs/kustomize
\ No newline at end of file
+[kustomize]: https://github.com/kubernetes-sigs/kustomize
+[standard-go-project]: https://github.com/golang-standards/project-layout
\ No newline at end of file
diff --git a/pkg/model/resource/utils.go b/pkg/model/resource/utils.go
index a71ad71fb1e..3d8b858c8c4 100644
--- a/pkg/model/resource/utils.go
+++ b/pkg/model/resource/utils.go
@@ -50,6 +50,14 @@ func safeImport(unsafe string) string {
// APIPackagePath returns the default path
func APIPackagePath(repo, group, version string, multiGroup bool) string {
+ if multiGroup && group != "" {
+ return path.Join(repo, "api", group, version)
+ }
+ return path.Join(repo, "api", version)
+}
+
+// APIPackagePathLegacy returns the default path
+func APIPackagePathLegacy(repo, group, version string, multiGroup bool) string {
if multiGroup {
if group != "" {
return path.Join(repo, "apis", group, version)
diff --git a/pkg/model/resource/utils_test.go b/pkg/model/resource/utils_test.go
index cea003e4363..9e1451a3217 100644
--- a/pkg/model/resource/utils_test.go
+++ b/pkg/model/resource/utils_test.go
@@ -45,6 +45,23 @@ var _ = Describe("APIPackagePath", func() {
Expect(APIPackagePath(repo, group, version, multiGroup)).To(Equal(p))
},
Entry("single group setup", repo, group, version, false, path.Join(repo, "api", version)),
+ Entry("multiple group setup", repo, group, version, true, path.Join(repo, "api", group, version)),
+ Entry("multiple group setup with empty group", repo, "", version, true, path.Join(repo, "api", version)),
+ )
+})
+
+var _ = Describe("APIPackagePathLegacy", func() {
+ const (
+ repo = "github.com/kubernetes-sigs/kubebuilder"
+ group = "group"
+ version = "v1"
+ )
+
+ DescribeTable("should work",
+ func(repo, group, version string, multiGroup bool, p string) {
+ Expect(APIPackagePathLegacy(repo, group, version, multiGroup)).To(Equal(p))
+ },
+ Entry("single group setup", repo, group, version, false, path.Join(repo, "api", version)),
Entry("multiple group setup", repo, group, version, true, path.Join(repo, "apis", group, version)),
Entry("multiple group setup with empty group", repo, "", version, true, path.Join(repo, "apis", version)),
)
diff --git a/pkg/plugin/helpers.go b/pkg/plugin/helpers.go
index d2edfaa6db9..a957d4cb071 100644
--- a/pkg/plugin/helpers.go
+++ b/pkg/plugin/helpers.go
@@ -47,6 +47,19 @@ func GetShortName(name string) string {
return strings.SplitN(name, ".", 2)[0]
}
+// Deprecated: it was added to ensure backwards compatibility and should
+// be removed when we remove the go/v3 plugin
+// IsLegacyLayout returns true when is possible to identify that the project
+// was scaffolded with the previous layout
+func IsLegacyLayout(config config.Config) bool {
+ for _, pluginKey := range config.GetPluginChain() {
+ if strings.Contains(pluginKey, "go.kubebuilder.io/v3") || strings.Contains(pluginKey, "go.kubebuilder.io/v2") {
+ return true
+ }
+ }
+ return false
+}
+
// Validate ensures a Plugin is valid.
func Validate(p Plugin) error {
if err := validateName(p.Name()); err != nil {
diff --git a/pkg/plugin/util/helpers.go b/pkg/plugin/util/helpers.go
index db252d63d8d..87d953f268b 100644
--- a/pkg/plugin/util/helpers.go
+++ b/pkg/plugin/util/helpers.go
@@ -20,16 +20,19 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/config"
)
+// Deprecated: go/v4 no longer supports v1beta1 option
// HasDifferentCRDVersion returns true if any other CRD version is tracked in the project configuration.
func HasDifferentCRDVersion(config config.Config, crdVersion string) bool {
return hasDifferentAPIVersion(config.ListCRDVersions(), crdVersion)
}
+// Deprecated: go/v4 no longer supports v1beta1 option
// HasDifferentWebhookVersion returns true if any other webhook version is tracked in the project configuration.
func HasDifferentWebhookVersion(config config.Config, webhookVersion string) bool {
return hasDifferentAPIVersion(config.ListWebhookVersions(), webhookVersion)
}
+// Deprecated: go/v4 no longer supports v1beta1 option
func hasDifferentAPIVersion(versions []string, version string) bool {
return !(len(versions) == 0 || (len(versions) == 1 && versions[0] == version))
}
diff --git a/pkg/plugin/util/util.go b/pkg/plugin/util/util.go
index 71d800980e0..927ceb2d473 100644
--- a/pkg/plugin/util/util.go
+++ b/pkg/plugin/util/util.go
@@ -191,6 +191,25 @@ func EnsureExistAndReplace(input, match, replace string) (string, error) {
return strings.Replace(input, match, replace, -1), nil
}
+func HasFragment(path, target string) (bool, error) {
+ _, err := os.Stat(path)
+ if err != nil {
+ return false, err
+ }
+
+ // false positive
+ // nolint:gosec
+ b, err := os.ReadFile(path)
+ if err != nil {
+ return false, err
+ }
+
+ if !strings.Contains(string(b), target) {
+ return false, nil
+ }
+ return true, nil
+}
+
// ReplaceInFile replaces all instances of old with new in the file at path.
func ReplaceInFile(path, old, new string) error {
info, err := os.Stat(path)
diff --git a/pkg/plugins/golang/declarative/v1/api.go b/pkg/plugins/golang/declarative/v1/api.go
index fd0d6f44b25..563202ba3a5 100644
--- a/pkg/plugins/golang/declarative/v1/api.go
+++ b/pkg/plugins/golang/declarative/v1/api.go
@@ -100,7 +100,8 @@ func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error {
}
// Update Dockerfile
- err = updateDockerfile()
+ // nolint:staticcheck
+ err = updateDockerfile(plugin.IsLegacyLayout(p.config))
if err != nil {
return err
}
diff --git a/pkg/plugins/golang/declarative/v1/init.go b/pkg/plugins/golang/declarative/v1/init.go
index 5a6e0bf5df0..db15aa1bbac 100644
--- a/pkg/plugins/golang/declarative/v1/init.go
+++ b/pkg/plugins/golang/declarative/v1/init.go
@@ -41,7 +41,8 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
}
func (p *initSubcommand) Scaffold(_ machinery.Filesystem) error {
- err := updateDockerfile()
+ //nolint:staticcheck
+ err := updateDockerfile(plugin.IsLegacyLayout(p.config))
if err != nil {
return err
}
@@ -49,19 +50,23 @@ func (p *initSubcommand) Scaffold(_ machinery.Filesystem) error {
}
// updateDockerfile will add channels staging required for declarative plugin
-func updateDockerfile() error {
+func updateDockerfile(isLegacyLayout bool) error {
fmt.Println("updating Dockerfile to add channels/ directory in the image")
- managerFile := filepath.Join("Dockerfile")
+ dockerfile := filepath.Join("Dockerfile")
+ controllerPath := "internal/controller/"
+ if isLegacyLayout {
+ controllerPath = "controllers/"
+ }
// nolint:lll
- err := insertCodeIfDoesNotExist(managerFile,
- "COPY controllers/ controllers/",
+ err := insertCodeIfDoesNotExist(dockerfile,
+ fmt.Sprintf("COPY %s %s", controllerPath, controllerPath),
"\n# https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/blob/master/docs/addon/walkthrough/README.md#adding-a-manifest\n# Stage channels and make readable\nCOPY channels/ /channels/\nRUN chmod -R a+rx /channels/")
if err != nil {
return err
}
- err = insertCodeIfDoesNotExist(managerFile,
+ err = insertCodeIfDoesNotExist(dockerfile,
"COPY --from=builder /workspace/manager .",
"\n# copy channels\nCOPY --from=builder /channels /channels\n")
if err != nil {
diff --git a/pkg/plugins/golang/declarative/v1/scaffolds/api.go b/pkg/plugins/golang/declarative/v1/scaffolds/api.go
index af0ab1907ed..10273b1958a 100644
--- a/pkg/plugins/golang/declarative/v1/scaffolds/api.go
+++ b/pkg/plugins/golang/declarative/v1/scaffolds/api.go
@@ -24,6 +24,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/config"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
+ "sigs.k8s.io/kubebuilder/v3/pkg/plugin"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins"
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates"
)
@@ -70,9 +71,10 @@ func (s *apiScaffolder) Scaffold() error {
machinery.WithResource(&s.resource),
)
+ //nolint:staticcheck
err = scaffold.Execute(
- &templates.Types{},
- &templates.Controller{},
+ &templates.Types{IsLegacyLayout: plugin.IsLegacyLayout(s.config)},
+ &templates.Controller{IsLegacyLayout: plugin.IsLegacyLayout(s.config)},
&templates.Channel{ManifestVersion: exampleManifestVersion},
&templates.Manifest{ManifestVersion: exampleManifestVersion},
)
diff --git a/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/controller.go b/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/controller.go
index f0b32456748..23a1340b684 100644
--- a/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/controller.go
+++ b/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/controller.go
@@ -17,6 +17,7 @@ limitations under the License.
package templates
import (
+ "fmt"
"path/filepath"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
@@ -31,18 +32,36 @@ type Controller struct {
machinery.MultiGroupMixin
machinery.BoilerplateMixin
machinery.ResourceMixin
+
+ IsLegacyLayout bool
+ PackageName string
}
// SetTemplateDefaults implements file.Template
func (f *Controller) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller.go")
+ if f.IsLegacyLayout {
+ if f.MultiGroup {
+ f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller.go")
+ } else {
+ f.Path = filepath.Join("controllers", "%[kind]_controller.go")
+ }
} else {
- f.Path = filepath.Join("controllers", "%[kind]_controller.go")
+ if f.MultiGroup {
+ f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller.go")
+ } else {
+ f.Path = filepath.Join("internal", "controller", "%[kind]_controller.go")
+ }
}
+
}
f.Path = f.Resource.Replacer().Replace(f.Path)
+ fmt.Println(f.Path)
+
+ f.PackageName = "controller"
+ if f.IsLegacyLayout {
+ f.PackageName = "controllers"
+ }
f.TemplateBody = controllerTemplate
@@ -54,7 +73,7 @@ func (f *Controller) SetTemplateDefaults() error {
//nolint:lll
const controllerTemplate = `{{ .Boilerplate }}
-package controllers
+package {{ .PackageName }}
import (
"github.com/go-logr/logr"
diff --git a/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/types.go b/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/types.go
index 4a3b063ba05..359c3bb0d34 100644
--- a/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/types.go
+++ b/pkg/plugins/golang/declarative/v1/scaffolds/internal/templates/types.go
@@ -33,18 +33,30 @@ type Types struct {
machinery.MultiGroupMixin
machinery.BoilerplateMixin
machinery.ResourceMixin
+
+ IsLegacyLayout bool
}
// SetTemplateDefaults implements file.Template
func (f *Types) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go")
+ if f.IsLegacyLayout {
+ if f.MultiGroup {
+ f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go")
+ } else {
+ f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
+ }
} else {
- f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
+ if f.MultiGroup {
+ f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go")
+ } else {
+ f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
+ }
}
+
}
f.Path = f.Resource.Replacer().Replace(f.Path)
+ fmt.Println(f.Path)
f.TemplateBody = typesTemplate
diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/api.go b/pkg/plugins/golang/deploy-image/v1alpha1/api.go
index a0e6ee27a07..5e256343e5c 100644
--- a/pkg/plugins/golang/deploy-image/v1alpha1/api.go
+++ b/pkg/plugins/golang/deploy-image/v1alpha1/api.go
@@ -20,10 +20,10 @@ import (
"errors"
"fmt"
"os"
-
- goPlugin "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
+ "strings"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
+ goPlugin "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang"
"github.com/spf13/pflag"
"sigs.k8s.io/kubebuilder/v3/pkg/config"
@@ -43,9 +43,6 @@ const deprecateMsg = "The v1beta1 API version for CRDs and Webhooks are deprecat
"recommend you no longer use these API versions." +
"More info: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22"
-// DefaultMainPath is default file path of main.go
-const DefaultMainPath = "main.go"
-
var _ plugin.CreateAPISubcommand = &createAPISubcommand{}
type createAPISubcommand struct {
@@ -152,6 +149,7 @@ func (p *createAPISubcommand) InjectResource(res *resource.Resource) error {
p.options.DoAPI = true
p.options.DoController = true
p.options.Namespaced = true
+
p.options.UpdateResource(p.resource, p.config)
if err := p.resource.Validate(); err != nil {
@@ -165,12 +163,14 @@ func (p *createAPISubcommand) InjectResource(res *resource.Resource) error {
}
// Check CRDVersion against all other CRDVersions in p.config for compatibility.
+ // nolint:staticcheck
if util.HasDifferentCRDVersion(p.config, p.resource.API.CRDVersion) {
return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q",
p.resource.API.CRDVersion)
}
// Check CRDVersion against all other CRDVersions in p.config for compatibility.
+ // nolint:staticcheck
if util.HasDifferentCRDVersion(p.config, p.resource.API.CRDVersion) {
return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q",
p.resource.API.CRDVersion)
@@ -184,9 +184,20 @@ func (p *createAPISubcommand) PreScaffold(machinery.Filesystem) error {
return fmt.Errorf("you MUST inform the image that will be used in the reconciliation")
}
- // check if main.go is present in the root directory
- if _, err := os.Stat(DefaultMainPath); os.IsNotExist(err) {
- return fmt.Errorf("%s file should present in the root directory", DefaultMainPath)
+ isGoV3 := false
+ for _, pluginKey := range p.config.GetPluginChain() {
+ if strings.Contains(pluginKey, "go.kubebuilder.io/v3") {
+ isGoV3 = true
+ }
+ }
+
+ defaultMainPath := "cmd/main.go"
+ if isGoV3 {
+ defaultMainPath = "main.go"
+ }
+ // check if main.go is present in the cmd/ directory
+ if _, err := os.Stat(defaultMainPath); os.IsNotExist(err) {
+ return fmt.Errorf("main.go file should be present in %s", defaultMainPath)
}
return nil
diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
index 5fad1c14bfd..274d87a4eef 100644
--- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
+++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/api.go
@@ -21,6 +21,8 @@ import (
"path/filepath"
"strings"
+ "sigs.k8s.io/kubebuilder/v3/pkg/plugin"
+
"github.com/spf13/afero"
"sigs.k8s.io/kubebuilder/v3/pkg/config"
@@ -77,13 +79,8 @@ func (s *apiScaffolder) InjectFS(fs machinery.Filesystem) {
func (s *apiScaffolder) Scaffold() error {
fmt.Println("Writing scaffold for you to edit...")
- //nolint:staticcheck
- isGoV3 := false
- for _, pluginKey := range s.config.GetPluginChain() {
- if strings.Contains(pluginKey, "go.kubebuilder.io/v3") {
- isGoV3 = true
- }
- }
+ //nolint: staticcheck
+ isGoV3 := plugin.IsLegacyLayout(s.config)
if err := s.scaffoldCreateAPIFromPlugins(isGoV3); err != nil {
return err
@@ -103,7 +100,7 @@ func (s *apiScaffolder) Scaffold() error {
)
if err := scaffold.Execute(
- &api.Types{Port: s.port},
+ &api.Types{Port: s.port, IsLegacyLayout: isGoV3},
); err != nil {
return fmt.Errorf("error updating APIs: %v", err)
}
@@ -116,7 +113,13 @@ func (s *apiScaffolder) Scaffold() error {
controller := &controllers.Controller{
ControllerRuntimeVersion: golangv3scaffolds.ControllerRuntimeVersion,
+ IsLegacyLayout: isGoV3,
}
+
+ if !isGoV3 {
+ controller.ControllerRuntimeVersion = golangv4scaffolds.ControllerRuntimeVersion
+ }
+
if err := scaffold.Execute(
controller,
); err != nil {
@@ -127,14 +130,18 @@ func (s *apiScaffolder) Scaffold() error {
return fmt.Errorf("error updating controller: %v", err)
}
- if err := s.updateMainByAddingEventRecorder(); err != nil {
+ defaultMainPath := "cmd/main.go"
+ if isGoV3 {
+ defaultMainPath = "main.go"
+ }
+ if err := s.updateMainByAddingEventRecorder(isGoV3, defaultMainPath); err != nil {
return fmt.Errorf("error updating main.go: %v", err)
}
if err := scaffold.Execute(
- &controllers.ControllerTest{Port: s.port},
+ &controllers.ControllerTest{Port: s.port, IsLegacyLayout: isGoV3},
); err != nil {
- return fmt.Errorf("error creating controllers/**_controller_test.go: %v", err)
+ return fmt.Errorf("error creating controller/**_controller_test.go: %v", err)
}
if err := s.addEnvVarIntoManager(); err != nil {
@@ -181,18 +188,29 @@ func (s *apiScaffolder) scaffoldCreateAPIFromPlugins(isLegacyLayout bool) error
// TODO: replace this implementation by creating its own MainUpdater
// which will have its own controller template which set the recorder so that we can use it
// in the reconciliation to create an event inside for the finalizer
-func (s *apiScaffolder) updateMainByAddingEventRecorder() error {
- defaultMainPath := "main.go"
-
- if err := util.InsertCode(
- defaultMainPath,
- fmt.Sprintf(
- `if err = (&controllers.%sReconciler{
+func (s *apiScaffolder) updateMainByAddingEventRecorder(isGoV3 bool, defaultMainPath string) error {
+ if isGoV3 {
+ if err := util.InsertCode(
+ defaultMainPath,
+ fmt.Sprintf(
+ `if err = (&controllers.%sReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),`, s.resource.Kind),
- fmt.Sprintf(recorderTemplate, strings.ToLower(s.resource.Kind)),
- ); err != nil {
- return fmt.Errorf("error scaffolding event recorder in %s: %v", defaultMainPath, err)
+ fmt.Sprintf(recorderTemplate, strings.ToLower(s.resource.Kind)),
+ ); err != nil {
+ return fmt.Errorf("error scaffolding event recorder in %s: %v", defaultMainPath, err)
+ }
+ } else {
+ if err := util.InsertCode(
+ defaultMainPath,
+ fmt.Sprintf(
+ `if err = (&controller.%sReconciler{
+ Client: mgr.GetClient(),
+ Scheme: mgr.GetScheme(),`, s.resource.Kind),
+ fmt.Sprintf(recorderTemplate, strings.ToLower(s.resource.Kind)),
+ ); err != nil {
+ return fmt.Errorf("error scaffolding event recorder in %s: %v", defaultMainPath, err)
+ }
}
return nil
@@ -276,13 +294,13 @@ func (s *apiScaffolder) updateControllerCode(controller controllers.Controller)
return nil
}
-func (s *apiScaffolder) scaffoldCreateAPIFromKustomize(isGoV3 bool) error {
+func (s *apiScaffolder) scaffoldCreateAPIFromKustomize(isLegacyLayout bool) error {
// Now we need call the kustomize/v1 plugin to do its scaffolds when we create a new API
// todo: when we have the go/v4-alpha plugin we will also need to check what is the plugin used
// in the Project layout to know if we should use kustomize/v1 OR kustomize/v2-alpha
var kustomizeScaffolder plugins.Scaffolder
- if isGoV3 {
+ if isLegacyLayout {
kustomizeScaffolder = kustomizev1scaffolds.NewAPIScaffolder(
s.config,
s.resource,
@@ -305,11 +323,11 @@ func (s *apiScaffolder) scaffoldCreateAPIFromKustomize(isGoV3 bool) error {
return nil
}
-func (s *apiScaffolder) scaffoldCreateAPIFromGolang(isGoV3 bool) error {
+func (s *apiScaffolder) scaffoldCreateAPIFromGolang(isLegacyLayout bool) error {
// Now we need call the kustomize/v1 plugin to do its scaffolds when we create a new API
// todo: when we have the go/v4-alpha plugin we will also need to check what is the plugin used
// in the Project layout to know if we should use kustomize/v1 OR kustomize/v2-alpha
- if isGoV3 {
+ if isLegacyLayout {
golangV3Scaffolder := golangv3scaffolds.NewAPIScaffolder(s.config,
s.resource, true)
golangV3Scaffolder.InjectFS(s.fs)
diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go
index 58efeeadf21..30779753ebd 100644
--- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go
+++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/api/types.go
@@ -35,21 +35,33 @@ type Types struct {
// Port if informed we will create the scaffold with this spec
Port string
+
+ IsLegacyLayout bool
}
// SetTemplateDefaults implements file.Template
func (f *Types) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- if f.Resource.Group != "" {
- f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go")
+
+ if f.IsLegacyLayout {
+ if f.MultiGroup {
+ if f.Resource.Group != "" {
+ f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go")
+ } else {
+ f.Path = filepath.Join("apis", "%[version]", "%[kind]_types.go")
+ }
} else {
- f.Path = filepath.Join("apis", "%[version]", "%[kind]_types.go")
+ f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
}
} else {
- f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
+ if f.MultiGroup && f.Resource.Group != "" {
+ f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go")
+ } else {
+ f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
+ }
}
}
+
f.Path = f.Resource.Replacer().Replace(f.Path)
fmt.Println(f.Path)
diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/config/samples/crd_sample.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/config/samples/crd_sample.go
index dbd94dab91c..a4344fd2e56 100644
--- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/config/samples/crd_sample.go
+++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/config/samples/crd_sample.go
@@ -14,6 +14,7 @@ limitations under the License.
package samples
import (
+ "fmt"
"path/filepath"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
@@ -36,6 +37,7 @@ func (f *CRDSample) SetTemplateDefaults() error {
f.Path = filepath.Join("config", "samples", "%[group]_%[version]_%[kind].yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)
+ fmt.Println(f.Path)
f.IfExistsAction = machinery.OverwriteFile
diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go
index 5bd6217bf2d..f39cdd0e8f1 100644
--- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go
+++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go
@@ -33,19 +33,35 @@ type ControllerTest struct {
machinery.BoilerplateMixin
machinery.ResourceMixin
- Port string
+ Port string
+ IsLegacyLayout bool
+ PackageName string
}
// SetTemplateDefaults implements file.Template
func (f *ControllerTest) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup && f.Resource.Group != "" {
- f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller_test.go")
+ if f.IsLegacyLayout {
+ f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller_test.go")
+ } else {
+ f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller_test.go")
+ }
} else {
- f.Path = filepath.Join("controllers", "%[kind]_controller_test.go")
+ if f.IsLegacyLayout {
+ f.Path = filepath.Join("controllers", "%[kind]_controller_test.go")
+ } else {
+ f.Path = filepath.Join("internal", "controller", "%[kind]_controller_test.go")
+ }
}
}
f.Path = f.Resource.Replacer().Replace(f.Path)
+ fmt.Println(f.Path)
+
+ f.PackageName = "controller"
+ if f.IsLegacyLayout {
+ f.PackageName = "controllers"
+ }
fmt.Println("creating import for %", f.Resource.Path)
f.TemplateBody = controllerTestTemplate
@@ -56,7 +72,7 @@ func (f *ControllerTest) SetTemplateDefaults() error {
//nolint:lll
const controllerTestTemplate = `{{ .Boilerplate }}
-package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}controllers{{ end }}
+package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}{{ .PackageName }}{{ end }}
import (
"context"
diff --git a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
index 4eac67bd723..1caaab444ac 100644
--- a/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
+++ b/pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
@@ -35,18 +35,37 @@ type Controller struct {
machinery.ProjectNameMixin
ControllerRuntimeVersion string
+
+ // IsLegacyLayout is added to ensure backwards compatibility and should
+ // be removed when we remove the go/v3 plugin
+ IsLegacyLayout bool
+ PackageName string
}
// SetTemplateDefaults implements file.Template
func (f *Controller) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup && f.Resource.Group != "" {
- f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller.go")
+ if f.IsLegacyLayout {
+ f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller.go")
+ } else {
+ f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller.go")
+ }
} else {
- f.Path = filepath.Join("controllers", "%[kind]_controller.go")
+ if f.IsLegacyLayout {
+ f.Path = filepath.Join("controllers", "%[kind]_controller.go")
+ } else {
+ f.Path = filepath.Join("internal", "controller", "%[kind]_controller.go")
+ }
}
}
f.Path = f.Resource.Replacer().Replace(f.Path)
+ fmt.Println(f.Path)
+
+ f.PackageName = "controller"
+ if f.IsLegacyLayout {
+ f.PackageName = "controllers"
+ }
fmt.Println("creating import for %", f.Resource.Path)
f.TemplateBody = controllerTemplate
@@ -60,7 +79,7 @@ func (f *Controller) SetTemplateDefaults() error {
//nolint:lll
const controllerTemplate = `{{ .Boilerplate }}
-package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}controllers{{ end }}
+package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}{{ .PackageName }}{{ end }}
import (
"context"
diff --git a/pkg/plugins/golang/options.go b/pkg/plugins/golang/options.go
index b6a7338ee93..33665f747e6 100644
--- a/pkg/plugins/golang/options.go
+++ b/pkg/plugins/golang/options.go
@@ -22,6 +22,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/config"
cfgv2 "sigs.k8s.io/kubebuilder/v3/pkg/config/v2"
"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
+ "sigs.k8s.io/kubebuilder/v3/pkg/plugin"
)
var (
@@ -80,11 +81,18 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
}
if opts.DoAPI {
- res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
+ //nolint:staticcheck
+ if plugin.IsLegacyLayout(c) {
+ res.Path = resource.APIPackagePathLegacy(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
+ } else {
+ res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
+ }
+
res.API = &resource.API{
CRDVersion: opts.CRDVersion,
Namespaced: opts.Namespaced,
}
+
}
if opts.DoController {
@@ -92,7 +100,14 @@ func (opts Options) UpdateResource(res *resource.Resource, c config.Config) {
}
if opts.DoDefaulting || opts.DoValidation || opts.DoConversion {
- res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
+ // IsLegacyLayout is added to ensure backwards compatibility and should
+ // be removed when we remove the go/v3 plugin
+ //nolint:staticcheck
+ if plugin.IsLegacyLayout(c) {
+ res.Path = resource.APIPackagePathLegacy(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
+ } else {
+ res.Path = resource.APIPackagePath(c.GetRepository(), res.Group, res.Version, c.IsMultiGroup())
+ }
res.Webhooks.WebhookVersion = opts.WebhookVersion
if opts.DoDefaulting {
res.Webhooks.Defaulting = true
diff --git a/pkg/plugins/golang/options_test.go b/pkg/plugins/golang/options_test.go
index df87ee20748..30a9c095838 100644
--- a/pkg/plugins/golang/options_test.go
+++ b/pkg/plugins/golang/options_test.go
@@ -18,7 +18,7 @@ package golang
import (
"path"
-
+
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
@@ -77,7 +77,7 @@ var _ = Describe("Options", func() {
if options.DoAPI || options.DoDefaulting || options.DoValidation || options.DoConversion {
if multiGroup {
Expect(res.Path).To(Equal(
- path.Join(cfg.GetRepository(), "apis", gvk.Group, gvk.Version)))
+ path.Join(cfg.GetRepository(), "api", gvk.Group, gvk.Version)))
} else {
Expect(res.Path).To(Equal(path.Join(cfg.GetRepository(), "api", gvk.Version)))
}
diff --git a/pkg/plugins/golang/v3/api.go b/pkg/plugins/golang/v3/api.go
index 30b81ca7f30..6e13838d7ef 100644
--- a/pkg/plugins/golang/v3/api.go
+++ b/pkg/plugins/golang/v3/api.go
@@ -161,6 +161,7 @@ func (p *createAPISubcommand) InjectResource(res *resource.Resource) error {
}
// Check CRDVersion against all other CRDVersions in p.config for compatibility.
+ // nolint:staticcheck
if util.HasDifferentCRDVersion(p.config, p.resource.API.CRDVersion) {
return fmt.Errorf("only one CRD version can be used for all resources, cannot add %q",
p.resource.API.CRDVersion)
diff --git a/pkg/plugins/golang/v3/webhook.go b/pkg/plugins/golang/v3/webhook.go
index 1baba22aaba..6fa5d9dcbe9 100644
--- a/pkg/plugins/golang/v3/webhook.go
+++ b/pkg/plugins/golang/v3/webhook.go
@@ -113,6 +113,7 @@ func (p *createWebhookSubcommand) InjectResource(res *resource.Resource) error {
return fmt.Errorf("webhook resource already exists")
}
+ // nolint:staticcheck
if pluginutil.HasDifferentWebhookVersion(p.config, p.resource.Webhooks.WebhookVersion) {
return fmt.Errorf("only one webhook version can be used for all resources, cannot add %q",
p.resource.Webhooks.WebhookVersion)
diff --git a/pkg/plugins/golang/v4/api.go b/pkg/plugins/golang/v4/api.go
index 86720b20eaa..6e07ff7390f 100644
--- a/pkg/plugins/golang/v4/api.go
+++ b/pkg/plugins/golang/v4/api.go
@@ -39,7 +39,7 @@ const (
)
// DefaultMainPath is default file path of main.go
-const DefaultMainPath = "main.go"
+const DefaultMainPath = "cmd/main.go"
var _ plugin.CreateAPISubcommand = &createAPISubcommand{}
@@ -74,13 +74,14 @@ make generate will be run.
%[1]s create api --group ship --version v1beta1 --kind Frigate
# Edit the API Scheme
+
nano api/v1beta1/frigate_types.go
# Edit the Controller
- nano controllers/frigate/frigate_controller.go
+ nano internal/controller/frigate/frigate_controller.go
# Edit the Controller Test
- nano controllers/frigate/frigate_controller_test.go
+ nano internal/controller/frigate/frigate_controller_test.go
# Generate the manifests
make manifests
diff --git a/pkg/plugins/golang/v4/init.go b/pkg/plugins/golang/v4/init.go
index 21927ec0fe4..681a20d7ba1 100644
--- a/pkg/plugins/golang/v4/init.go
+++ b/pkg/plugins/golang/v4/init.go
@@ -66,13 +66,13 @@ func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *
- a "PROJECT" file that stores project configuration
- a "Makefile" with several useful make targets for the project
- several YAML files for project deployment under the "config" directory
- - a "main.go" file that creates the manager that will run the project controllers
+ - a "cmd/main.go" file that creates the manager that will run the project controllers
`
subcmdMeta.Examples = fmt.Sprintf(` # Initialize a new project with your domain and name in copyright
- %[1]s init --plugins go/v3 --domain example.org --owner "Your name"
+ %[1]s init --plugins go/v4-alpha --domain example.org --owner "Your name"
# Initialize a new project defining a specific project version
- %[1]s init --plugins go/v3 --project-version 3
+ %[1]s init --plugins go/v4-alpha --project-version 3
`, cliMeta.CommandName)
}
diff --git a/pkg/plugins/golang/v4/scaffolds/api.go b/pkg/plugins/golang/v4/scaffolds/api.go
index 69a5a02748d..6afcb040627 100644
--- a/pkg/plugins/golang/v4/scaffolds/api.go
+++ b/pkg/plugins/golang/v4/scaffolds/api.go
@@ -106,7 +106,7 @@ func (s *apiScaffolder) Scaffold() error {
if err := scaffold.Execute(
&templates.MainUpdater{WireResource: doAPI, WireController: doController},
); err != nil {
- return fmt.Errorf("error updating main.go: %v", err)
+ return fmt.Errorf("error updating cmd/main.go: %v", err)
}
return nil
diff --git a/pkg/plugins/golang/v4/scaffolds/edit.go b/pkg/plugins/golang/v4/scaffolds/edit.go
index 1fe5e6505e5..2d2ab1c563e 100644
--- a/pkg/plugins/golang/v4/scaffolds/edit.go
+++ b/pkg/plugins/golang/v4/scaffolds/edit.go
@@ -17,9 +17,6 @@ limitations under the License.
package scaffolds
import (
- "fmt"
- "strings"
-
"github.com/spf13/afero"
"sigs.k8s.io/kubebuilder/v3/pkg/config"
@@ -59,20 +56,6 @@ func (s *editScaffolder) Scaffold() error {
}
str := string(bs)
- // update dockerfile
- if s.multigroup {
- str, err = ensureExistAndReplace(
- str,
- "COPY api/ api/",
- `COPY apis/ apis/`)
-
- } else {
- str, err = ensureExistAndReplace(
- str,
- "COPY apis/ apis/",
- `COPY api/ api/`)
- }
-
// Ignore the error encountered, if the file is already in desired format.
if err != nil && s.multigroup != s.config.IsMultiGroup() {
return err
@@ -93,10 +76,3 @@ func (s *editScaffolder) Scaffold() error {
return nil
}
-
-func ensureExistAndReplace(input, match, replace string) (string, error) {
- if !strings.Contains(input, match) {
- return "", fmt.Errorf("can't find %q", match)
- }
- return strings.Replace(input, match, replace, -1), nil
-}
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/group.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/group.go
index c1acc9cfc63..15c8a67a7c6 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/group.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/group.go
@@ -36,12 +36,8 @@ type Group struct {
// SetTemplateDefaults implements file.Template
func (f *Group) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- if f.Resource.Group != "" {
- f.Path = filepath.Join("apis", "%[group]", "%[version]", "groupversion_info.go")
- } else {
- f.Path = filepath.Join("apis", "%[version]", "groupversion_info.go")
- }
+ if f.MultiGroup && f.Resource.Group != "" {
+ f.Path = filepath.Join("api", "%[group]", "%[version]", "groupversion_info.go")
} else {
f.Path = filepath.Join("api", "%[version]", "groupversion_info.go")
}
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go
index 567c165fa5f..3a27bf88d00 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go
@@ -39,12 +39,8 @@ type Types struct {
// SetTemplateDefaults implements file.Template
func (f *Types) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- if f.Resource.Group != "" {
- f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_types.go")
- } else {
- f.Path = filepath.Join("apis", "%[version]", "%[kind]_types.go")
- }
+ if f.MultiGroup && f.Resource.Group != "" {
+ f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_types.go")
} else {
f.Path = filepath.Join("api", "%[version]", "%[kind]_types.go")
}
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go
index 76561a5a794..bb9c26028f3 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook.go
@@ -45,12 +45,8 @@ type Webhook struct { // nolint:maligned
// SetTemplateDefaults implements file.Template
func (f *Webhook) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- if f.Resource.Group != "" {
- f.Path = filepath.Join("apis", "%[group]", "%[version]", "%[kind]_webhook.go")
- } else {
- f.Path = filepath.Join("apis", "%[version]", "%[kind]_webhook.go")
- }
+ if f.MultiGroup && f.Resource.Group != "" {
+ f.Path = filepath.Join("api", "%[group]", "%[version]", "%[kind]_webhook.go")
} else {
f.Path = filepath.Join("api", "%[version]", "%[kind]_webhook.go")
}
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go
index 2ebc091b9e2..3b13084e907 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/api/webhook_suitetest.go
@@ -43,12 +43,8 @@ type WebhookSuite struct { //nolint:maligned
// SetTemplateDefaults implements file.Template
func (f *WebhookSuite) SetTemplateDefaults() error {
if f.Path == "" {
- if f.MultiGroup {
- if f.Resource.Group != "" {
- f.Path = filepath.Join("apis", "%[group]", "%[version]", "webhook_suite_test.go")
- } else {
- f.Path = filepath.Join("apis", "%[version]", "webhook_suite_test.go")
- }
+ if f.MultiGroup && f.Resource.Group != "" {
+ f.Path = filepath.Join("api", "%[group]", "%[version]", "webhook_suite_test.go")
} else {
f.Path = filepath.Join("api", "%[version]", "webhook_suite_test.go")
}
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go
index 5b5a30aa62e..fb4388f372b 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go
@@ -42,9 +42,9 @@ type Controller struct {
func (f *Controller) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup && f.Resource.Group != "" {
- f.Path = filepath.Join("controllers", "%[group]", "%[kind]_controller.go")
+ f.Path = filepath.Join("internal", "controller", "%[group]", "%[kind]_controller.go")
} else {
- f.Path = filepath.Join("controllers", "%[kind]_controller.go")
+ f.Path = filepath.Join("internal", "controller", "%[kind]_controller.go")
}
}
@@ -65,7 +65,7 @@ func (f *Controller) SetTemplateDefaults() error {
//nolint:lll
const controllerTemplate = `{{ .Boilerplate }}
-package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}controllers{{ end }}
+package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}controller{{ end }}
import (
"context"
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go
index 20a574dd8ae..60bd156124f 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller_suitetest.go
@@ -44,9 +44,9 @@ type SuiteTest struct {
func (f *SuiteTest) SetTemplateDefaults() error {
if f.Path == "" {
if f.MultiGroup && f.Resource.Group != "" {
- f.Path = filepath.Join("controllers", "%[group]", "suite_test.go")
+ f.Path = filepath.Join("internal", "controller", "%[group]", "suite_test.go")
} else {
- f.Path = filepath.Join("controllers", "suite_test.go")
+ f.Path = filepath.Join("internal", "controller", "suite_test.go")
}
}
@@ -60,9 +60,9 @@ func (f *SuiteTest) SetTemplateDefaults() error {
// If is multigroup the path needs to be ../../ since it has
// the group dir.
- f.CRDDirectoryRelativePath = `".."`
+ f.CRDDirectoryRelativePath = `"..",".."`
if f.MultiGroup && f.Resource.Group != "" {
- f.CRDDirectoryRelativePath = `"..", ".."`
+ f.CRDDirectoryRelativePath = `"..", "..",".."`
}
if f.Force {
@@ -126,7 +126,7 @@ const controllerSuiteTestTemplate = `{{ .Boilerplate }}
{{if and .MultiGroup .Resource.Group }}
package {{ .Resource.PackageName }}
{{else}}
-package controllers
+package controller
{{end}}
import (
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/dockerfile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/dockerfile.go
index d8032525c8c..2ac315c30b5 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/dockerfile.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/dockerfile.go
@@ -52,16 +52,16 @@ COPY go.sum go.sum
RUN go mod download
# Copy the go source
-COPY main.go main.go
+COPY cmd/main.go cmd/main.go
COPY api/ api/
-COPY controllers/ controllers/
+COPY internal/controller/ internal/controller/
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
-RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go
index f1122f5696a..f95541d69de 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/main.go
@@ -23,7 +23,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
)
-const defaultMainPath = "main.go"
+const defaultMainPath = "cmd/main.go"
var _ machinery.Template = &Main{}
@@ -53,7 +53,7 @@ func (f *Main) SetTemplateDefaults() error {
var _ machinery.Inserter = &MainUpdater{}
-// MainUpdater updates main.go to run Controllers
+// MainUpdater updates cmd/main.go to run Controllers
type MainUpdater struct { //nolint:maligned
machinery.RepositoryMixin
machinery.MultiGroupMixin
@@ -91,13 +91,13 @@ func (f *MainUpdater) GetMarkers() []machinery.Marker {
const (
apiImportCodeFragment = `%s "%s"
`
- controllerImportCodeFragment = `"%s/controllers"
+ controllerImportCodeFragment = `"%s/internal/controller"
`
- multiGroupControllerImportCodeFragment = `%scontrollers "%s/controllers/%s"
+ multiGroupControllerImportCodeFragment = `%scontroller "%s/internal/controller/%s"
`
addschemeCodeFragment = `utilruntime.Must(%s.AddToScheme(scheme))
`
- reconcilerSetupCodeFragment = `if err = (&controllers.%sReconciler{
+ reconcilerSetupCodeFragment = `if err = (&controller.%sReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -105,7 +105,7 @@ const (
os.Exit(1)
}
`
- multiGroupReconcilerSetupCodeFragment = `if err = (&%scontrollers.%sReconciler{
+ multiGroupReconcilerSetupCodeFragment = `if err = (&%scontroller.%sReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go
index 101411755cf..04725c9ec0c 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go
@@ -122,11 +122,11 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
- go build -o bin/manager main.go
+ go build -o bin/manager cmd/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
- go run ./main.go
+ go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
diff --git a/test/e2e/v4/generate_test.go b/test/e2e/v4/generate_test.go
index f285bc2d794..c5d2702f32e 100644
--- a/test/e2e/v4/generate_test.go
+++ b/test/e2e/v4/generate_test.go
@@ -25,12 +25,8 @@ import (
//nolint:golint
//nolint:revive
- . "github.com/onsi/ginkgo/v2"
-
//nolint:golint
//nolint:revive
- . "github.com/onsi/gomega"
-
"sigs.k8s.io/kubebuilder/v3/test/e2e/utils"
)
diff --git a/testdata/project-v4-config/Dockerfile b/testdata/project-v4-config/Dockerfile
index 8f9cca18eb6..ef4cfaf90bd 100644
--- a/testdata/project-v4-config/Dockerfile
+++ b/testdata/project-v4-config/Dockerfile
@@ -12,16 +12,16 @@ COPY go.sum go.sum
RUN go mod download
# Copy the go source
-COPY main.go main.go
+COPY cmd/main.go cmd/main.go
COPY api/ api/
-COPY controllers/ controllers/
+COPY internal/controller/ internal/controller/
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
-RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
diff --git a/testdata/project-v4-config/Makefile b/testdata/project-v4-config/Makefile
index 2f361a625c7..496e0260937 100644
--- a/testdata/project-v4-config/Makefile
+++ b/testdata/project-v4-config/Makefile
@@ -62,11 +62,11 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
- go build -o bin/manager main.go
+ go build -o bin/manager cmd/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
- go run ./main.go
+ go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
diff --git a/testdata/project-v4-config/main.go b/testdata/project-v4-config/cmd/main.go
similarity index 94%
rename from testdata/project-v4-config/main.go
rename to testdata/project-v4-config/cmd/main.go
index 296c9d8af21..ad43bbdd413 100644
--- a/testdata/project-v4-config/main.go
+++ b/testdata/project-v4-config/cmd/main.go
@@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-config/api/v1"
- "sigs.k8s.io/kubebuilder/testdata/project-v4-config/controllers"
+ "sigs.k8s.io/kubebuilder/testdata/project-v4-config/internal/controller"
//+kubebuilder:scaffold:imports
)
@@ -78,7 +78,7 @@ func main() {
os.Exit(1)
}
- if err = (&controllers.CaptainReconciler{
+ if err = (&controller.CaptainReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -89,7 +89,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
}
- if err = (&controllers.FirstMateReconciler{
+ if err = (&controller.FirstMateReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -100,7 +100,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "FirstMate")
os.Exit(1)
}
- if err = (&controllers.AdmiralReconciler{
+ if err = (&controller.AdmiralReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -111,7 +111,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Admiral")
os.Exit(1)
}
- if err = (&controllers.LakerReconciler{
+ if err = (&controller.LakerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
diff --git a/testdata/project-v4-config/controllers/admiral_controller.go b/testdata/project-v4-config/internal/controller/admiral_controller.go
similarity index 99%
rename from testdata/project-v4-config/controllers/admiral_controller.go
rename to testdata/project-v4-config/internal/controller/admiral_controller.go
index feded9e9a3f..4ab108aac1e 100644
--- a/testdata/project-v4-config/controllers/admiral_controller.go
+++ b/testdata/project-v4-config/internal/controller/admiral_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-config/controllers/captain_controller.go b/testdata/project-v4-config/internal/controller/captain_controller.go
similarity index 99%
rename from testdata/project-v4-config/controllers/captain_controller.go
rename to testdata/project-v4-config/internal/controller/captain_controller.go
index c6997086d7e..eecc9800b83 100644
--- a/testdata/project-v4-config/controllers/captain_controller.go
+++ b/testdata/project-v4-config/internal/controller/captain_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-config/controllers/firstmate_controller.go b/testdata/project-v4-config/internal/controller/firstmate_controller.go
similarity index 99%
rename from testdata/project-v4-config/controllers/firstmate_controller.go
rename to testdata/project-v4-config/internal/controller/firstmate_controller.go
index 55e8d0dbba0..e25d255f9c6 100644
--- a/testdata/project-v4-config/controllers/firstmate_controller.go
+++ b/testdata/project-v4-config/internal/controller/firstmate_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4/controllers/laker_controller.go b/testdata/project-v4-config/internal/controller/laker_controller.go
similarity index 99%
rename from testdata/project-v4/controllers/laker_controller.go
rename to testdata/project-v4-config/internal/controller/laker_controller.go
index 9e9536c1b2e..71f204eeef8 100644
--- a/testdata/project-v4/controllers/laker_controller.go
+++ b/testdata/project-v4-config/internal/controller/laker_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-multigroup/controllers/crew/suite_test.go b/testdata/project-v4-config/internal/controller/suite_test.go
similarity index 95%
rename from testdata/project-v4-multigroup/controllers/crew/suite_test.go
rename to testdata/project-v4-config/internal/controller/suite_test.go
index 686e7eb5a0e..9921c464a6e 100644
--- a/testdata/project-v4-multigroup/controllers/crew/suite_test.go
+++ b/testdata/project-v4-config/internal/controller/suite_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package crew
+package controller
import (
"path/filepath"
@@ -30,7 +30,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/crew/v1"
+ crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-config/api/v1"
//+kubebuilder:scaffold:imports
)
diff --git a/testdata/project-v4-declarative-v1/Dockerfile b/testdata/project-v4-declarative-v1/Dockerfile
index c4733c56e1b..0aaf979e1dc 100644
--- a/testdata/project-v4-declarative-v1/Dockerfile
+++ b/testdata/project-v4-declarative-v1/Dockerfile
@@ -12,9 +12,9 @@ COPY go.sum go.sum
RUN go mod download
# Copy the go source
-COPY main.go main.go
+COPY cmd/main.go cmd/main.go
COPY api/ api/
-COPY controllers/ controllers/
+COPY internal/controller/ internal/controller/
# https://github.com/kubernetes-sigs/kubebuilder-declarative-pattern/blob/master/docs/addon/walkthrough/README.md#adding-a-manifest
# Stage channels and make readable
COPY channels/ /channels/
@@ -25,7 +25,7 @@ RUN chmod -R a+rx /channels/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
-RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
diff --git a/testdata/project-v4-declarative-v1/Makefile b/testdata/project-v4-declarative-v1/Makefile
index 2f361a625c7..496e0260937 100644
--- a/testdata/project-v4-declarative-v1/Makefile
+++ b/testdata/project-v4-declarative-v1/Makefile
@@ -62,11 +62,11 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
- go build -o bin/manager main.go
+ go build -o bin/manager cmd/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
- go run ./main.go
+ go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
diff --git a/testdata/project-v4-declarative-v1/main.go b/testdata/project-v4-declarative-v1/cmd/main.go
similarity index 95%
rename from testdata/project-v4-declarative-v1/main.go
rename to testdata/project-v4-declarative-v1/cmd/main.go
index 6bf66f320f2..2efba338554 100644
--- a/testdata/project-v4-declarative-v1/main.go
+++ b/testdata/project-v4-declarative-v1/cmd/main.go
@@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-declarative-v1/api/v1"
- "sigs.k8s.io/kubebuilder/testdata/project-v4-declarative-v1/controllers"
+ "sigs.k8s.io/kubebuilder/testdata/project-v4-declarative-v1/internal/controller"
//+kubebuilder:scaffold:imports
)
@@ -89,21 +89,21 @@ func main() {
os.Exit(1)
}
- if err = (&controllers.CaptainReconciler{
+ if err = (&controller.CaptainReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Captain")
os.Exit(1)
}
- if err = (&controllers.FirstMateReconciler{
+ if err = (&controller.FirstMateReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "FirstMate")
os.Exit(1)
}
- if err = (&controllers.AdmiralReconciler{
+ if err = (&controller.AdmiralReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
diff --git a/testdata/project-v4-declarative-v1/controllers/admiral_controller.go b/testdata/project-v4-declarative-v1/internal/controller/admiral_controller.go
similarity index 99%
rename from testdata/project-v4-declarative-v1/controllers/admiral_controller.go
rename to testdata/project-v4-declarative-v1/internal/controller/admiral_controller.go
index b36af579f73..909e8462785 100644
--- a/testdata/project-v4-declarative-v1/controllers/admiral_controller.go
+++ b/testdata/project-v4-declarative-v1/internal/controller/admiral_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"github.com/go-logr/logr"
diff --git a/testdata/project-v4-declarative-v1/controllers/captain_controller.go b/testdata/project-v4-declarative-v1/internal/controller/captain_controller.go
similarity index 99%
rename from testdata/project-v4-declarative-v1/controllers/captain_controller.go
rename to testdata/project-v4-declarative-v1/internal/controller/captain_controller.go
index 38e58756a54..091333d34bf 100644
--- a/testdata/project-v4-declarative-v1/controllers/captain_controller.go
+++ b/testdata/project-v4-declarative-v1/internal/controller/captain_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"github.com/go-logr/logr"
diff --git a/testdata/project-v4-declarative-v1/controllers/firstmate_controller.go b/testdata/project-v4-declarative-v1/internal/controller/firstmate_controller.go
similarity index 99%
rename from testdata/project-v4-declarative-v1/controllers/firstmate_controller.go
rename to testdata/project-v4-declarative-v1/internal/controller/firstmate_controller.go
index 8cea99c2aea..6f12c13cfd0 100644
--- a/testdata/project-v4-declarative-v1/controllers/firstmate_controller.go
+++ b/testdata/project-v4-declarative-v1/internal/controller/firstmate_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"github.com/go-logr/logr"
diff --git a/testdata/project-v4-declarative-v1/controllers/suite_test.go b/testdata/project-v4-declarative-v1/internal/controller/suite_test.go
similarity index 95%
rename from testdata/project-v4-declarative-v1/controllers/suite_test.go
rename to testdata/project-v4-declarative-v1/internal/controller/suite_test.go
index 960328975df..8c1f448c14a 100644
--- a/testdata/project-v4-declarative-v1/controllers/suite_test.go
+++ b/testdata/project-v4-declarative-v1/internal/controller/suite_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"path/filepath"
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/Dockerfile b/testdata/project-v4-multigroup/Dockerfile
index 8e7dcf7a007..ef4cfaf90bd 100644
--- a/testdata/project-v4-multigroup/Dockerfile
+++ b/testdata/project-v4-multigroup/Dockerfile
@@ -12,16 +12,16 @@ COPY go.sum go.sum
RUN go mod download
# Copy the go source
-COPY main.go main.go
-COPY apis/ apis/
-COPY controllers/ controllers/
+COPY cmd/main.go cmd/main.go
+COPY api/ api/
+COPY internal/controller/ internal/controller/
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
-RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile
index 2f361a625c7..496e0260937 100644
--- a/testdata/project-v4-multigroup/Makefile
+++ b/testdata/project-v4-multigroup/Makefile
@@ -62,11 +62,11 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
- go build -o bin/manager main.go
+ go build -o bin/manager cmd/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
- go run ./main.go
+ go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
diff --git a/testdata/project-v4-multigroup/PROJECT b/testdata/project-v4-multigroup/PROJECT
index efe0381f3a0..60096e6e453 100644
--- a/testdata/project-v4-multigroup/PROJECT
+++ b/testdata/project-v4-multigroup/PROJECT
@@ -16,7 +16,7 @@ resources:
domain: testproject.org
group: crew
kind: Captain
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/crew/v1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/crew/v1
version: v1
webhooks:
defaulting: true
@@ -29,7 +29,7 @@ resources:
domain: testproject.org
group: ship
kind: Frigate
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1beta1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1beta1
version: v1beta1
webhooks:
conversion: true
@@ -40,7 +40,7 @@ resources:
domain: testproject.org
group: ship
kind: Destroyer
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1
version: v1
webhooks:
defaulting: true
@@ -51,7 +51,7 @@ resources:
domain: testproject.org
group: ship
kind: Cruiser
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v2alpha1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v2alpha1
version: v2alpha1
webhooks:
validation: true
@@ -63,7 +63,7 @@ resources:
domain: testproject.org
group: sea-creatures
kind: Kraken
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta1
version: v1beta1
- api:
crdVersion: v1
@@ -72,7 +72,7 @@ resources:
domain: testproject.org
group: sea-creatures
kind: Leviathan
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta2
version: v1beta2
- api:
crdVersion: v1
@@ -81,7 +81,7 @@ resources:
domain: testproject.org
group: foo.policy
kind: HealthCheckPolicy
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo.policy/v1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo.policy/v1
version: v1
- controller: true
group: apps
@@ -95,7 +95,7 @@ resources:
domain: testproject.org
group: foo
kind: Bar
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo/v1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo/v1
version: v1
- api:
crdVersion: v1
@@ -104,7 +104,7 @@ resources:
domain: testproject.org
group: fiz
kind: Bar
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/fiz/v1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/fiz/v1
version: v1
- api:
crdVersion: v1
@@ -112,7 +112,7 @@ resources:
controller: true
domain: testproject.org
kind: Lakers
- path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/v1
+ path: sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/v1
version: v1
webhooks:
defaulting: true
diff --git a/testdata/project-v4-multigroup/apis/crew/v1/captain_types.go b/testdata/project-v4-multigroup/api/crew/v1/captain_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/crew/v1/captain_types.go
rename to testdata/project-v4-multigroup/api/crew/v1/captain_types.go
diff --git a/testdata/project-v4-multigroup/apis/crew/v1/captain_webhook.go b/testdata/project-v4-multigroup/api/crew/v1/captain_webhook.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/crew/v1/captain_webhook.go
rename to testdata/project-v4-multigroup/api/crew/v1/captain_webhook.go
diff --git a/testdata/project-v4-multigroup/apis/crew/v1/groupversion_info.go b/testdata/project-v4-multigroup/api/crew/v1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/crew/v1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/crew/v1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/crew/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/crew/v1/webhook_suite_test.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/crew/v1/webhook_suite_test.go
rename to testdata/project-v4-multigroup/api/crew/v1/webhook_suite_test.go
diff --git a/testdata/project-v4-multigroup/apis/crew/v1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/crew/v1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/crew/v1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/crew/v1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/fiz/v1/bar_types.go b/testdata/project-v4-multigroup/api/fiz/v1/bar_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/fiz/v1/bar_types.go
rename to testdata/project-v4-multigroup/api/fiz/v1/bar_types.go
diff --git a/testdata/project-v4-multigroup/apis/fiz/v1/groupversion_info.go b/testdata/project-v4-multigroup/api/fiz/v1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/fiz/v1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/fiz/v1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/fiz/v1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/fiz/v1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/fiz/v1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/fiz/v1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/foo.policy/v1/groupversion_info.go b/testdata/project-v4-multigroup/api/foo.policy/v1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/foo.policy/v1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/foo.policy/v1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/foo.policy/v1/healthcheckpolicy_types.go b/testdata/project-v4-multigroup/api/foo.policy/v1/healthcheckpolicy_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/foo.policy/v1/healthcheckpolicy_types.go
rename to testdata/project-v4-multigroup/api/foo.policy/v1/healthcheckpolicy_types.go
diff --git a/testdata/project-v4-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/foo.policy/v1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/foo.policy/v1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/foo.policy/v1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/foo/v1/bar_types.go b/testdata/project-v4-multigroup/api/foo/v1/bar_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/foo/v1/bar_types.go
rename to testdata/project-v4-multigroup/api/foo/v1/bar_types.go
diff --git a/testdata/project-v4-multigroup/apis/foo/v1/groupversion_info.go b/testdata/project-v4-multigroup/api/foo/v1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/foo/v1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/foo/v1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/foo/v1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/foo/v1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/foo/v1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/foo/v1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1/groupversion_info.go b/testdata/project-v4-multigroup/api/sea-creatures/v1beta1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/sea-creatures/v1beta1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/sea-creatures/v1beta1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1/kraken_types.go b/testdata/project-v4-multigroup/api/sea-creatures/v1beta1/kraken_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/sea-creatures/v1beta1/kraken_types.go
rename to testdata/project-v4-multigroup/api/sea-creatures/v1beta1/kraken_types.go
diff --git a/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/sea-creatures/v1beta1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/sea-creatures/v1beta1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/sea-creatures/v1beta1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2/groupversion_info.go b/testdata/project-v4-multigroup/api/sea-creatures/v1beta2/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/sea-creatures/v1beta2/groupversion_info.go
rename to testdata/project-v4-multigroup/api/sea-creatures/v1beta2/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2/leviathan_types.go b/testdata/project-v4-multigroup/api/sea-creatures/v1beta2/leviathan_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/sea-creatures/v1beta2/leviathan_types.go
rename to testdata/project-v4-multigroup/api/sea-creatures/v1beta2/leviathan_types.go
diff --git a/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/sea-creatures/v1beta2/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/sea-creatures/v1beta2/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/sea-creatures/v1beta2/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1/destroyer_types.go b/testdata/project-v4-multigroup/api/ship/v1/destroyer_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1/destroyer_types.go
rename to testdata/project-v4-multigroup/api/ship/v1/destroyer_types.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1/destroyer_webhook.go b/testdata/project-v4-multigroup/api/ship/v1/destroyer_webhook.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1/destroyer_webhook.go
rename to testdata/project-v4-multigroup/api/ship/v1/destroyer_webhook.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1/groupversion_info.go b/testdata/project-v4-multigroup/api/ship/v1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/ship/v1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/ship/v1/webhook_suite_test.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1/webhook_suite_test.go
rename to testdata/project-v4-multigroup/api/ship/v1/webhook_suite_test.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/ship/v1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/ship/v1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1beta1/frigate_types.go b/testdata/project-v4-multigroup/api/ship/v1beta1/frigate_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1beta1/frigate_types.go
rename to testdata/project-v4-multigroup/api/ship/v1beta1/frigate_types.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1beta1/frigate_webhook.go b/testdata/project-v4-multigroup/api/ship/v1beta1/frigate_webhook.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1beta1/frigate_webhook.go
rename to testdata/project-v4-multigroup/api/ship/v1beta1/frigate_webhook.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1beta1/groupversion_info.go b/testdata/project-v4-multigroup/api/ship/v1beta1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1beta1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/ship/v1beta1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/ship/v1beta1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v1beta1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/ship/v1beta1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v2alpha1/cruiser_types.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v2alpha1/cruiser_types.go
rename to testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_types.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v2alpha1/cruiser_webhook.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_webhook.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v2alpha1/cruiser_webhook.go
rename to testdata/project-v4-multigroup/api/ship/v2alpha1/cruiser_webhook.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v2alpha1/groupversion_info.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v2alpha1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/ship/v2alpha1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v2alpha1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/webhook_suite_test.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v2alpha1/webhook_suite_test.go
rename to testdata/project-v4-multigroup/api/ship/v2alpha1/webhook_suite_test.go
diff --git a/testdata/project-v4-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/ship/v2alpha1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/ship/v2alpha1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/ship/v2alpha1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/apis/v1/groupversion_info.go b/testdata/project-v4-multigroup/api/v1/groupversion_info.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/v1/groupversion_info.go
rename to testdata/project-v4-multigroup/api/v1/groupversion_info.go
diff --git a/testdata/project-v4-multigroup/apis/v1/lakers_types.go b/testdata/project-v4-multigroup/api/v1/lakers_types.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/v1/lakers_types.go
rename to testdata/project-v4-multigroup/api/v1/lakers_types.go
diff --git a/testdata/project-v4-multigroup/apis/v1/lakers_webhook.go b/testdata/project-v4-multigroup/api/v1/lakers_webhook.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/v1/lakers_webhook.go
rename to testdata/project-v4-multigroup/api/v1/lakers_webhook.go
diff --git a/testdata/project-v4-multigroup/apis/v1/webhook_suite_test.go b/testdata/project-v4-multigroup/api/v1/webhook_suite_test.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/v1/webhook_suite_test.go
rename to testdata/project-v4-multigroup/api/v1/webhook_suite_test.go
diff --git a/testdata/project-v4-multigroup/apis/v1/zz_generated.deepcopy.go b/testdata/project-v4-multigroup/api/v1/zz_generated.deepcopy.go
similarity index 100%
rename from testdata/project-v4-multigroup/apis/v1/zz_generated.deepcopy.go
rename to testdata/project-v4-multigroup/api/v1/zz_generated.deepcopy.go
diff --git a/testdata/project-v4-multigroup/main.go b/testdata/project-v4-multigroup/cmd/main.go
similarity index 83%
rename from testdata/project-v4-multigroup/main.go
rename to testdata/project-v4-multigroup/cmd/main.go
index fb53924ca8f..98e96acd3ed 100644
--- a/testdata/project-v4-multigroup/main.go
+++ b/testdata/project-v4-multigroup/cmd/main.go
@@ -31,24 +31,24 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/crew/v1"
- fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/fiz/v1"
- foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo.policy/v1"
- foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo/v1"
- seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1"
- seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2"
- shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1"
- shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1beta1"
- shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v2alpha1"
- testprojectorgv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/v1"
- "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers"
- appscontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/apps"
- crewcontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/crew"
- fizcontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/fiz"
- foocontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/foo"
- foopolicycontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/foo.policy"
- seacreaturescontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/sea-creatures"
- shipcontrollers "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/controllers/ship"
+ crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/crew/v1"
+ fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/fiz/v1"
+ foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo.policy/v1"
+ foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo/v1"
+ seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta1"
+ seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta2"
+ shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1"
+ shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1beta1"
+ shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v2alpha1"
+ testprojectorgv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/v1"
+ "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller"
+ appscontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/apps"
+ crewcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/crew"
+ fizcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/fiz"
+ foocontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/foo"
+ foopolicycontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/foo.policy"
+ seacreaturescontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/sea-creatures"
+ shipcontroller "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/internal/controller/ship"
//+kubebuilder:scaffold:imports
)
@@ -114,7 +114,7 @@ func main() {
os.Exit(1)
}
- if err = (&crewcontrollers.CaptainReconciler{
+ if err = (&crewcontroller.CaptainReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -125,7 +125,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
}
- if err = (&shipcontrollers.FrigateReconciler{
+ if err = (&shipcontroller.FrigateReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -136,7 +136,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Frigate")
os.Exit(1)
}
- if err = (&shipcontrollers.DestroyerReconciler{
+ if err = (&shipcontroller.DestroyerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -147,7 +147,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Destroyer")
os.Exit(1)
}
- if err = (&shipcontrollers.CruiserReconciler{
+ if err = (&shipcontroller.CruiserReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -158,49 +158,49 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser")
os.Exit(1)
}
- if err = (&seacreaturescontrollers.KrakenReconciler{
+ if err = (&seacreaturescontroller.KrakenReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Kraken")
os.Exit(1)
}
- if err = (&seacreaturescontrollers.LeviathanReconciler{
+ if err = (&seacreaturescontroller.LeviathanReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Leviathan")
os.Exit(1)
}
- if err = (&foopolicycontrollers.HealthCheckPolicyReconciler{
+ if err = (&foopolicycontroller.HealthCheckPolicyReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "HealthCheckPolicy")
os.Exit(1)
}
- if err = (&appscontrollers.DeploymentReconciler{
+ if err = (&appscontroller.DeploymentReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Deployment")
os.Exit(1)
}
- if err = (&foocontrollers.BarReconciler{
+ if err = (&foocontroller.BarReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Bar")
os.Exit(1)
}
- if err = (&fizcontrollers.BarReconciler{
+ if err = (&fizcontroller.BarReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Bar")
os.Exit(1)
}
- if err = (&controllers.LakersReconciler{
+ if err = (&controller.LakersReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
diff --git a/testdata/project-v4-multigroup/controllers/apps/deployment_controller.go b/testdata/project-v4-multigroup/internal/controller/apps/deployment_controller.go
similarity index 100%
rename from testdata/project-v4-multigroup/controllers/apps/deployment_controller.go
rename to testdata/project-v4-multigroup/internal/controller/apps/deployment_controller.go
diff --git a/testdata/project-v4-multigroup/controllers/apps/suite_test.go b/testdata/project-v4-multigroup/internal/controller/apps/suite_test.go
similarity index 95%
rename from testdata/project-v4-multigroup/controllers/apps/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/apps/suite_test.go
index 08290b1d050..462ca84cb4b 100644
--- a/testdata/project-v4-multigroup/controllers/apps/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/apps/suite_test.go
@@ -51,7 +51,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: false,
}
diff --git a/testdata/project-v4-multigroup/controllers/crew/captain_controller.go b/testdata/project-v4-multigroup/internal/controller/crew/captain_controller.go
similarity index 99%
rename from testdata/project-v4-multigroup/controllers/crew/captain_controller.go
rename to testdata/project-v4-multigroup/internal/controller/crew/captain_controller.go
index a113bc63867..1b89ca19458 100644
--- a/testdata/project-v4-multigroup/controllers/crew/captain_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/crew/captain_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/crew/v1"
+ crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/crew/v1"
)
// CaptainReconciler reconciles a Captain object
diff --git a/testdata/project-v4-config/controllers/suite_test.go b/testdata/project-v4-multigroup/internal/controller/crew/suite_test.go
similarity index 91%
rename from testdata/project-v4-config/controllers/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/crew/suite_test.go
index 1c61e38a95d..594c8a03d22 100644
--- a/testdata/project-v4-config/controllers/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/crew/suite_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package crew
import (
"path/filepath"
@@ -30,7 +30,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-config/api/v1"
+ crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/crew/v1"
//+kubebuilder:scaffold:imports
)
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/controllers/fiz/bar_controller.go b/testdata/project-v4-multigroup/internal/controller/fiz/bar_controller.go
similarity index 99%
rename from testdata/project-v4-multigroup/controllers/fiz/bar_controller.go
rename to testdata/project-v4-multigroup/internal/controller/fiz/bar_controller.go
index 6ac7c405478..3cfa99bfb46 100644
--- a/testdata/project-v4-multigroup/controllers/fiz/bar_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/fiz/bar_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/fiz/v1"
+ fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/fiz/v1"
)
// BarReconciler reconciles a Bar object
diff --git a/testdata/project-v4-multigroup/controllers/fiz/suite_test.go b/testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go
similarity index 95%
rename from testdata/project-v4-multigroup/controllers/fiz/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go
index 0615d928f66..bb0540abad0 100644
--- a/testdata/project-v4-multigroup/controllers/fiz/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/fiz/suite_test.go
@@ -30,7 +30,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/fiz/v1"
+ fizv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/fiz/v1"
//+kubebuilder:scaffold:imports
)
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/controllers/foo.policy/healthcheckpolicy_controller.go b/testdata/project-v4-multigroup/internal/controller/foo.policy/healthcheckpolicy_controller.go
similarity index 98%
rename from testdata/project-v4-multigroup/controllers/foo.policy/healthcheckpolicy_controller.go
rename to testdata/project-v4-multigroup/internal/controller/foo.policy/healthcheckpolicy_controller.go
index c6ebc03b47d..dc45ce88f8c 100644
--- a/testdata/project-v4-multigroup/controllers/foo.policy/healthcheckpolicy_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/foo.policy/healthcheckpolicy_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo.policy/v1"
+ foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo.policy/v1"
)
// HealthCheckPolicyReconciler reconciles a HealthCheckPolicy object
diff --git a/testdata/project-v4-multigroup/controllers/foo.policy/suite_test.go b/testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go
similarity index 94%
rename from testdata/project-v4-multigroup/controllers/foo.policy/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go
index 213de495121..d4da3c27001 100644
--- a/testdata/project-v4-multigroup/controllers/foo.policy/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/foo.policy/suite_test.go
@@ -30,7 +30,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo.policy/v1"
+ foopolicyv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo.policy/v1"
//+kubebuilder:scaffold:imports
)
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/controllers/foo/bar_controller.go b/testdata/project-v4-multigroup/internal/controller/foo/bar_controller.go
similarity index 99%
rename from testdata/project-v4-multigroup/controllers/foo/bar_controller.go
rename to testdata/project-v4-multigroup/internal/controller/foo/bar_controller.go
index 204721380b3..fc25e185ae7 100644
--- a/testdata/project-v4-multigroup/controllers/foo/bar_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/foo/bar_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo/v1"
+ foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo/v1"
)
// BarReconciler reconciles a Bar object
diff --git a/testdata/project-v4-multigroup/controllers/foo/suite_test.go b/testdata/project-v4-multigroup/internal/controller/foo/suite_test.go
similarity index 95%
rename from testdata/project-v4-multigroup/controllers/foo/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/foo/suite_test.go
index d38918fbd67..093d18389b7 100644
--- a/testdata/project-v4-multigroup/controllers/foo/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/foo/suite_test.go
@@ -30,7 +30,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/foo/v1"
+ foov1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/foo/v1"
//+kubebuilder:scaffold:imports
)
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/controllers/lakers_controller.go b/testdata/project-v4-multigroup/internal/controller/lakers_controller.go
similarity index 98%
rename from testdata/project-v4-multigroup/controllers/lakers_controller.go
rename to testdata/project-v4-multigroup/internal/controller/lakers_controller.go
index 4de7301a1dd..5b7ef1aa871 100644
--- a/testdata/project-v4-multigroup/controllers/lakers_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/lakers_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- testprojectorgv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/v1"
+ testprojectorgv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/v1"
)
// LakersReconciler reconciles a Lakers object
diff --git a/testdata/project-v4-multigroup/controllers/sea-creatures/kraken_controller.go b/testdata/project-v4-multigroup/internal/controller/sea-creatures/kraken_controller.go
similarity index 98%
rename from testdata/project-v4-multigroup/controllers/sea-creatures/kraken_controller.go
rename to testdata/project-v4-multigroup/internal/controller/sea-creatures/kraken_controller.go
index e1c4a323b63..2d56d29c6f4 100644
--- a/testdata/project-v4-multigroup/controllers/sea-creatures/kraken_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/sea-creatures/kraken_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1"
+ seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta1"
)
// KrakenReconciler reconciles a Kraken object
diff --git a/testdata/project-v4-multigroup/controllers/sea-creatures/leviathan_controller.go b/testdata/project-v4-multigroup/internal/controller/sea-creatures/leviathan_controller.go
similarity index 98%
rename from testdata/project-v4-multigroup/controllers/sea-creatures/leviathan_controller.go
rename to testdata/project-v4-multigroup/internal/controller/sea-creatures/leviathan_controller.go
index 7ea938670f0..a46e27aab68 100644
--- a/testdata/project-v4-multigroup/controllers/sea-creatures/leviathan_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/sea-creatures/leviathan_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2"
+ seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta2"
)
// LeviathanReconciler reconciles a Leviathan object
diff --git a/testdata/project-v4-multigroup/controllers/sea-creatures/suite_test.go b/testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go
similarity index 92%
rename from testdata/project-v4-multigroup/controllers/sea-creatures/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go
index 968ad7e2587..3d0cfcffc33 100644
--- a/testdata/project-v4-multigroup/controllers/sea-creatures/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/sea-creatures/suite_test.go
@@ -30,8 +30,8 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta1"
- seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/sea-creatures/v1beta2"
+ seacreaturesv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta1"
+ seacreaturesv1beta2 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/sea-creatures/v1beta2"
//+kubebuilder:scaffold:imports
)
@@ -53,7 +53,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/controllers/ship/cruiser_controller.go b/testdata/project-v4-multigroup/internal/controller/ship/cruiser_controller.go
similarity index 98%
rename from testdata/project-v4-multigroup/controllers/ship/cruiser_controller.go
rename to testdata/project-v4-multigroup/internal/controller/ship/cruiser_controller.go
index afb06915704..5ccbafa6e55 100644
--- a/testdata/project-v4-multigroup/controllers/ship/cruiser_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/ship/cruiser_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v2alpha1"
+ shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v2alpha1"
)
// CruiserReconciler reconciles a Cruiser object
diff --git a/testdata/project-v4-multigroup/controllers/ship/destroyer_controller.go b/testdata/project-v4-multigroup/internal/controller/ship/destroyer_controller.go
similarity index 99%
rename from testdata/project-v4-multigroup/controllers/ship/destroyer_controller.go
rename to testdata/project-v4-multigroup/internal/controller/ship/destroyer_controller.go
index 424e9ede9a1..633f0145635 100644
--- a/testdata/project-v4-multigroup/controllers/ship/destroyer_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/ship/destroyer_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1"
+ shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1"
)
// DestroyerReconciler reconciles a Destroyer object
diff --git a/testdata/project-v4-multigroup/controllers/ship/frigate_controller.go b/testdata/project-v4-multigroup/internal/controller/ship/frigate_controller.go
similarity index 98%
rename from testdata/project-v4-multigroup/controllers/ship/frigate_controller.go
rename to testdata/project-v4-multigroup/internal/controller/ship/frigate_controller.go
index 5c744e8a3a6..fd4d3f3696e 100644
--- a/testdata/project-v4-multigroup/controllers/ship/frigate_controller.go
+++ b/testdata/project-v4-multigroup/internal/controller/ship/frigate_controller.go
@@ -24,7 +24,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
- shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1beta1"
+ shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1beta1"
)
// FrigateReconciler reconciles a Frigate object
diff --git a/testdata/project-v4-multigroup/controllers/ship/suite_test.go b/testdata/project-v4-multigroup/internal/controller/ship/suite_test.go
similarity index 93%
rename from testdata/project-v4-multigroup/controllers/ship/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/ship/suite_test.go
index 1f3d1f1bfc4..608ea5f2c72 100644
--- a/testdata/project-v4-multigroup/controllers/ship/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/ship/suite_test.go
@@ -30,9 +30,9 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1"
- shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v1beta1"
- shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/ship/v2alpha1"
+ shipv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1"
+ shipv1beta1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v1beta1"
+ shipv2alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/ship/v2alpha1"
//+kubebuilder:scaffold:imports
)
@@ -54,7 +54,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-multigroup/controllers/suite_test.go b/testdata/project-v4-multigroup/internal/controller/suite_test.go
similarity index 94%
rename from testdata/project-v4-multigroup/controllers/suite_test.go
rename to testdata/project-v4-multigroup/internal/controller/suite_test.go
index 2cc3e726507..b5d44f178f8 100644
--- a/testdata/project-v4-multigroup/controllers/suite_test.go
+++ b/testdata/project-v4-multigroup/internal/controller/suite_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"path/filepath"
@@ -30,7 +30,7 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
- testprojectorgv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/apis/v1"
+ testprojectorgv1 "sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/v1"
//+kubebuilder:scaffold:imports
)
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4-with-deploy-image/Dockerfile b/testdata/project-v4-with-deploy-image/Dockerfile
index 8f9cca18eb6..ef4cfaf90bd 100644
--- a/testdata/project-v4-with-deploy-image/Dockerfile
+++ b/testdata/project-v4-with-deploy-image/Dockerfile
@@ -12,16 +12,16 @@ COPY go.sum go.sum
RUN go mod download
# Copy the go source
-COPY main.go main.go
+COPY cmd/main.go cmd/main.go
COPY api/ api/
-COPY controllers/ controllers/
+COPY internal/controller/ internal/controller/
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
-RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
diff --git a/testdata/project-v4-with-deploy-image/Makefile b/testdata/project-v4-with-deploy-image/Makefile
index 2f361a625c7..496e0260937 100644
--- a/testdata/project-v4-with-deploy-image/Makefile
+++ b/testdata/project-v4-with-deploy-image/Makefile
@@ -62,11 +62,11 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
- go build -o bin/manager main.go
+ go build -o bin/manager cmd/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
- go run ./main.go
+ go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
diff --git a/testdata/project-v4-with-deploy-image/main.go b/testdata/project-v4-with-deploy-image/cmd/main.go
similarity index 97%
rename from testdata/project-v4-with-deploy-image/main.go
rename to testdata/project-v4-with-deploy-image/cmd/main.go
index 59d643f1727..a60667a4d2c 100644
--- a/testdata/project-v4-with-deploy-image/main.go
+++ b/testdata/project-v4-with-deploy-image/cmd/main.go
@@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
examplecomv1alpha1 "sigs.k8s.io/kubebuilder/testdata/project-v4-with-deploy-image/api/v1alpha1"
- "sigs.k8s.io/kubebuilder/testdata/project-v4-with-deploy-image/controllers"
+ "sigs.k8s.io/kubebuilder/testdata/project-v4-with-deploy-image/internal/controller"
//+kubebuilder:scaffold:imports
)
@@ -89,7 +89,7 @@ func main() {
os.Exit(1)
}
- if err = (&controllers.MemcachedReconciler{
+ if err = (&controller.MemcachedReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("memcached-controller"),
@@ -97,7 +97,7 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Memcached")
os.Exit(1)
}
- if err = (&controllers.BusyboxReconciler{
+ if err = (&controller.BusyboxReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("busybox-controller"),
diff --git a/testdata/project-v4-with-deploy-image/controllers/busybox_controller.go b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go
similarity index 99%
rename from testdata/project-v4-with-deploy-image/controllers/busybox_controller.go
rename to testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go
index 297fdf12af3..b8da2da34ec 100644
--- a/testdata/project-v4-with-deploy-image/controllers/busybox_controller.go
+++ b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-with-deploy-image/controllers/busybox_controller_test.go b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go
similarity index 99%
rename from testdata/project-v4-with-deploy-image/controllers/busybox_controller_test.go
rename to testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go
index 655aaaac694..8540d8a62ee 100644
--- a/testdata/project-v4-with-deploy-image/controllers/busybox_controller_test.go
+++ b/testdata/project-v4-with-deploy-image/internal/controller/busybox_controller_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-with-deploy-image/controllers/memcached_controller.go b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go
similarity index 99%
rename from testdata/project-v4-with-deploy-image/controllers/memcached_controller.go
rename to testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go
index a6950224103..3930389fdb9 100644
--- a/testdata/project-v4-with-deploy-image/controllers/memcached_controller.go
+++ b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-with-deploy-image/controllers/memcached_controller_test.go b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go
similarity index 99%
rename from testdata/project-v4-with-deploy-image/controllers/memcached_controller_test.go
rename to testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go
index cbedf08c7e7..22c35204ccd 100644
--- a/testdata/project-v4-with-deploy-image/controllers/memcached_controller_test.go
+++ b/testdata/project-v4-with-deploy-image/internal/controller/memcached_controller_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-with-deploy-image/controllers/suite_test.go b/testdata/project-v4-with-deploy-image/internal/controller/suite_test.go
similarity index 95%
rename from testdata/project-v4-with-deploy-image/controllers/suite_test.go
rename to testdata/project-v4-with-deploy-image/internal/controller/suite_test.go
index d98a393008f..fcacc534e1b 100644
--- a/testdata/project-v4-with-deploy-image/controllers/suite_test.go
+++ b/testdata/project-v4-with-deploy-image/internal/controller/suite_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"path/filepath"
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}
diff --git a/testdata/project-v4/Dockerfile b/testdata/project-v4/Dockerfile
index 8f9cca18eb6..ef4cfaf90bd 100644
--- a/testdata/project-v4/Dockerfile
+++ b/testdata/project-v4/Dockerfile
@@ -12,16 +12,16 @@ COPY go.sum go.sum
RUN go mod download
# Copy the go source
-COPY main.go main.go
+COPY cmd/main.go cmd/main.go
COPY api/ api/
-COPY controllers/ controllers/
+COPY internal/controller/ internal/controller/
# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
-RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
+RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile
index 2f361a625c7..496e0260937 100644
--- a/testdata/project-v4/Makefile
+++ b/testdata/project-v4/Makefile
@@ -62,11 +62,11 @@ test: manifests generate fmt vet envtest ## Run tests.
.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
- go build -o bin/manager main.go
+ go build -o bin/manager cmd/main.go
.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
- go run ./main.go
+ go run ./cmd/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
diff --git a/testdata/project-v4/main.go b/testdata/project-v4/cmd/main.go
similarity index 95%
rename from testdata/project-v4/main.go
rename to testdata/project-v4/cmd/main.go
index 1c44a24f4dc..c4f9fa7c07e 100644
--- a/testdata/project-v4/main.go
+++ b/testdata/project-v4/cmd/main.go
@@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
crewv1 "sigs.k8s.io/kubebuilder/testdata/project-v4/api/v1"
- "sigs.k8s.io/kubebuilder/testdata/project-v4/controllers"
+ "sigs.k8s.io/kubebuilder/testdata/project-v4/internal/controller"
//+kubebuilder:scaffold:imports
)
@@ -89,7 +89,7 @@ func main() {
os.Exit(1)
}
- if err = (&controllers.CaptainReconciler{
+ if err = (&controller.CaptainReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -100,7 +100,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
}
- if err = (&controllers.FirstMateReconciler{
+ if err = (&controller.FirstMateReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -111,7 +111,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "FirstMate")
os.Exit(1)
}
- if err = (&controllers.AdmiralReconciler{
+ if err = (&controller.AdmiralReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
@@ -122,7 +122,7 @@ func main() {
setupLog.Error(err, "unable to create webhook", "webhook", "Admiral")
os.Exit(1)
}
- if err = (&controllers.LakerReconciler{
+ if err = (&controller.LakerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
diff --git a/testdata/project-v4/controllers/admiral_controller.go b/testdata/project-v4/internal/controller/admiral_controller.go
similarity index 99%
rename from testdata/project-v4/controllers/admiral_controller.go
rename to testdata/project-v4/internal/controller/admiral_controller.go
index 66f23dc0b2f..b5ffcacee81 100644
--- a/testdata/project-v4/controllers/admiral_controller.go
+++ b/testdata/project-v4/internal/controller/admiral_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4/controllers/captain_controller.go b/testdata/project-v4/internal/controller/captain_controller.go
similarity index 99%
rename from testdata/project-v4/controllers/captain_controller.go
rename to testdata/project-v4/internal/controller/captain_controller.go
index 88f53b380f3..31006c12364 100644
--- a/testdata/project-v4/controllers/captain_controller.go
+++ b/testdata/project-v4/internal/controller/captain_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4/controllers/firstmate_controller.go b/testdata/project-v4/internal/controller/firstmate_controller.go
similarity index 99%
rename from testdata/project-v4/controllers/firstmate_controller.go
rename to testdata/project-v4/internal/controller/firstmate_controller.go
index d5b5100ce81..2c2e35297ea 100644
--- a/testdata/project-v4/controllers/firstmate_controller.go
+++ b/testdata/project-v4/internal/controller/firstmate_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4-config/controllers/laker_controller.go b/testdata/project-v4/internal/controller/laker_controller.go
similarity index 99%
rename from testdata/project-v4-config/controllers/laker_controller.go
rename to testdata/project-v4/internal/controller/laker_controller.go
index 9e9536c1b2e..71f204eeef8 100644
--- a/testdata/project-v4-config/controllers/laker_controller.go
+++ b/testdata/project-v4/internal/controller/laker_controller.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"context"
diff --git a/testdata/project-v4/controllers/suite_test.go b/testdata/project-v4/internal/controller/suite_test.go
similarity index 95%
rename from testdata/project-v4/controllers/suite_test.go
rename to testdata/project-v4/internal/controller/suite_test.go
index d17fdb2d4ad..8b12cc5e27e 100644
--- a/testdata/project-v4/controllers/suite_test.go
+++ b/testdata/project-v4/internal/controller/suite_test.go
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-package controllers
+package controller
import (
"path/filepath"
@@ -52,7 +52,7 @@ var _ = BeforeSuite(func() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
- CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")},
+ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
}