From 66baebf88d4684b58d5f0ebba4410b01d52e0b77 Mon Sep 17 00:00:00 2001 From: Adrian Orive Date: Tue, 4 Feb 2020 07:50:16 +0100 Subject: [PATCH] Move templates to internal package Signed-off-by: Adrian Orive --- pkg/scaffold/api.go | 24 ++-- pkg/scaffold/init.go | 122 ++++++++++-------- .../templates/v1}/authproxyrole.go | 2 +- .../templates/v1}/authproxyrolebinding.go | 2 +- .../templates}/v1/authproxyservice.go | 0 .../templates/v1}/boilerplate.go | 2 +- .../templates}/v1/controller/add.go | 0 .../templates}/v1/controller/controller.go | 0 .../v1/controller/controllersuitetest.go | 0 .../v1/controller/controllertest.go | 0 .../templates}/v1/crd/addtoscheme.go | 0 .../templates}/v1/crd/crd_sample.go | 0 .../{ => internal/templates}/v1/crd/doc.go | 0 .../{ => internal/templates}/v1/crd/group.go | 0 .../templates}/v1/crd/register.go | 0 .../{ => internal/templates}/v1/crd/types.go | 0 .../templates}/v1/crd/typestest.go | 0 .../templates}/v1/crd/version_suitetest.go | 0 .../templates/v1}/gitignore.go | 2 +- .../templates/v1}/gopkg.go | 2 +- .../templates/v1}/kustomize.go | 2 +- .../templates}/v1/kustomize_image_patch.go | 0 .../templates/v1}/kustomize_manager_base.go | 2 +- .../templates/v1}/kustomize_rbac_base.go | 2 +- .../templates/v1}/makefile.go | 2 +- .../templates}/v1/manager/apis.go | 0 .../templates}/v1/manager/cmd.go | 0 .../templates}/v1/manager/config.go | 0 .../templates}/v1/manager/controller.go | 0 .../templates}/v1/manager/dockerfile.go | 0 .../templates}/v1/manager/webhook.go | 0 .../metricsauth/kustomize_auth_proxy_patch.go | 0 .../v1/metricsauth/kustomize_metrics_patch.go | 0 .../webhook/add_admissionbuilder_handler.go | 0 .../templates}/v1/webhook/add_server.go | 0 .../templates}/v1/webhook/admissionbuilder.go | 0 .../templates}/v1/webhook/admissionhandler.go | 0 .../v1/webhook/admissionwebhooks.go | 0 .../templates}/v1/webhook/config.go | 0 .../templates}/v1/webhook/server.go | 0 .../templates}/v1/webhook/util.go | 0 .../internal/templates/v2/authproxyrole.go | 54 ++++++++ .../templates/v2/authproxyrolebinding.go | 53 ++++++++ .../internal/templates/v2/boilerplate.go | 90 +++++++++++++ .../templates}/v2/certmanager/certificate.go | 0 .../templates}/v2/certmanager/kustomize.go | 0 .../v2/certmanager/kustomizeconfig.go | 0 .../templates}/v2/controller/controller.go | 0 .../v2/controller/controller_suitetest.go | 8 +- .../v2/crd/enablecainjection_patch.go | 0 .../templates}/v2/crd/enablewebhook_patch.go | 0 .../templates}/v2/crd/kustomization.go | 2 +- .../templates}/v2/crd/kustomizeconfig.go | 0 .../templates}/v2/crd_editor_rbac.go | 0 .../{ => internal/templates}/v2/crd_sample.go | 0 .../templates}/v2/crd_viewer_rbac.go | 0 .../{ => internal/templates}/v2/dockerfile.go | 0 .../internal/templates/v2/gitignore.go | 63 +++++++++ .../{ => internal/templates}/v2/gomod.go | 0 .../{ => internal/templates}/v2/group.go | 0 .../templates}/v2/internal/string_utils.go | 0 .../v2/internal/string_utils_test.go | 0 .../{ => internal/templates}/v2/kustomize.go | 0 .../templates}/v2/leaderelectionrole.go | 0 .../v2/leaderelectionrolebinding.go | 0 .../{ => internal/templates}/v2/main.go | 2 +- .../{ => internal/templates}/v2/makefile.go | 0 .../templates}/v2/manager/config.go | 0 .../templates}/v2/manager/kustomization.go | 0 .../v2/metricsauth/auth_proxy_patch.go | 0 .../v2/metricsauth/authproxyservice.go | 0 .../v2/metricsauth/clientclusterrole.go | 0 .../templates}/v2/mgrrolebinding.go | 0 .../templates}/v2/prometheus/kustomize.go | 0 .../templates}/v2/prometheus/monitor.go | 0 .../{ => internal/templates}/v2/rbac.go | 0 .../{ => internal/templates}/v2/types.go | 0 .../v2/webhook/enablecainection_patch.go | 0 .../templates}/v2/webhook/kustomization.go | 0 .../templates}/v2/webhook/kustomizeconfig.go | 0 .../templates}/v2/webhook/service.go | 0 .../templates}/v2/webhook/webhook.go | 0 .../templates}/v2/webhook_manager_patch.go | 0 pkg/scaffold/update.go | 4 +- pkg/scaffold/webhook.go | 12 +- 85 files changed, 361 insertions(+), 91 deletions(-) rename pkg/scaffold/{project => internal/templates/v1}/authproxyrole.go (98%) rename pkg/scaffold/{project => internal/templates/v1}/authproxyrolebinding.go (98%) rename pkg/scaffold/{ => internal/templates}/v1/authproxyservice.go (100%) rename pkg/scaffold/{project => internal/templates/v1}/boilerplate.go (99%) rename pkg/scaffold/{ => internal/templates}/v1/controller/add.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/controller/controller.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/controller/controllersuitetest.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/controller/controllertest.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/addtoscheme.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/crd_sample.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/doc.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/group.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/register.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/types.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/typestest.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/crd/version_suitetest.go (100%) rename pkg/scaffold/{project => internal/templates/v1}/gitignore.go (98%) rename pkg/scaffold/{project => internal/templates/v1}/gopkg.go (99%) rename pkg/scaffold/{project => internal/templates/v1}/kustomize.go (99%) rename pkg/scaffold/{ => internal/templates}/v1/kustomize_image_patch.go (100%) rename pkg/scaffold/{project => internal/templates/v1}/kustomize_manager_base.go (98%) rename pkg/scaffold/{project => internal/templates/v1}/kustomize_rbac_base.go (98%) rename pkg/scaffold/{project => internal/templates/v1}/makefile.go (99%) rename pkg/scaffold/{ => internal/templates}/v1/manager/apis.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/manager/cmd.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/manager/config.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/manager/controller.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/manager/dockerfile.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/manager/webhook.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/metricsauth/kustomize_auth_proxy_patch.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/metricsauth/kustomize_metrics_patch.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/add_admissionbuilder_handler.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/add_server.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/admissionbuilder.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/admissionhandler.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/admissionwebhooks.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/config.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/server.go (100%) rename pkg/scaffold/{ => internal/templates}/v1/webhook/util.go (100%) create mode 100644 pkg/scaffold/internal/templates/v2/authproxyrole.go create mode 100644 pkg/scaffold/internal/templates/v2/authproxyrolebinding.go create mode 100644 pkg/scaffold/internal/templates/v2/boilerplate.go rename pkg/scaffold/{ => internal/templates}/v2/certmanager/certificate.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/certmanager/kustomize.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/certmanager/kustomizeconfig.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/controller/controller.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/controller/controller_suitetest.go (92%) rename pkg/scaffold/{ => internal/templates}/v2/crd/enablecainjection_patch.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/crd/enablewebhook_patch.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/crd/kustomization.go (97%) rename pkg/scaffold/{ => internal/templates}/v2/crd/kustomizeconfig.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/crd_editor_rbac.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/crd_sample.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/crd_viewer_rbac.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/dockerfile.go (100%) create mode 100644 pkg/scaffold/internal/templates/v2/gitignore.go rename pkg/scaffold/{ => internal/templates}/v2/gomod.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/group.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/internal/string_utils.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/internal/string_utils_test.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/kustomize.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/leaderelectionrole.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/leaderelectionrolebinding.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/main.go (98%) rename pkg/scaffold/{ => internal/templates}/v2/makefile.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/manager/config.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/manager/kustomization.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/metricsauth/auth_proxy_patch.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/metricsauth/authproxyservice.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/metricsauth/clientclusterrole.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/mgrrolebinding.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/prometheus/kustomize.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/prometheus/monitor.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/rbac.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/types.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/webhook/enablecainection_patch.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/webhook/kustomization.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/webhook/kustomizeconfig.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/webhook/service.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/webhook/webhook.go (100%) rename pkg/scaffold/{ => internal/templates}/v2/webhook_manager_patch.go (100%) diff --git a/pkg/scaffold/api.go b/pkg/scaffold/api.go index f404ef422e5..e291ae842b6 100644 --- a/pkg/scaffold/api.go +++ b/pkg/scaffold/api.go @@ -25,11 +25,11 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - controllerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/controller" - crdv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/crd" - scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" - controllerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/controller" - crdv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/crd" + controllerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1/controller" + crdv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1/crd" + templatesv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2" + controllerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/controller" + crdv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/crd" ) // apiScaffolder contains configuration for generating scaffolding for Go type @@ -151,11 +151,11 @@ func (s *apiScaffolder) scaffoldV2() error { if err := machinery.NewScaffold(s.plugins...).Execute( s.newUniverse(), - &scaffoldv2.Types{Resource: s.resource}, - &scaffoldv2.Group{Resource: s.resource}, - &scaffoldv2.CRDSample{Resource: s.resource}, - &scaffoldv2.CRDEditorRole{Resource: s.resource}, - &scaffoldv2.CRDViewerRole{Resource: s.resource}, + &templatesv2.Types{Resource: s.resource}, + &templatesv2.Group{Resource: s.resource}, + &templatesv2.CRDSample{Resource: s.resource}, + &templatesv2.CRDEditorRole{Resource: s.resource}, + &templatesv2.CRDViewerRole{Resource: s.resource}, &crdv2.EnableWebhookPatch{Resource: s.resource}, &crdv2.EnableCAInjectionPatch{Resource: s.resource}, ); err != nil { @@ -206,8 +206,8 @@ func (s *apiScaffolder) scaffoldV2() error { } } - if err := (&scaffoldv2.Main{}).Update( - &scaffoldv2.MainUpdateOptions{ + if err := (&templatesv2.Main{}).Update( + &templatesv2.MainUpdateOptions{ Config: &s.config.Config, WireResource: s.doResource, WireController: s.doController, diff --git a/pkg/scaffold/init.go b/pkg/scaffold/init.go index 14867b0966a..d2ceace0b69 100644 --- a/pkg/scaffold/init.go +++ b/pkg/scaffold/init.go @@ -25,16 +25,15 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model" "sigs.k8s.io/kubebuilder/pkg/model/file" "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - "sigs.k8s.io/kubebuilder/pkg/scaffold/project" - scaffoldv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1" - managerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/manager" - metricsauthv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/metricsauth" - scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" - certmanagerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/certmanager" - managerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/manager" - metricsauthv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/metricsauth" - prometheusv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/prometheus" - webhookv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/webhook" + templatesv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1" + managerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1/manager" + metricsauthv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1/metricsauth" + templatesv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2" + certmanagerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/certmanager" + managerv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/manager" + metricsauthv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/metricsauth" + prometheusv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/prometheus" + webhookv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/webhook" ) const ( @@ -49,7 +48,6 @@ const ( type initScaffolder struct { config *config.Config boilerplatePath string - boilerplate string license string owner string } @@ -63,10 +61,10 @@ func NewInitScaffolder(config *config.Config, license, owner string) Scaffolder } } -func (s *initScaffolder) newUniverse() *model.Universe { +func (s *initScaffolder) newUniverse(boilerplate string) *model.Universe { return model.NewUniverse( model.WithConfig(&s.config.Config), - model.WithBoilerplate(s.boilerplate), + model.WithBoilerplate(boilerplate), ) } @@ -77,9 +75,20 @@ func (s *initScaffolder) Scaffold() error { return err } + switch { + case s.config.IsV1(): + return s.scaffoldV1() + case s.config.IsV2(): + return s.scaffoldV2() + default: + return fmt.Errorf("unknown project version %v", s.config.Version) + } +} + +func (s *initScaffolder) scaffoldV1() error { if err := machinery.NewScaffold().Execute( - s.newUniverse(), // Boilerplate is still empty by this call as desired - &project.Boilerplate{ + s.newUniverse(""), + &templatesv1.Boilerplate{ Input: file.Input{Path: s.boilerplatePath}, License: s.license, Owner: s.owner, @@ -88,45 +97,27 @@ func (s *initScaffolder) Scaffold() error { return err } - boilerplateBytes, err := ioutil.ReadFile(s.boilerplatePath) // nolint:gosec + boilerplate, err := ioutil.ReadFile(s.boilerplatePath) // nolint:gosec if err != nil { return err } - s.boilerplate = string(boilerplateBytes) - - if err := machinery.NewScaffold().Execute( - s.newUniverse(), - &project.GitIgnore{}, - &project.AuthProxyRole{}, - &project.AuthProxyRoleBinding{}, - ); err != nil { - return err - } - - switch { - case s.config.IsV1(): - return s.scaffoldV1() - case s.config.IsV2(): - return s.scaffoldV2() - default: - return fmt.Errorf("unknown project version %v", s.config.Version) - } -} -func (s *initScaffolder) scaffoldV1() error { return machinery.NewScaffold().Execute( - s.newUniverse(), - &project.KustomizeRBAC{}, - &scaffoldv1.KustomizeImagePatch{}, + s.newUniverse(string(boilerplate)), + &templatesv1.GitIgnore{}, + &templatesv1.AuthProxyRole{}, + &templatesv1.AuthProxyRoleBinding{}, + &templatesv1.KustomizeRBAC{}, + &templatesv1.KustomizeImagePatch{}, &metricsauthv1.KustomizePrometheusMetricsPatch{}, &metricsauthv1.KustomizeAuthProxyPatch{}, - &scaffoldv1.AuthProxyService{}, + &templatesv1.AuthProxyService{}, &managerv1.Config{Image: ImageName}, - &project.Makefile{Image: ImageName}, - &project.GopkgToml{}, + &templatesv1.Makefile{Image: ImageName}, + &templatesv1.GopkgToml{}, &managerv1.Dockerfile{}, - &project.Kustomize{}, - &project.KustomizeManager{}, + &templatesv1.Kustomize{}, + &templatesv1.KustomizeManager{}, &managerv1.APIs{BoilerplatePath: s.boilerplatePath}, &managerv1.Controller{}, &managerv1.Webhook{}, @@ -135,26 +126,45 @@ func (s *initScaffolder) scaffoldV1() error { } func (s *initScaffolder) scaffoldV2() error { + if err := machinery.NewScaffold().Execute( + s.newUniverse(""), + &templatesv2.Boilerplate{ + Input: file.Input{Path: s.boilerplatePath}, + License: s.license, + Owner: s.owner, + }, + ); err != nil { + return err + } + + boilerplate, err := ioutil.ReadFile(s.boilerplatePath) // nolint:gosec + if err != nil { + return err + } + return machinery.NewScaffold().Execute( - s.newUniverse(), + s.newUniverse(string(boilerplate)), + &templatesv2.GitIgnore{}, + &templatesv2.AuthProxyRole{}, + &templatesv2.AuthProxyRoleBinding{}, &metricsauthv2.AuthProxyPatch{}, &metricsauthv2.AuthProxyService{}, &metricsauthv2.ClientClusterRole{}, &managerv2.Config{Image: ImageName}, - &scaffoldv2.Main{}, - &scaffoldv2.GoMod{ControllerRuntimeVersion: ControllerRuntimeVersion}, - &scaffoldv2.Makefile{ + &templatesv2.Main{}, + &templatesv2.GoMod{ControllerRuntimeVersion: ControllerRuntimeVersion}, + &templatesv2.Makefile{ Image: ImageName, BoilerplatePath: s.boilerplatePath, ControllerToolsVersion: ControllerToolsVersion, }, - &scaffoldv2.Dockerfile{}, - &scaffoldv2.Kustomize{}, - &scaffoldv2.ManagerWebhookPatch{}, - &scaffoldv2.ManagerRoleBinding{}, - &scaffoldv2.LeaderElectionRole{}, - &scaffoldv2.LeaderElectionRoleBinding{}, - &scaffoldv2.KustomizeRBAC{}, + &templatesv2.Dockerfile{}, + &templatesv2.Kustomize{}, + &templatesv2.ManagerWebhookPatch{}, + &templatesv2.ManagerRoleBinding{}, + &templatesv2.LeaderElectionRole{}, + &templatesv2.LeaderElectionRoleBinding{}, + &templatesv2.KustomizeRBAC{}, &managerv2.Kustomization{}, &webhookv2.Kustomization{}, &webhookv2.KustomizeConfigWebhook{}, diff --git a/pkg/scaffold/project/authproxyrole.go b/pkg/scaffold/internal/templates/v1/authproxyrole.go similarity index 98% rename from pkg/scaffold/project/authproxyrole.go rename to pkg/scaffold/internal/templates/v1/authproxyrole.go index ad8bdf5f507..af69f0b2e36 100644 --- a/pkg/scaffold/project/authproxyrole.go +++ b/pkg/scaffold/internal/templates/v1/authproxyrole.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "path/filepath" diff --git a/pkg/scaffold/project/authproxyrolebinding.go b/pkg/scaffold/internal/templates/v1/authproxyrolebinding.go similarity index 98% rename from pkg/scaffold/project/authproxyrolebinding.go rename to pkg/scaffold/internal/templates/v1/authproxyrolebinding.go index 4000fc5bb9f..eea137abceb 100644 --- a/pkg/scaffold/project/authproxyrolebinding.go +++ b/pkg/scaffold/internal/templates/v1/authproxyrolebinding.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "path/filepath" diff --git a/pkg/scaffold/v1/authproxyservice.go b/pkg/scaffold/internal/templates/v1/authproxyservice.go similarity index 100% rename from pkg/scaffold/v1/authproxyservice.go rename to pkg/scaffold/internal/templates/v1/authproxyservice.go diff --git a/pkg/scaffold/project/boilerplate.go b/pkg/scaffold/internal/templates/v1/boilerplate.go similarity index 99% rename from pkg/scaffold/project/boilerplate.go rename to pkg/scaffold/internal/templates/v1/boilerplate.go index c96d33486d9..94f8c9d96ae 100644 --- a/pkg/scaffold/project/boilerplate.go +++ b/pkg/scaffold/internal/templates/v1/boilerplate.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "fmt" diff --git a/pkg/scaffold/v1/controller/add.go b/pkg/scaffold/internal/templates/v1/controller/add.go similarity index 100% rename from pkg/scaffold/v1/controller/add.go rename to pkg/scaffold/internal/templates/v1/controller/add.go diff --git a/pkg/scaffold/v1/controller/controller.go b/pkg/scaffold/internal/templates/v1/controller/controller.go similarity index 100% rename from pkg/scaffold/v1/controller/controller.go rename to pkg/scaffold/internal/templates/v1/controller/controller.go diff --git a/pkg/scaffold/v1/controller/controllersuitetest.go b/pkg/scaffold/internal/templates/v1/controller/controllersuitetest.go similarity index 100% rename from pkg/scaffold/v1/controller/controllersuitetest.go rename to pkg/scaffold/internal/templates/v1/controller/controllersuitetest.go diff --git a/pkg/scaffold/v1/controller/controllertest.go b/pkg/scaffold/internal/templates/v1/controller/controllertest.go similarity index 100% rename from pkg/scaffold/v1/controller/controllertest.go rename to pkg/scaffold/internal/templates/v1/controller/controllertest.go diff --git a/pkg/scaffold/v1/crd/addtoscheme.go b/pkg/scaffold/internal/templates/v1/crd/addtoscheme.go similarity index 100% rename from pkg/scaffold/v1/crd/addtoscheme.go rename to pkg/scaffold/internal/templates/v1/crd/addtoscheme.go diff --git a/pkg/scaffold/v1/crd/crd_sample.go b/pkg/scaffold/internal/templates/v1/crd/crd_sample.go similarity index 100% rename from pkg/scaffold/v1/crd/crd_sample.go rename to pkg/scaffold/internal/templates/v1/crd/crd_sample.go diff --git a/pkg/scaffold/v1/crd/doc.go b/pkg/scaffold/internal/templates/v1/crd/doc.go similarity index 100% rename from pkg/scaffold/v1/crd/doc.go rename to pkg/scaffold/internal/templates/v1/crd/doc.go diff --git a/pkg/scaffold/v1/crd/group.go b/pkg/scaffold/internal/templates/v1/crd/group.go similarity index 100% rename from pkg/scaffold/v1/crd/group.go rename to pkg/scaffold/internal/templates/v1/crd/group.go diff --git a/pkg/scaffold/v1/crd/register.go b/pkg/scaffold/internal/templates/v1/crd/register.go similarity index 100% rename from pkg/scaffold/v1/crd/register.go rename to pkg/scaffold/internal/templates/v1/crd/register.go diff --git a/pkg/scaffold/v1/crd/types.go b/pkg/scaffold/internal/templates/v1/crd/types.go similarity index 100% rename from pkg/scaffold/v1/crd/types.go rename to pkg/scaffold/internal/templates/v1/crd/types.go diff --git a/pkg/scaffold/v1/crd/typestest.go b/pkg/scaffold/internal/templates/v1/crd/typestest.go similarity index 100% rename from pkg/scaffold/v1/crd/typestest.go rename to pkg/scaffold/internal/templates/v1/crd/typestest.go diff --git a/pkg/scaffold/v1/crd/version_suitetest.go b/pkg/scaffold/internal/templates/v1/crd/version_suitetest.go similarity index 100% rename from pkg/scaffold/v1/crd/version_suitetest.go rename to pkg/scaffold/internal/templates/v1/crd/version_suitetest.go diff --git a/pkg/scaffold/project/gitignore.go b/pkg/scaffold/internal/templates/v1/gitignore.go similarity index 98% rename from pkg/scaffold/project/gitignore.go rename to pkg/scaffold/internal/templates/v1/gitignore.go index dc4b587f0fd..7bc5d462beb 100644 --- a/pkg/scaffold/project/gitignore.go +++ b/pkg/scaffold/internal/templates/v1/gitignore.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "sigs.k8s.io/kubebuilder/pkg/model/file" diff --git a/pkg/scaffold/project/gopkg.go b/pkg/scaffold/internal/templates/v1/gopkg.go similarity index 99% rename from pkg/scaffold/project/gopkg.go rename to pkg/scaffold/internal/templates/v1/gopkg.go index 8a36e4faab3..f187c3ca13d 100644 --- a/pkg/scaffold/project/gopkg.go +++ b/pkg/scaffold/internal/templates/v1/gopkg.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "bufio" diff --git a/pkg/scaffold/project/kustomize.go b/pkg/scaffold/internal/templates/v1/kustomize.go similarity index 99% rename from pkg/scaffold/project/kustomize.go rename to pkg/scaffold/internal/templates/v1/kustomize.go index cb0b48ddebf..07ea6266a81 100644 --- a/pkg/scaffold/project/kustomize.go +++ b/pkg/scaffold/internal/templates/v1/kustomize.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "os" diff --git a/pkg/scaffold/v1/kustomize_image_patch.go b/pkg/scaffold/internal/templates/v1/kustomize_image_patch.go similarity index 100% rename from pkg/scaffold/v1/kustomize_image_patch.go rename to pkg/scaffold/internal/templates/v1/kustomize_image_patch.go diff --git a/pkg/scaffold/project/kustomize_manager_base.go b/pkg/scaffold/internal/templates/v1/kustomize_manager_base.go similarity index 98% rename from pkg/scaffold/project/kustomize_manager_base.go rename to pkg/scaffold/internal/templates/v1/kustomize_manager_base.go index e757c795543..251751af84a 100644 --- a/pkg/scaffold/project/kustomize_manager_base.go +++ b/pkg/scaffold/internal/templates/v1/kustomize_manager_base.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "path/filepath" diff --git a/pkg/scaffold/project/kustomize_rbac_base.go b/pkg/scaffold/internal/templates/v1/kustomize_rbac_base.go similarity index 98% rename from pkg/scaffold/project/kustomize_rbac_base.go rename to pkg/scaffold/internal/templates/v1/kustomize_rbac_base.go index d5aae8909ba..bee665ab800 100644 --- a/pkg/scaffold/project/kustomize_rbac_base.go +++ b/pkg/scaffold/internal/templates/v1/kustomize_rbac_base.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "path/filepath" diff --git a/pkg/scaffold/project/makefile.go b/pkg/scaffold/internal/templates/v1/makefile.go similarity index 99% rename from pkg/scaffold/project/makefile.go rename to pkg/scaffold/internal/templates/v1/makefile.go index d1d260c4de4..1903701ffc3 100644 --- a/pkg/scaffold/project/makefile.go +++ b/pkg/scaffold/internal/templates/v1/makefile.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package project +package v1 import ( "sigs.k8s.io/kubebuilder/pkg/model/file" diff --git a/pkg/scaffold/v1/manager/apis.go b/pkg/scaffold/internal/templates/v1/manager/apis.go similarity index 100% rename from pkg/scaffold/v1/manager/apis.go rename to pkg/scaffold/internal/templates/v1/manager/apis.go diff --git a/pkg/scaffold/v1/manager/cmd.go b/pkg/scaffold/internal/templates/v1/manager/cmd.go similarity index 100% rename from pkg/scaffold/v1/manager/cmd.go rename to pkg/scaffold/internal/templates/v1/manager/cmd.go diff --git a/pkg/scaffold/v1/manager/config.go b/pkg/scaffold/internal/templates/v1/manager/config.go similarity index 100% rename from pkg/scaffold/v1/manager/config.go rename to pkg/scaffold/internal/templates/v1/manager/config.go diff --git a/pkg/scaffold/v1/manager/controller.go b/pkg/scaffold/internal/templates/v1/manager/controller.go similarity index 100% rename from pkg/scaffold/v1/manager/controller.go rename to pkg/scaffold/internal/templates/v1/manager/controller.go diff --git a/pkg/scaffold/v1/manager/dockerfile.go b/pkg/scaffold/internal/templates/v1/manager/dockerfile.go similarity index 100% rename from pkg/scaffold/v1/manager/dockerfile.go rename to pkg/scaffold/internal/templates/v1/manager/dockerfile.go diff --git a/pkg/scaffold/v1/manager/webhook.go b/pkg/scaffold/internal/templates/v1/manager/webhook.go similarity index 100% rename from pkg/scaffold/v1/manager/webhook.go rename to pkg/scaffold/internal/templates/v1/manager/webhook.go diff --git a/pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go b/pkg/scaffold/internal/templates/v1/metricsauth/kustomize_auth_proxy_patch.go similarity index 100% rename from pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go rename to pkg/scaffold/internal/templates/v1/metricsauth/kustomize_auth_proxy_patch.go diff --git a/pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go b/pkg/scaffold/internal/templates/v1/metricsauth/kustomize_metrics_patch.go similarity index 100% rename from pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go rename to pkg/scaffold/internal/templates/v1/metricsauth/kustomize_metrics_patch.go diff --git a/pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go b/pkg/scaffold/internal/templates/v1/webhook/add_admissionbuilder_handler.go similarity index 100% rename from pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go rename to pkg/scaffold/internal/templates/v1/webhook/add_admissionbuilder_handler.go diff --git a/pkg/scaffold/v1/webhook/add_server.go b/pkg/scaffold/internal/templates/v1/webhook/add_server.go similarity index 100% rename from pkg/scaffold/v1/webhook/add_server.go rename to pkg/scaffold/internal/templates/v1/webhook/add_server.go diff --git a/pkg/scaffold/v1/webhook/admissionbuilder.go b/pkg/scaffold/internal/templates/v1/webhook/admissionbuilder.go similarity index 100% rename from pkg/scaffold/v1/webhook/admissionbuilder.go rename to pkg/scaffold/internal/templates/v1/webhook/admissionbuilder.go diff --git a/pkg/scaffold/v1/webhook/admissionhandler.go b/pkg/scaffold/internal/templates/v1/webhook/admissionhandler.go similarity index 100% rename from pkg/scaffold/v1/webhook/admissionhandler.go rename to pkg/scaffold/internal/templates/v1/webhook/admissionhandler.go diff --git a/pkg/scaffold/v1/webhook/admissionwebhooks.go b/pkg/scaffold/internal/templates/v1/webhook/admissionwebhooks.go similarity index 100% rename from pkg/scaffold/v1/webhook/admissionwebhooks.go rename to pkg/scaffold/internal/templates/v1/webhook/admissionwebhooks.go diff --git a/pkg/scaffold/v1/webhook/config.go b/pkg/scaffold/internal/templates/v1/webhook/config.go similarity index 100% rename from pkg/scaffold/v1/webhook/config.go rename to pkg/scaffold/internal/templates/v1/webhook/config.go diff --git a/pkg/scaffold/v1/webhook/server.go b/pkg/scaffold/internal/templates/v1/webhook/server.go similarity index 100% rename from pkg/scaffold/v1/webhook/server.go rename to pkg/scaffold/internal/templates/v1/webhook/server.go diff --git a/pkg/scaffold/v1/webhook/util.go b/pkg/scaffold/internal/templates/v1/webhook/util.go similarity index 100% rename from pkg/scaffold/v1/webhook/util.go rename to pkg/scaffold/internal/templates/v1/webhook/util.go diff --git a/pkg/scaffold/internal/templates/v2/authproxyrole.go b/pkg/scaffold/internal/templates/v2/authproxyrole.go new file mode 100644 index 00000000000..6d36581f84c --- /dev/null +++ b/pkg/scaffold/internal/templates/v2/authproxyrole.go @@ -0,0 +1,54 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2 + +import ( + "path/filepath" + + "sigs.k8s.io/kubebuilder/pkg/model/file" +) + +var _ file.Template = &AuthProxyRole{} + +// AuthProxyRole scaffolds the config/rbac/auth_proxy_role.yaml file +type AuthProxyRole struct { + file.Input +} + +// GetInput implements input.Template +func (f *AuthProxyRole) GetInput() (file.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", "auth_proxy_role.yaml") + } + f.TemplateBody = proxyRoleTemplate + return f.Input, nil +} + +const proxyRoleTemplate = `apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: proxy-role +rules: +- apiGroups: ["authentication.k8s.io"] + resources: + - tokenreviews + verbs: ["create"] +- apiGroups: ["authorization.k8s.io"] + resources: + - subjectaccessreviews + verbs: ["create"] +` diff --git a/pkg/scaffold/internal/templates/v2/authproxyrolebinding.go b/pkg/scaffold/internal/templates/v2/authproxyrolebinding.go new file mode 100644 index 00000000000..0bb1e2c39ef --- /dev/null +++ b/pkg/scaffold/internal/templates/v2/authproxyrolebinding.go @@ -0,0 +1,53 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2 + +import ( + "path/filepath" + + "sigs.k8s.io/kubebuilder/pkg/model/file" +) + +var _ file.Template = &AuthProxyRoleBinding{} + +// AuthProxyRoleBinding scaffolds the config/rbac/auth_proxy_role_binding_rbac.yaml file +type AuthProxyRoleBinding struct { + file.Input +} + +// GetInput implements input.Template +func (f *AuthProxyRoleBinding) GetInput() (file.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("config", "rbac", "auth_proxy_role_binding.yaml") + } + f.TemplateBody = proxyRoleBindinggTemplate + return f.Input, nil +} + +const proxyRoleBindinggTemplate = `apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: proxy-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: proxy-role +subjects: +- kind: ServiceAccount + name: default + namespace: system +` diff --git a/pkg/scaffold/internal/templates/v2/boilerplate.go b/pkg/scaffold/internal/templates/v2/boilerplate.go new file mode 100644 index 00000000000..2997e30b66c --- /dev/null +++ b/pkg/scaffold/internal/templates/v2/boilerplate.go @@ -0,0 +1,90 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2 + +import ( + "fmt" + "path/filepath" + "time" + + "sigs.k8s.io/kubebuilder/pkg/model/file" +) + +var _ file.Template = &Boilerplate{} + +// Boilerplate scaffolds a boilerplate header file. +type Boilerplate struct { + file.Input + + // License is the License type to write + License string + + // Owner is the copyright owner - e.g. "The Kubernetes Authors" + Owner string + + // Year is the copyright year + Year string +} + +// GetInput implements input.Template +func (f *Boilerplate) GetInput() (file.Input, error) { + if f.Path == "" { + f.Path = filepath.Join("hack", "boilerplate.go.txt") + } + + // Boilerplate given + if len(f.Boilerplate) > 0 { + f.TemplateBody = f.Boilerplate + return f.Input, nil + } + + // Pick a template boilerplate option + if f.Year == "" { + f.Year = fmt.Sprintf("%v", time.Now().Year()) + } + switch f.License { + case "", "apache2": + f.TemplateBody = apache + case "none": + f.TemplateBody = none + } + return f.Input, nil +} + +const apache = `/* +{{ if .Owner -}} +Copyright {{ .Year }} {{ .Owner }}. +{{- end }} + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/` + +const none = `/* +{{ if .Owner -}} +Copyright {{ .Year }} {{ .Owner }}. +{{- end }} +*/` diff --git a/pkg/scaffold/v2/certmanager/certificate.go b/pkg/scaffold/internal/templates/v2/certmanager/certificate.go similarity index 100% rename from pkg/scaffold/v2/certmanager/certificate.go rename to pkg/scaffold/internal/templates/v2/certmanager/certificate.go diff --git a/pkg/scaffold/v2/certmanager/kustomize.go b/pkg/scaffold/internal/templates/v2/certmanager/kustomize.go similarity index 100% rename from pkg/scaffold/v2/certmanager/kustomize.go rename to pkg/scaffold/internal/templates/v2/certmanager/kustomize.go diff --git a/pkg/scaffold/v2/certmanager/kustomizeconfig.go b/pkg/scaffold/internal/templates/v2/certmanager/kustomizeconfig.go similarity index 100% rename from pkg/scaffold/v2/certmanager/kustomizeconfig.go rename to pkg/scaffold/internal/templates/v2/certmanager/kustomizeconfig.go diff --git a/pkg/scaffold/v2/controller/controller.go b/pkg/scaffold/internal/templates/v2/controller/controller.go similarity index 100% rename from pkg/scaffold/v2/controller/controller.go rename to pkg/scaffold/internal/templates/v2/controller/controller.go diff --git a/pkg/scaffold/v2/controller/controller_suitetest.go b/pkg/scaffold/internal/templates/v2/controller/controller_suitetest.go similarity index 92% rename from pkg/scaffold/v2/controller/controller_suitetest.go rename to pkg/scaffold/internal/templates/v2/controller/controller_suitetest.go index 4524da2aee9..a6dac0c7815 100644 --- a/pkg/scaffold/v2/controller/controller_suitetest.go +++ b/pkg/scaffold/internal/templates/v2/controller/controller_suitetest.go @@ -22,8 +22,8 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/file" "sigs.k8s.io/kubebuilder/pkg/model/resource" - scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" - "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/internal" + templatesv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2" + "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/internal" ) var _ file.Template = &SuiteTest{} @@ -132,8 +132,8 @@ Expect(err).NotTo(HaveOccurred()) err := internal.InsertStringsInFile(f.Path, map[string][]string{ - scaffoldv2.APIPkgImportScaffoldMarker: {ctrlImportCodeFragment, apiImportCodeFragment}, - scaffoldv2.APISchemeScaffoldMarker: {addschemeCodeFragment}, + templatesv2.APIPkgImportScaffoldMarker: {ctrlImportCodeFragment, apiImportCodeFragment}, + templatesv2.APISchemeScaffoldMarker: {addschemeCodeFragment}, }) if err != nil { return err diff --git a/pkg/scaffold/v2/crd/enablecainjection_patch.go b/pkg/scaffold/internal/templates/v2/crd/enablecainjection_patch.go similarity index 100% rename from pkg/scaffold/v2/crd/enablecainjection_patch.go rename to pkg/scaffold/internal/templates/v2/crd/enablecainjection_patch.go diff --git a/pkg/scaffold/v2/crd/enablewebhook_patch.go b/pkg/scaffold/internal/templates/v2/crd/enablewebhook_patch.go similarity index 100% rename from pkg/scaffold/v2/crd/enablewebhook_patch.go rename to pkg/scaffold/internal/templates/v2/crd/enablewebhook_patch.go diff --git a/pkg/scaffold/v2/crd/kustomization.go b/pkg/scaffold/internal/templates/v2/crd/kustomization.go similarity index 97% rename from pkg/scaffold/v2/crd/kustomization.go rename to pkg/scaffold/internal/templates/v2/crd/kustomization.go index a6ce21c1416..50c14580a32 100644 --- a/pkg/scaffold/v2/crd/kustomization.go +++ b/pkg/scaffold/internal/templates/v2/crd/kustomization.go @@ -22,7 +22,7 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/file" "sigs.k8s.io/kubebuilder/pkg/model/resource" - "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/internal" + "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/internal" ) const ( diff --git a/pkg/scaffold/v2/crd/kustomizeconfig.go b/pkg/scaffold/internal/templates/v2/crd/kustomizeconfig.go similarity index 100% rename from pkg/scaffold/v2/crd/kustomizeconfig.go rename to pkg/scaffold/internal/templates/v2/crd/kustomizeconfig.go diff --git a/pkg/scaffold/v2/crd_editor_rbac.go b/pkg/scaffold/internal/templates/v2/crd_editor_rbac.go similarity index 100% rename from pkg/scaffold/v2/crd_editor_rbac.go rename to pkg/scaffold/internal/templates/v2/crd_editor_rbac.go diff --git a/pkg/scaffold/v2/crd_sample.go b/pkg/scaffold/internal/templates/v2/crd_sample.go similarity index 100% rename from pkg/scaffold/v2/crd_sample.go rename to pkg/scaffold/internal/templates/v2/crd_sample.go diff --git a/pkg/scaffold/v2/crd_viewer_rbac.go b/pkg/scaffold/internal/templates/v2/crd_viewer_rbac.go similarity index 100% rename from pkg/scaffold/v2/crd_viewer_rbac.go rename to pkg/scaffold/internal/templates/v2/crd_viewer_rbac.go diff --git a/pkg/scaffold/v2/dockerfile.go b/pkg/scaffold/internal/templates/v2/dockerfile.go similarity index 100% rename from pkg/scaffold/v2/dockerfile.go rename to pkg/scaffold/internal/templates/v2/dockerfile.go diff --git a/pkg/scaffold/internal/templates/v2/gitignore.go b/pkg/scaffold/internal/templates/v2/gitignore.go new file mode 100644 index 00000000000..fc32f64627c --- /dev/null +++ b/pkg/scaffold/internal/templates/v2/gitignore.go @@ -0,0 +1,63 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v2 + +import ( + "sigs.k8s.io/kubebuilder/pkg/model/file" +) + +var _ file.Template = &GitIgnore{} + +// GitIgnore scaffolds the .gitignore file +type GitIgnore struct { + file.Input +} + +// GetInput implements input.Template +func (f *GitIgnore) GetInput() (file.Input, error) { + if f.Path == "" { + f.Path = ".gitignore" + } + f.TemplateBody = gitignoreTemplate + return f.Input, nil +} + +const gitignoreTemplate = ` +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +bin + +# Test binary, build with ` + "`go test -c`" + ` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Kubernetes Generated files - skip generated files, except for vendored files + +!vendor/**/zz_generated.* + +# editor and IDE paraphernalia +.idea +*.swp +*.swo +*~ +` diff --git a/pkg/scaffold/v2/gomod.go b/pkg/scaffold/internal/templates/v2/gomod.go similarity index 100% rename from pkg/scaffold/v2/gomod.go rename to pkg/scaffold/internal/templates/v2/gomod.go diff --git a/pkg/scaffold/v2/group.go b/pkg/scaffold/internal/templates/v2/group.go similarity index 100% rename from pkg/scaffold/v2/group.go rename to pkg/scaffold/internal/templates/v2/group.go diff --git a/pkg/scaffold/v2/internal/string_utils.go b/pkg/scaffold/internal/templates/v2/internal/string_utils.go similarity index 100% rename from pkg/scaffold/v2/internal/string_utils.go rename to pkg/scaffold/internal/templates/v2/internal/string_utils.go diff --git a/pkg/scaffold/v2/internal/string_utils_test.go b/pkg/scaffold/internal/templates/v2/internal/string_utils_test.go similarity index 100% rename from pkg/scaffold/v2/internal/string_utils_test.go rename to pkg/scaffold/internal/templates/v2/internal/string_utils_test.go diff --git a/pkg/scaffold/v2/kustomize.go b/pkg/scaffold/internal/templates/v2/kustomize.go similarity index 100% rename from pkg/scaffold/v2/kustomize.go rename to pkg/scaffold/internal/templates/v2/kustomize.go diff --git a/pkg/scaffold/v2/leaderelectionrole.go b/pkg/scaffold/internal/templates/v2/leaderelectionrole.go similarity index 100% rename from pkg/scaffold/v2/leaderelectionrole.go rename to pkg/scaffold/internal/templates/v2/leaderelectionrole.go diff --git a/pkg/scaffold/v2/leaderelectionrolebinding.go b/pkg/scaffold/internal/templates/v2/leaderelectionrolebinding.go similarity index 100% rename from pkg/scaffold/v2/leaderelectionrolebinding.go rename to pkg/scaffold/internal/templates/v2/leaderelectionrolebinding.go diff --git a/pkg/scaffold/v2/main.go b/pkg/scaffold/internal/templates/v2/main.go similarity index 98% rename from pkg/scaffold/v2/main.go rename to pkg/scaffold/internal/templates/v2/main.go index 69a7c529d41..e5d7e52ddb0 100644 --- a/pkg/scaffold/v2/main.go +++ b/pkg/scaffold/internal/templates/v2/main.go @@ -23,7 +23,7 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/file" "sigs.k8s.io/kubebuilder/pkg/model/resource" - "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/internal" + "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/internal" ) const ( diff --git a/pkg/scaffold/v2/makefile.go b/pkg/scaffold/internal/templates/v2/makefile.go similarity index 100% rename from pkg/scaffold/v2/makefile.go rename to pkg/scaffold/internal/templates/v2/makefile.go diff --git a/pkg/scaffold/v2/manager/config.go b/pkg/scaffold/internal/templates/v2/manager/config.go similarity index 100% rename from pkg/scaffold/v2/manager/config.go rename to pkg/scaffold/internal/templates/v2/manager/config.go diff --git a/pkg/scaffold/v2/manager/kustomization.go b/pkg/scaffold/internal/templates/v2/manager/kustomization.go similarity index 100% rename from pkg/scaffold/v2/manager/kustomization.go rename to pkg/scaffold/internal/templates/v2/manager/kustomization.go diff --git a/pkg/scaffold/v2/metricsauth/auth_proxy_patch.go b/pkg/scaffold/internal/templates/v2/metricsauth/auth_proxy_patch.go similarity index 100% rename from pkg/scaffold/v2/metricsauth/auth_proxy_patch.go rename to pkg/scaffold/internal/templates/v2/metricsauth/auth_proxy_patch.go diff --git a/pkg/scaffold/v2/metricsauth/authproxyservice.go b/pkg/scaffold/internal/templates/v2/metricsauth/authproxyservice.go similarity index 100% rename from pkg/scaffold/v2/metricsauth/authproxyservice.go rename to pkg/scaffold/internal/templates/v2/metricsauth/authproxyservice.go diff --git a/pkg/scaffold/v2/metricsauth/clientclusterrole.go b/pkg/scaffold/internal/templates/v2/metricsauth/clientclusterrole.go similarity index 100% rename from pkg/scaffold/v2/metricsauth/clientclusterrole.go rename to pkg/scaffold/internal/templates/v2/metricsauth/clientclusterrole.go diff --git a/pkg/scaffold/v2/mgrrolebinding.go b/pkg/scaffold/internal/templates/v2/mgrrolebinding.go similarity index 100% rename from pkg/scaffold/v2/mgrrolebinding.go rename to pkg/scaffold/internal/templates/v2/mgrrolebinding.go diff --git a/pkg/scaffold/v2/prometheus/kustomize.go b/pkg/scaffold/internal/templates/v2/prometheus/kustomize.go similarity index 100% rename from pkg/scaffold/v2/prometheus/kustomize.go rename to pkg/scaffold/internal/templates/v2/prometheus/kustomize.go diff --git a/pkg/scaffold/v2/prometheus/monitor.go b/pkg/scaffold/internal/templates/v2/prometheus/monitor.go similarity index 100% rename from pkg/scaffold/v2/prometheus/monitor.go rename to pkg/scaffold/internal/templates/v2/prometheus/monitor.go diff --git a/pkg/scaffold/v2/rbac.go b/pkg/scaffold/internal/templates/v2/rbac.go similarity index 100% rename from pkg/scaffold/v2/rbac.go rename to pkg/scaffold/internal/templates/v2/rbac.go diff --git a/pkg/scaffold/v2/types.go b/pkg/scaffold/internal/templates/v2/types.go similarity index 100% rename from pkg/scaffold/v2/types.go rename to pkg/scaffold/internal/templates/v2/types.go diff --git a/pkg/scaffold/v2/webhook/enablecainection_patch.go b/pkg/scaffold/internal/templates/v2/webhook/enablecainection_patch.go similarity index 100% rename from pkg/scaffold/v2/webhook/enablecainection_patch.go rename to pkg/scaffold/internal/templates/v2/webhook/enablecainection_patch.go diff --git a/pkg/scaffold/v2/webhook/kustomization.go b/pkg/scaffold/internal/templates/v2/webhook/kustomization.go similarity index 100% rename from pkg/scaffold/v2/webhook/kustomization.go rename to pkg/scaffold/internal/templates/v2/webhook/kustomization.go diff --git a/pkg/scaffold/v2/webhook/kustomizeconfig.go b/pkg/scaffold/internal/templates/v2/webhook/kustomizeconfig.go similarity index 100% rename from pkg/scaffold/v2/webhook/kustomizeconfig.go rename to pkg/scaffold/internal/templates/v2/webhook/kustomizeconfig.go diff --git a/pkg/scaffold/v2/webhook/service.go b/pkg/scaffold/internal/templates/v2/webhook/service.go similarity index 100% rename from pkg/scaffold/v2/webhook/service.go rename to pkg/scaffold/internal/templates/v2/webhook/service.go diff --git a/pkg/scaffold/v2/webhook/webhook.go b/pkg/scaffold/internal/templates/v2/webhook/webhook.go similarity index 100% rename from pkg/scaffold/v2/webhook/webhook.go rename to pkg/scaffold/internal/templates/v2/webhook/webhook.go diff --git a/pkg/scaffold/v2/webhook_manager_patch.go b/pkg/scaffold/internal/templates/v2/webhook_manager_patch.go similarity index 100% rename from pkg/scaffold/v2/webhook_manager_patch.go rename to pkg/scaffold/internal/templates/v2/webhook_manager_patch.go diff --git a/pkg/scaffold/update.go b/pkg/scaffold/update.go index 8f4a6378bc4..65cd5082df3 100644 --- a/pkg/scaffold/update.go +++ b/pkg/scaffold/update.go @@ -20,7 +20,7 @@ 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/project" + templatesv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1" ) type updateScaffolder struct { @@ -39,6 +39,6 @@ func (s *updateScaffolder) Scaffold() error { model.WithConfig(s.config), model.WithoutBoilerplate, ), - &project.GopkgToml{}, + &templatesv1.GopkgToml{}, ) } diff --git a/pkg/scaffold/webhook.go b/pkg/scaffold/webhook.go index da2e29e1ed6..531c5d21319 100644 --- a/pkg/scaffold/webhook.go +++ b/pkg/scaffold/webhook.go @@ -25,10 +25,10 @@ import ( "sigs.k8s.io/kubebuilder/pkg/model/config" "sigs.k8s.io/kubebuilder/pkg/model/resource" "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/machinery" - managerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/manager" - webhookv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/v1/webhook" - scaffoldv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2" - webhookv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/v2/webhook" + managerv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1/manager" + webhookv1 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v1/webhook" + templatesv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2" + webhookv2 "sigs.k8s.io/kubebuilder/pkg/scaffold/internal/templates/v2/webhook" ) type webhookScaffolder struct { @@ -141,8 +141,8 @@ You need to implement the conversion.Hub and conversion.Convertible interfaces f return err } - if err := (&scaffoldv2.Main{}).Update( - &scaffoldv2.MainUpdateOptions{ + if err := (&templatesv2.Main{}).Update( + &templatesv2.MainUpdateOptions{ Config: s.config, WireResource: false, WireController: false,