Skip to content

Commit

Permalink
All scaffold templates and machinery are housed under pkg/plugin since
Browse files Browse the repository at this point in the history
that machinery directly and only relates to plugins. Scaffold templates
are also versioned with plugin major version, ex. pkg/plugin/v2.
  • Loading branch information
estroz committed Jun 4, 2020
1 parent 44997bf commit 6fde51d
Show file tree
Hide file tree
Showing 67 changed files with 66 additions and 59 deletions.
5 changes: 3 additions & 2 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmdutil/cmdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package internal
package util

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package internal
package util

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package internal
package util

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package internal
package util

import (
"bufio"
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions pkg/plugin/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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")
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
19 changes: 10 additions & 9 deletions pkg/plugin/v2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/scaffold/api.go → pkg/plugin/v2/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package scaffold
package scaffolds

import (
"fmt"

"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.
Expand All @@ -55,7 +56,7 @@ func NewAPIScaffolder(
res *resource.Resource,
doResource, doController bool,
plugins []model.Plugin,
) Scaffolder {
) scaffold.Scaffolder {
return &apiScaffolder{
config: config,
boilerplate: boilerplate,
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/doc.go → pkg/plugin/v2/scaffolds/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ limitations under the License.
*/

// Package scaffold contains libraries for scaffolding code to use with controller-runtime
package scaffold
package scaffolds
7 changes: 4 additions & 3 deletions pkg/scaffold/edit.go → pkg/plugin/v2/scaffolds/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package scaffold
package scaffolds

import (
"fmt"
"io/ioutil"
"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
multigroup bool
}

// 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,
Expand Down
21 changes: 11 additions & 10 deletions pkg/scaffold/init.go → pkg/plugin/v2/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package scaffold
package scaffolds

import (
"fmt"
Expand All @@ -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 (
Expand All @@ -43,7 +44,7 @@ const (
imageName = "controller:latest"
)

var _ Scaffolder = &initScaffolder{}
var _ scaffold.Scaffolder = &initScaffolder{}

type initScaffolder struct {
config *config.Config
Expand All @@ -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"),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 7 additions & 6 deletions pkg/scaffold/webhook.go → pkg/plugin/v2/scaffolds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package scaffold
package scaffolds

import (
"fmt"

"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
Expand All @@ -46,7 +47,7 @@ func NewWebhookScaffolder(
defaulting bool,
validation bool,
conversion bool,
) Scaffolder {
) scaffold.Scaffolder {
return &webhookScaffolder{
config: config,
boilerplate: boilerplate,
Expand Down
5 changes: 3 additions & 2 deletions pkg/plugin/v2/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 6fde51d

Please sign in to comment.