From 6fde51d7c79f0df629a4e1bec5e0d78d444b85cd Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Thu, 4 Jun 2020 10:54:02 -0700 Subject: [PATCH] All scaffold templates and machinery are housed under pkg/plugin since that machinery directly and only relates to plugins. Scaffold templates are also versioned with plugin major version, ex. pkg/plugin/v2. --- cmd/edit.go | 5 +++-- internal/cmdutil/cmdutil.go | 2 +- .../internal/filesystem/errors.go | 0 .../internal/filesystem/errors_test.go | 0 .../internal/filesystem/filesystem.go | 0 .../internal/filesystem/filesystem_test.go | 0 .../internal/filesystem/mock.go | 0 .../internal/filesystem/mock_test.go | 0 .../internal/machinery/errors.go | 0 .../internal/machinery/errors_test.go | 0 .../internal/machinery/scaffold.go | 2 +- .../internal/machinery/scaffold_test.go | 2 +- pkg/plugin/internal/{ => util}/exec.go | 2 +- pkg/plugin/internal/{ => util}/go_version.go | 2 +- .../internal/{ => util}/go_version_test.go | 2 +- pkg/plugin/internal/{ => util}/repository.go | 2 +- pkg/plugin/internal/{ => util}/stdin.go | 2 +- pkg/{ => plugin}/scaffold/interface.go | 0 pkg/plugin/v2/api.go | 20 +++++++++--------- pkg/plugin/v2/init.go | 19 +++++++++-------- pkg/{scaffold => plugin/v2/scaffolds}/api.go | 15 ++++++------- pkg/{scaffold => plugin/v2/scaffolds}/doc.go | 2 +- pkg/{scaffold => plugin/v2/scaffolds}/edit.go | 7 ++++--- pkg/{scaffold => plugin/v2/scaffolds}/init.go | 21 ++++++++++--------- .../internal/templates/authproxyrole.go | 0 .../templates/authproxyrolebinding.go | 0 .../internal/templates/boilerplate.go | 0 .../templates/certmanager/certificate.go | 0 .../templates/certmanager/kustomize.go | 0 .../templates/certmanager/kustomizeconfig.go | 0 .../templates/controller/controller.go | 0 .../controller/controller_suitetest.go | 0 .../templates/crd/enablecainjection_patch.go | 0 .../templates/crd/enablewebhook_patch.go | 0 .../internal/templates/crd/kustomization.go | 0 .../internal/templates/crd/kustomizeconfig.go | 0 .../internal/templates/crd_editor_rbac.go | 0 .../internal/templates/crd_sample.go | 0 .../internal/templates/crd_viewer_rbac.go | 0 .../internal/templates/dockerfile.go | 0 .../internal/templates/gitignore.go | 0 .../v2/scaffolds}/internal/templates/gomod.go | 0 .../v2/scaffolds}/internal/templates/group.go | 0 .../internal/templates/kustomize.go | 0 .../internal/templates/leaderelectionrole.go | 0 .../templates/leaderelectionrolebinding.go | 0 .../v2/scaffolds}/internal/templates/main.go | 0 .../scaffolds}/internal/templates/makefile.go | 0 .../internal/templates/manager/config.go | 0 .../templates/manager/kustomization.go | 0 .../templates/metricsauth/auth_proxy_patch.go | 0 .../templates/metricsauth/authproxyservice.go | 0 .../metricsauth/clientclusterrole.go | 0 .../internal/templates/mgrrolebinding.go | 0 .../templates/prometheus/kustomize.go | 0 .../internal/templates/prometheus/monitor.go | 0 .../v2/scaffolds}/internal/templates/rbac.go | 0 .../v2/scaffolds}/internal/templates/types.go | 0 .../webhook/enablecainection_patch.go | 0 .../templates/webhook/kustomization.go | 0 .../templates/webhook/kustomizeconfig.go | 0 .../internal/templates/webhook/service.go | 0 .../internal/templates/webhook/webhook.go | 0 .../templates/webhook_manager_patch.go | 0 .../v2/scaffolds}/webhook.go | 13 ++++++------ pkg/plugin/v2/webhook.go | 5 +++-- plugins/README.md | 2 +- 67 files changed, 66 insertions(+), 59 deletions(-) rename pkg/{scaffold => plugin}/internal/filesystem/errors.go (100%) rename pkg/{scaffold => plugin}/internal/filesystem/errors_test.go (100%) rename pkg/{scaffold => plugin}/internal/filesystem/filesystem.go (100%) rename pkg/{scaffold => plugin}/internal/filesystem/filesystem_test.go (100%) rename pkg/{scaffold => plugin}/internal/filesystem/mock.go (100%) rename pkg/{scaffold => plugin}/internal/filesystem/mock_test.go (100%) rename pkg/{scaffold => plugin}/internal/machinery/errors.go (100%) rename pkg/{scaffold => plugin}/internal/machinery/errors_test.go (100%) rename pkg/{scaffold => plugin}/internal/machinery/scaffold.go (99%) rename pkg/{scaffold => plugin}/internal/machinery/scaffold_test.go (99%) rename pkg/plugin/internal/{ => util}/exec.go (98%) rename pkg/plugin/internal/{ => util}/go_version.go (99%) rename pkg/plugin/internal/{ => util}/go_version_test.go (98%) rename pkg/plugin/internal/{ => util}/repository.go (99%) rename pkg/plugin/internal/{ => util}/stdin.go (98%) rename pkg/{ => plugin}/scaffold/interface.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/api.go (89%) rename pkg/{scaffold => plugin/v2/scaffolds}/doc.go (97%) rename pkg/{scaffold => plugin/v2/scaffolds}/edit.go (89%) rename pkg/{scaffold => plugin/v2/scaffolds}/init.go (84%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/authproxyrole.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/authproxyrolebinding.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/boilerplate.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/certmanager/certificate.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/certmanager/kustomize.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/certmanager/kustomizeconfig.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/controller/controller.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/controller/controller_suitetest.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd/enablecainjection_patch.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd/enablewebhook_patch.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd/kustomization.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd/kustomizeconfig.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd_editor_rbac.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd_sample.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/crd_viewer_rbac.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/dockerfile.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/gitignore.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/gomod.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/group.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/kustomize.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/leaderelectionrole.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/leaderelectionrolebinding.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/main.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/makefile.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/manager/config.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/manager/kustomization.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/metricsauth/auth_proxy_patch.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/metricsauth/authproxyservice.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/metricsauth/clientclusterrole.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/mgrrolebinding.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/prometheus/kustomize.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/prometheus/monitor.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/rbac.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/types.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/webhook/enablecainection_patch.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/webhook/kustomization.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/webhook/kustomizeconfig.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/webhook/service.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/webhook/webhook.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/internal/templates/webhook_manager_patch.go (100%) rename pkg/{scaffold => plugin/v2/scaffolds}/webhook.go (86%) diff --git a/cmd/edit.go b/cmd/edit.go index bb89a3e85b6..328fff3cd06 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -24,7 +24,8 @@ import ( "sigs.k8s.io/kubebuilder/internal/cmdutil" "sigs.k8s.io/kubebuilder/internal/config" - "sigs.k8s.io/kubebuilder/pkg/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + scaffolds "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds" ) type editError struct { @@ -80,7 +81,7 @@ func (o *editOptions) Validate() error { } func (o *editOptions) GetScaffolder() (scaffold.Scaffolder, error) { - return scaffold.NewEditScaffolder(&o.config.Config, o.multigroup), nil + return scaffolds.NewEditScaffolder(&o.config.Config, o.multigroup), nil } func (o *editOptions) PostScaffold() error { diff --git a/internal/cmdutil/cmdutil.go b/internal/cmdutil/cmdutil.go index 98ed0308765..65972398189 100644 --- a/internal/cmdutil/cmdutil.go +++ b/internal/cmdutil/cmdutil.go @@ -17,7 +17,7 @@ limitations under the License. package cmdutil import ( - "sigs.k8s.io/kubebuilder/pkg/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" ) // RunOptions represent the types used to implement the different commands diff --git a/pkg/scaffold/internal/filesystem/errors.go b/pkg/plugin/internal/filesystem/errors.go similarity index 100% rename from pkg/scaffold/internal/filesystem/errors.go rename to pkg/plugin/internal/filesystem/errors.go diff --git a/pkg/scaffold/internal/filesystem/errors_test.go b/pkg/plugin/internal/filesystem/errors_test.go similarity index 100% rename from pkg/scaffold/internal/filesystem/errors_test.go rename to pkg/plugin/internal/filesystem/errors_test.go diff --git a/pkg/scaffold/internal/filesystem/filesystem.go b/pkg/plugin/internal/filesystem/filesystem.go similarity index 100% rename from pkg/scaffold/internal/filesystem/filesystem.go rename to pkg/plugin/internal/filesystem/filesystem.go diff --git a/pkg/scaffold/internal/filesystem/filesystem_test.go b/pkg/plugin/internal/filesystem/filesystem_test.go similarity index 100% rename from pkg/scaffold/internal/filesystem/filesystem_test.go rename to pkg/plugin/internal/filesystem/filesystem_test.go diff --git a/pkg/scaffold/internal/filesystem/mock.go b/pkg/plugin/internal/filesystem/mock.go similarity index 100% rename from pkg/scaffold/internal/filesystem/mock.go rename to pkg/plugin/internal/filesystem/mock.go diff --git a/pkg/scaffold/internal/filesystem/mock_test.go b/pkg/plugin/internal/filesystem/mock_test.go similarity index 100% rename from pkg/scaffold/internal/filesystem/mock_test.go rename to pkg/plugin/internal/filesystem/mock_test.go diff --git a/pkg/scaffold/internal/machinery/errors.go b/pkg/plugin/internal/machinery/errors.go similarity index 100% rename from pkg/scaffold/internal/machinery/errors.go rename to pkg/plugin/internal/machinery/errors.go diff --git a/pkg/scaffold/internal/machinery/errors_test.go b/pkg/plugin/internal/machinery/errors_test.go similarity index 100% rename from pkg/scaffold/internal/machinery/errors_test.go rename to pkg/plugin/internal/machinery/errors_test.go diff --git a/pkg/scaffold/internal/machinery/scaffold.go b/pkg/plugin/internal/machinery/scaffold.go similarity index 99% rename from pkg/scaffold/internal/machinery/scaffold.go rename to pkg/plugin/internal/machinery/scaffold.go index 477ab733973..5eb2fae1dff 100644 --- a/pkg/scaffold/internal/machinery/scaffold.go +++ b/pkg/plugin/internal/machinery/scaffold.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/filesystem" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/filesystem" ) var options = imports.Options{ diff --git a/pkg/scaffold/internal/machinery/scaffold_test.go b/pkg/plugin/internal/machinery/scaffold_test.go similarity index 99% rename from pkg/scaffold/internal/machinery/scaffold_test.go rename to pkg/plugin/internal/machinery/scaffold_test.go index 7927b42c041..961d7d30ad2 100644 --- a/pkg/scaffold/internal/machinery/scaffold_test.go +++ b/pkg/plugin/internal/machinery/scaffold_test.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/file" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/filesystem" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/filesystem" ) func TestScaffold(t *testing.T) { diff --git a/pkg/plugin/internal/exec.go b/pkg/plugin/internal/util/exec.go similarity index 98% rename from pkg/plugin/internal/exec.go rename to pkg/plugin/internal/util/exec.go index 56e3d0ed9a1..6e9d7085cfc 100644 --- a/pkg/plugin/internal/exec.go +++ b/pkg/plugin/internal/util/exec.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package internal +package util import ( "fmt" diff --git a/pkg/plugin/internal/go_version.go b/pkg/plugin/internal/util/go_version.go similarity index 99% rename from pkg/plugin/internal/go_version.go rename to pkg/plugin/internal/util/go_version.go index a07dcd8e053..336ac6ca873 100644 --- a/pkg/plugin/internal/go_version.go +++ b/pkg/plugin/internal/util/go_version.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package internal +package util import ( "fmt" diff --git a/pkg/plugin/internal/go_version_test.go b/pkg/plugin/internal/util/go_version_test.go similarity index 98% rename from pkg/plugin/internal/go_version_test.go rename to pkg/plugin/internal/util/go_version_test.go index f8a51dccb79..1814dcdd5b4 100644 --- a/pkg/plugin/internal/go_version_test.go +++ b/pkg/plugin/internal/util/go_version_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package internal +package util import ( "testing" diff --git a/pkg/plugin/internal/repository.go b/pkg/plugin/internal/util/repository.go similarity index 99% rename from pkg/plugin/internal/repository.go rename to pkg/plugin/internal/util/repository.go index c33f86afd05..5af2d1578be 100644 --- a/pkg/plugin/internal/repository.go +++ b/pkg/plugin/internal/util/repository.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package internal +package util import ( "encoding/json" diff --git a/pkg/plugin/internal/stdin.go b/pkg/plugin/internal/util/stdin.go similarity index 98% rename from pkg/plugin/internal/stdin.go rename to pkg/plugin/internal/util/stdin.go index 9bb01acfdfb..5b1f6be6971 100644 --- a/pkg/plugin/internal/stdin.go +++ b/pkg/plugin/internal/util/stdin.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package internal +package util import ( "bufio" diff --git a/pkg/scaffold/interface.go b/pkg/plugin/scaffold/interface.go similarity index 100% rename from pkg/scaffold/interface.go rename to pkg/plugin/scaffold/interface.go diff --git a/pkg/plugin/v2/api.go b/pkg/plugin/v2/api.go index c6b69519b61..9a45a1f967b 100644 --- a/pkg/plugin/v2/api.go +++ b/pkg/plugin/v2/api.go @@ -32,8 +32,9 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/plugin" - "sigs.k8s.io/kubebuilder/pkg/plugin/internal" - "sigs.k8s.io/kubebuilder/pkg/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/util" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds" "sigs.k8s.io/kubebuilder/plugins/addon" ) @@ -133,11 +134,11 @@ func (p *createAPIPlugin) Validate() error { reader := bufio.NewReader(os.Stdin) if !p.resourceFlag.Changed { fmt.Println("Create Resource [y/n]") - p.doResource = internal.YesNo(reader) + p.doResource = util.YesNo(reader) } if !p.controllerFlag.Changed { fmt.Println("Create Controller [y/n]") - p.doController = internal.YesNo(reader) + p.doController = util.YesNo(reader) } // In case we want to scaffold a resource API we need to do some checks @@ -148,8 +149,7 @@ func (p *createAPIPlugin) Validate() error { } // Check that the provided group can be added to the project - if (p.config.IsV2() || p.config.IsV3()) && !p.config.MultiGroup && - len(p.config.Resources) != 0 && !p.config.HasGroup(p.resource.Group) { + if !p.config.MultiGroup && len(p.config.Resources) != 0 && !p.config.HasGroup(p.resource.Group) { return fmt.Errorf("multiple groups are not allowed by default, to enable multi-group visit %s", "kubebuilder.io/migration/multi-group.html") } @@ -178,7 +178,7 @@ func (p *createAPIPlugin) GetScaffolder() (scaffold.Scaffolder, error) { // Create the actual resource from the resource options res := p.resource.NewResource(p.config, p.doResource) - return scaffold.NewAPIScaffolder(p.config, string(bp), res, p.doResource, p.doController, plugins), nil + return scaffolds.NewAPIScaffolder(p.config, string(bp), res, p.doResource, p.doController, plugins), nil } func (p *createAPIPlugin) PostScaffold() error { @@ -188,8 +188,8 @@ func (p *createAPIPlugin) PostScaffold() error { // Default pattern case "addon": // Ensure that we are pinning sigs.k8s.io/kubebuilder-declarative-pattern version - err := internal.RunCmd("Get controller runtime", "go", "get", - "sigs.k8s.io/kubebuilder-declarative-pattern@"+scaffold.KbDeclarativePattern) + err := util.RunCmd("Get controller runtime", "go", "get", + "sigs.k8s.io/kubebuilder-declarative-pattern@"+scaffolds.KbDeclarativePattern) if err != nil { return err } @@ -198,7 +198,7 @@ func (p *createAPIPlugin) PostScaffold() error { } if p.runMake { - return internal.RunCmd("Running make", "make") + return util.RunCmd("Running make", "make") } return nil } diff --git a/pkg/plugin/v2/init.go b/pkg/plugin/v2/init.go index 8c9c697ca3e..d85d3045da3 100644 --- a/pkg/plugin/v2/init.go +++ b/pkg/plugin/v2/init.go @@ -28,8 +28,9 @@ import ( "sigs.k8s.io/kubebuilder/pkg/internal/validation" "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/plugin" - "sigs.k8s.io/kubebuilder/pkg/plugin/internal" - "sigs.k8s.io/kubebuilder/pkg/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/util" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds" ) type initPlugin struct { @@ -107,7 +108,7 @@ func (p *initPlugin) Run() error { func (p *initPlugin) Validate() error { // Requires go1.11+ if !p.skipGoVersionCheck { - if err := internal.ValidateGoVersion(); err != nil { + if err := util.ValidateGoVersion(); err != nil { return err } } @@ -124,7 +125,7 @@ func (p *initPlugin) Validate() error { // Try to guess repository if flag is not set. if p.config.Repo == "" { - repoPath, err := internal.FindCurrentRepo() + repoPath, err := util.FindCurrentRepo() if err != nil { return fmt.Errorf("error finding current repository: %v", err) } @@ -135,7 +136,7 @@ func (p *initPlugin) Validate() error { } func (p *initPlugin) GetScaffolder() (scaffold.Scaffolder, error) { - return scaffold.NewInitScaffolder(p.config, p.license, p.owner), nil + return scaffolds.NewInitScaffolder(p.config, p.license, p.owner), nil } func (p *initPlugin) PostScaffold() error { @@ -146,18 +147,18 @@ func (p *initPlugin) PostScaffold() error { // Ensure that we are pinning controller-runtime version // xref: https://github.com/kubernetes-sigs/kubebuilder/issues/997 - err := internal.RunCmd("Get controller runtime", "go", "get", - "sigs.k8s.io/controller-runtime@"+scaffold.ControllerRuntimeVersion) + err := util.RunCmd("Get controller runtime", "go", "get", + "sigs.k8s.io/controller-runtime@"+scaffolds.ControllerRuntimeVersion) if err != nil { return err } - err = internal.RunCmd("Update go.mod", "go", "mod", "tidy") + err = util.RunCmd("Update go.mod", "go", "mod", "tidy") if err != nil { return err } - err = internal.RunCmd("Running make", "make") + err = util.RunCmd("Running make", "make") if err != nil { return err } diff --git a/pkg/scaffold/api.go b/pkg/plugin/v2/scaffolds/api.go similarity index 89% rename from pkg/scaffold/api.go rename to pkg/plugin/v2/scaffolds/api.go index 914f0ab8f38..bd9da07f861 100644 --- a/pkg/scaffold/api.go +++ b/pkg/plugin/v2/scaffolds/api.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package scaffold +package scaffolds import ( "fmt" @@ -22,17 +22,18 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/controller" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/crd" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/machinery" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/controller" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/crd" ) // (used only to gen api with --pattern=addon) // KbDeclarativePattern is the sigs.k8s.io/kubebuilder-declarative-pattern version const KbDeclarativePattern = "v0.0.0-20200522144838-848d48e5b073" -var _ Scaffolder = &apiScaffolder{} +var _ scaffold.Scaffolder = &apiScaffolder{} // apiScaffolder contains configuration for generating scaffolding for Go type // representing the API and controller that implements the behavior for the API. @@ -55,7 +56,7 @@ func NewAPIScaffolder( res *resource.Resource, doResource, doController bool, plugins []model.Plugin, -) Scaffolder { +) scaffold.Scaffolder { return &apiScaffolder{ config: config, boilerplate: boilerplate, diff --git a/pkg/scaffold/doc.go b/pkg/plugin/v2/scaffolds/doc.go similarity index 97% rename from pkg/scaffold/doc.go rename to pkg/plugin/v2/scaffolds/doc.go index 583a19eb4ea..463ece622a5 100644 --- a/pkg/scaffold/doc.go +++ b/pkg/plugin/v2/scaffolds/doc.go @@ -15,4 +15,4 @@ limitations under the License. */ // Package scaffold contains libraries for scaffolding code to use with controller-runtime -package scaffold +package scaffolds diff --git a/pkg/scaffold/edit.go b/pkg/plugin/v2/scaffolds/edit.go similarity index 89% rename from pkg/scaffold/edit.go rename to pkg/plugin/v2/scaffolds/edit.go index bb83f25ce2e..08221c98c30 100644 --- a/pkg/scaffold/edit.go +++ b/pkg/plugin/v2/scaffolds/edit.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package scaffold +package scaffolds import ( "fmt" @@ -22,9 +22,10 @@ import ( "strings" "sigs.k8s.io/kubebuilder/pkg/model/config" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" ) -var _ Scaffolder = &editScaffolder{} +var _ scaffold.Scaffolder = &editScaffolder{} type editScaffolder struct { config *config.Config @@ -32,7 +33,7 @@ type editScaffolder struct { } // NewEditScaffolder returns a new Scaffolder for configuration edit operations -func NewEditScaffolder(config *config.Config, multigroup bool) Scaffolder { +func NewEditScaffolder(config *config.Config, multigroup bool) scaffold.Scaffolder { return &editScaffolder{ config: config, multigroup: multigroup, diff --git a/pkg/scaffold/init.go b/pkg/plugin/v2/scaffolds/init.go similarity index 84% rename from pkg/scaffold/init.go rename to pkg/plugin/v2/scaffolds/init.go index a8380198580..0df668111b2 100644 --- a/pkg/scaffold/init.go +++ b/pkg/plugin/v2/scaffolds/init.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package scaffold +package scaffolds import ( "fmt" @@ -23,13 +23,14 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/config" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/certmanager" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/manager" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/metricsauth" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/prometheus" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/webhook" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/machinery" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/certmanager" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/manager" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/metricsauth" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/prometheus" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/webhook" ) const ( @@ -43,7 +44,7 @@ const ( imageName = "controller:latest" ) -var _ Scaffolder = &initScaffolder{} +var _ scaffold.Scaffolder = &initScaffolder{} type initScaffolder struct { config *config.Config @@ -53,7 +54,7 @@ type initScaffolder struct { } // NewInitScaffolder returns a new Scaffolder for project initialization operations -func NewInitScaffolder(config *config.Config, license, owner string) Scaffolder { +func NewInitScaffolder(config *config.Config, license, owner string) scaffold.Scaffolder { return &initScaffolder{ config: config, boilerplatePath: filepath.Join("hack", "boilerplate.go.txt"), diff --git a/pkg/scaffold/internal/templates/authproxyrole.go b/pkg/plugin/v2/scaffolds/internal/templates/authproxyrole.go similarity index 100% rename from pkg/scaffold/internal/templates/authproxyrole.go rename to pkg/plugin/v2/scaffolds/internal/templates/authproxyrole.go diff --git a/pkg/scaffold/internal/templates/authproxyrolebinding.go b/pkg/plugin/v2/scaffolds/internal/templates/authproxyrolebinding.go similarity index 100% rename from pkg/scaffold/internal/templates/authproxyrolebinding.go rename to pkg/plugin/v2/scaffolds/internal/templates/authproxyrolebinding.go diff --git a/pkg/scaffold/internal/templates/boilerplate.go b/pkg/plugin/v2/scaffolds/internal/templates/boilerplate.go similarity index 100% rename from pkg/scaffold/internal/templates/boilerplate.go rename to pkg/plugin/v2/scaffolds/internal/templates/boilerplate.go diff --git a/pkg/scaffold/internal/templates/certmanager/certificate.go b/pkg/plugin/v2/scaffolds/internal/templates/certmanager/certificate.go similarity index 100% rename from pkg/scaffold/internal/templates/certmanager/certificate.go rename to pkg/plugin/v2/scaffolds/internal/templates/certmanager/certificate.go diff --git a/pkg/scaffold/internal/templates/certmanager/kustomize.go b/pkg/plugin/v2/scaffolds/internal/templates/certmanager/kustomize.go similarity index 100% rename from pkg/scaffold/internal/templates/certmanager/kustomize.go rename to pkg/plugin/v2/scaffolds/internal/templates/certmanager/kustomize.go diff --git a/pkg/scaffold/internal/templates/certmanager/kustomizeconfig.go b/pkg/plugin/v2/scaffolds/internal/templates/certmanager/kustomizeconfig.go similarity index 100% rename from pkg/scaffold/internal/templates/certmanager/kustomizeconfig.go rename to pkg/plugin/v2/scaffolds/internal/templates/certmanager/kustomizeconfig.go diff --git a/pkg/scaffold/internal/templates/controller/controller.go b/pkg/plugin/v2/scaffolds/internal/templates/controller/controller.go similarity index 100% rename from pkg/scaffold/internal/templates/controller/controller.go rename to pkg/plugin/v2/scaffolds/internal/templates/controller/controller.go diff --git a/pkg/scaffold/internal/templates/controller/controller_suitetest.go b/pkg/plugin/v2/scaffolds/internal/templates/controller/controller_suitetest.go similarity index 100% rename from pkg/scaffold/internal/templates/controller/controller_suitetest.go rename to pkg/plugin/v2/scaffolds/internal/templates/controller/controller_suitetest.go diff --git a/pkg/scaffold/internal/templates/crd/enablecainjection_patch.go b/pkg/plugin/v2/scaffolds/internal/templates/crd/enablecainjection_patch.go similarity index 100% rename from pkg/scaffold/internal/templates/crd/enablecainjection_patch.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd/enablecainjection_patch.go diff --git a/pkg/scaffold/internal/templates/crd/enablewebhook_patch.go b/pkg/plugin/v2/scaffolds/internal/templates/crd/enablewebhook_patch.go similarity index 100% rename from pkg/scaffold/internal/templates/crd/enablewebhook_patch.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd/enablewebhook_patch.go diff --git a/pkg/scaffold/internal/templates/crd/kustomization.go b/pkg/plugin/v2/scaffolds/internal/templates/crd/kustomization.go similarity index 100% rename from pkg/scaffold/internal/templates/crd/kustomization.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd/kustomization.go diff --git a/pkg/scaffold/internal/templates/crd/kustomizeconfig.go b/pkg/plugin/v2/scaffolds/internal/templates/crd/kustomizeconfig.go similarity index 100% rename from pkg/scaffold/internal/templates/crd/kustomizeconfig.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd/kustomizeconfig.go diff --git a/pkg/scaffold/internal/templates/crd_editor_rbac.go b/pkg/plugin/v2/scaffolds/internal/templates/crd_editor_rbac.go similarity index 100% rename from pkg/scaffold/internal/templates/crd_editor_rbac.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd_editor_rbac.go diff --git a/pkg/scaffold/internal/templates/crd_sample.go b/pkg/plugin/v2/scaffolds/internal/templates/crd_sample.go similarity index 100% rename from pkg/scaffold/internal/templates/crd_sample.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd_sample.go diff --git a/pkg/scaffold/internal/templates/crd_viewer_rbac.go b/pkg/plugin/v2/scaffolds/internal/templates/crd_viewer_rbac.go similarity index 100% rename from pkg/scaffold/internal/templates/crd_viewer_rbac.go rename to pkg/plugin/v2/scaffolds/internal/templates/crd_viewer_rbac.go diff --git a/pkg/scaffold/internal/templates/dockerfile.go b/pkg/plugin/v2/scaffolds/internal/templates/dockerfile.go similarity index 100% rename from pkg/scaffold/internal/templates/dockerfile.go rename to pkg/plugin/v2/scaffolds/internal/templates/dockerfile.go diff --git a/pkg/scaffold/internal/templates/gitignore.go b/pkg/plugin/v2/scaffolds/internal/templates/gitignore.go similarity index 100% rename from pkg/scaffold/internal/templates/gitignore.go rename to pkg/plugin/v2/scaffolds/internal/templates/gitignore.go diff --git a/pkg/scaffold/internal/templates/gomod.go b/pkg/plugin/v2/scaffolds/internal/templates/gomod.go similarity index 100% rename from pkg/scaffold/internal/templates/gomod.go rename to pkg/plugin/v2/scaffolds/internal/templates/gomod.go diff --git a/pkg/scaffold/internal/templates/group.go b/pkg/plugin/v2/scaffolds/internal/templates/group.go similarity index 100% rename from pkg/scaffold/internal/templates/group.go rename to pkg/plugin/v2/scaffolds/internal/templates/group.go diff --git a/pkg/scaffold/internal/templates/kustomize.go b/pkg/plugin/v2/scaffolds/internal/templates/kustomize.go similarity index 100% rename from pkg/scaffold/internal/templates/kustomize.go rename to pkg/plugin/v2/scaffolds/internal/templates/kustomize.go diff --git a/pkg/scaffold/internal/templates/leaderelectionrole.go b/pkg/plugin/v2/scaffolds/internal/templates/leaderelectionrole.go similarity index 100% rename from pkg/scaffold/internal/templates/leaderelectionrole.go rename to pkg/plugin/v2/scaffolds/internal/templates/leaderelectionrole.go diff --git a/pkg/scaffold/internal/templates/leaderelectionrolebinding.go b/pkg/plugin/v2/scaffolds/internal/templates/leaderelectionrolebinding.go similarity index 100% rename from pkg/scaffold/internal/templates/leaderelectionrolebinding.go rename to pkg/plugin/v2/scaffolds/internal/templates/leaderelectionrolebinding.go diff --git a/pkg/scaffold/internal/templates/main.go b/pkg/plugin/v2/scaffolds/internal/templates/main.go similarity index 100% rename from pkg/scaffold/internal/templates/main.go rename to pkg/plugin/v2/scaffolds/internal/templates/main.go diff --git a/pkg/scaffold/internal/templates/makefile.go b/pkg/plugin/v2/scaffolds/internal/templates/makefile.go similarity index 100% rename from pkg/scaffold/internal/templates/makefile.go rename to pkg/plugin/v2/scaffolds/internal/templates/makefile.go diff --git a/pkg/scaffold/internal/templates/manager/config.go b/pkg/plugin/v2/scaffolds/internal/templates/manager/config.go similarity index 100% rename from pkg/scaffold/internal/templates/manager/config.go rename to pkg/plugin/v2/scaffolds/internal/templates/manager/config.go diff --git a/pkg/scaffold/internal/templates/manager/kustomization.go b/pkg/plugin/v2/scaffolds/internal/templates/manager/kustomization.go similarity index 100% rename from pkg/scaffold/internal/templates/manager/kustomization.go rename to pkg/plugin/v2/scaffolds/internal/templates/manager/kustomization.go diff --git a/pkg/scaffold/internal/templates/metricsauth/auth_proxy_patch.go b/pkg/plugin/v2/scaffolds/internal/templates/metricsauth/auth_proxy_patch.go similarity index 100% rename from pkg/scaffold/internal/templates/metricsauth/auth_proxy_patch.go rename to pkg/plugin/v2/scaffolds/internal/templates/metricsauth/auth_proxy_patch.go diff --git a/pkg/scaffold/internal/templates/metricsauth/authproxyservice.go b/pkg/plugin/v2/scaffolds/internal/templates/metricsauth/authproxyservice.go similarity index 100% rename from pkg/scaffold/internal/templates/metricsauth/authproxyservice.go rename to pkg/plugin/v2/scaffolds/internal/templates/metricsauth/authproxyservice.go diff --git a/pkg/scaffold/internal/templates/metricsauth/clientclusterrole.go b/pkg/plugin/v2/scaffolds/internal/templates/metricsauth/clientclusterrole.go similarity index 100% rename from pkg/scaffold/internal/templates/metricsauth/clientclusterrole.go rename to pkg/plugin/v2/scaffolds/internal/templates/metricsauth/clientclusterrole.go diff --git a/pkg/scaffold/internal/templates/mgrrolebinding.go b/pkg/plugin/v2/scaffolds/internal/templates/mgrrolebinding.go similarity index 100% rename from pkg/scaffold/internal/templates/mgrrolebinding.go rename to pkg/plugin/v2/scaffolds/internal/templates/mgrrolebinding.go diff --git a/pkg/scaffold/internal/templates/prometheus/kustomize.go b/pkg/plugin/v2/scaffolds/internal/templates/prometheus/kustomize.go similarity index 100% rename from pkg/scaffold/internal/templates/prometheus/kustomize.go rename to pkg/plugin/v2/scaffolds/internal/templates/prometheus/kustomize.go diff --git a/pkg/scaffold/internal/templates/prometheus/monitor.go b/pkg/plugin/v2/scaffolds/internal/templates/prometheus/monitor.go similarity index 100% rename from pkg/scaffold/internal/templates/prometheus/monitor.go rename to pkg/plugin/v2/scaffolds/internal/templates/prometheus/monitor.go diff --git a/pkg/scaffold/internal/templates/rbac.go b/pkg/plugin/v2/scaffolds/internal/templates/rbac.go similarity index 100% rename from pkg/scaffold/internal/templates/rbac.go rename to pkg/plugin/v2/scaffolds/internal/templates/rbac.go diff --git a/pkg/scaffold/internal/templates/types.go b/pkg/plugin/v2/scaffolds/internal/templates/types.go similarity index 100% rename from pkg/scaffold/internal/templates/types.go rename to pkg/plugin/v2/scaffolds/internal/templates/types.go diff --git a/pkg/scaffold/internal/templates/webhook/enablecainection_patch.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook/enablecainection_patch.go similarity index 100% rename from pkg/scaffold/internal/templates/webhook/enablecainection_patch.go rename to pkg/plugin/v2/scaffolds/internal/templates/webhook/enablecainection_patch.go diff --git a/pkg/scaffold/internal/templates/webhook/kustomization.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook/kustomization.go similarity index 100% rename from pkg/scaffold/internal/templates/webhook/kustomization.go rename to pkg/plugin/v2/scaffolds/internal/templates/webhook/kustomization.go diff --git a/pkg/scaffold/internal/templates/webhook/kustomizeconfig.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook/kustomizeconfig.go similarity index 100% rename from pkg/scaffold/internal/templates/webhook/kustomizeconfig.go rename to pkg/plugin/v2/scaffolds/internal/templates/webhook/kustomizeconfig.go diff --git a/pkg/scaffold/internal/templates/webhook/service.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook/service.go similarity index 100% rename from pkg/scaffold/internal/templates/webhook/service.go rename to pkg/plugin/v2/scaffolds/internal/templates/webhook/service.go diff --git a/pkg/scaffold/internal/templates/webhook/webhook.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go similarity index 100% rename from pkg/scaffold/internal/templates/webhook/webhook.go rename to pkg/plugin/v2/scaffolds/internal/templates/webhook/webhook.go diff --git a/pkg/scaffold/internal/templates/webhook_manager_patch.go b/pkg/plugin/v2/scaffolds/internal/templates/webhook_manager_patch.go similarity index 100% rename from pkg/scaffold/internal/templates/webhook_manager_patch.go rename to pkg/plugin/v2/scaffolds/internal/templates/webhook_manager_patch.go diff --git a/pkg/scaffold/webhook.go b/pkg/plugin/v2/scaffolds/webhook.go similarity index 86% rename from pkg/scaffold/webhook.go rename to pkg/plugin/v2/scaffolds/webhook.go index b37167f7197..fab3385a76e 100644 --- a/pkg/scaffold/webhook.go +++ b/pkg/plugin/v2/scaffolds/webhook.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package scaffold +package scaffolds import ( "fmt" @@ -22,12 +22,13 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates" - "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/webhook" + "sigs.k8s.io/kubebuilder/pkg/plugin/internal/machinery" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds/internal/templates/webhook" ) -var _ Scaffolder = &webhookScaffolder{} +var _ scaffold.Scaffolder = &webhookScaffolder{} type webhookScaffolder struct { config *config.Config @@ -46,7 +47,7 @@ func NewWebhookScaffolder( defaulting bool, validation bool, conversion bool, -) Scaffolder { +) scaffold.Scaffolder { return &webhookScaffolder{ config: config, boilerplate: boilerplate, diff --git a/pkg/plugin/v2/webhook.go b/pkg/plugin/v2/webhook.go index 80ab43aebb1..dbb0f68f2e7 100644 --- a/pkg/plugin/v2/webhook.go +++ b/pkg/plugin/v2/webhook.go @@ -27,7 +27,8 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/plugin" - "sigs.k8s.io/kubebuilder/pkg/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/scaffold" + "sigs.k8s.io/kubebuilder/pkg/plugin/v2/scaffolds" ) type createWebhookPlugin struct { @@ -107,7 +108,7 @@ func (p *createWebhookPlugin) GetScaffolder() (scaffold.Scaffolder, error) { // Create the actual resource from the resource options res := p.resource.NewResource(p.config, false) - return scaffold.NewWebhookScaffolder(p.config, string(bp), res, p.defaulting, p.validation, p.conversion), nil + return scaffolds.NewWebhookScaffolder(p.config, string(bp), res, p.defaulting, p.validation, p.conversion), nil } func (p *createWebhookPlugin) PostScaffold() error { diff --git a/plugins/README.md b/plugins/README.md index 00a78e223cf..4cab5423bc2 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -31,7 +31,7 @@ yaml or json (to be determined!). While we are developing this functionality though, we are developing it using an in-process golang interface named `Plugin`, defined in -[pkg/scaffold/scaffold.go](../pkg/scaffold/scaffold.go). The interface is a +[pkg/plugin/scaffold/scaffold.go](../pkg/plugin/scaffold/scaffold.go). The interface is a simple single-method interface that is intended to mirror the data-in / data-out approach that will be used when executing a plugin in a separate binary. When we have more stability of the plugin, we intend to replace the in-process