Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins Phase 1 #1469

Merged
merged 13 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ bin/*
/testdata/project-v2/go.sum
/testdata/project-v2-addon/go.sum
/testdata/project-v2-multigroup/go.sum
/testdata/project-v3/go.sum
/testdata/project-v3-multigroup/go.sum
/testdata/project-v3-addon/go.sum
221 changes: 0 additions & 221 deletions cmd/api.go

This file was deleted.

38 changes: 17 additions & 21 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ limitations under the License.
package main

import (
"errors"
"fmt"
"log"
"os"

"github.com/spf13/cobra"

"sigs.k8s.io/kubebuilder/internal/cmdutil"
"sigs.k8s.io/kubebuilder/internal/config"
"sigs.k8s.io/kubebuilder/pkg/scaffold"
)
Expand All @@ -49,7 +48,11 @@ func newEditCmd() *cobra.Command {
# Disable the multigroup layout
kubebuilder edit --multigroup=false`,
Run: func(_ *cobra.Command, _ []string) {
if err := run(options); err != nil {
var err error
if options.config, err = config.LoadInitialized(); err != nil {
log.Fatal(err)
}
if err := cmdutil.Run(options); err != nil {
log.Fatal(editError{err})
}
},
Expand All @@ -60,39 +63,32 @@ func newEditCmd() *cobra.Command {
return cmd
}

var _ commandOptions = &editOptions{}
var _ cmdutil.RunOptions = &editOptions{}

type editOptions struct {
config *config.Config

multigroup bool
}

func (o *editOptions) bindFlags(cmd *cobra.Command) {
cmd.Flags().BoolVar(&o.multigroup, "multigroup", false, "enable or disable multigroup layout")
}

func (o *editOptions) loadConfig() (*config.Config, error) {
projectConfig, err := config.Load()
if os.IsNotExist(err) {
return nil, errors.New("unable to find configuration file, project must be initialized")
}

return projectConfig, err
}

func (o *editOptions) validate(c *config.Config) error {
if !c.IsV2() {
if c.MultiGroup {
return fmt.Errorf("multiple group support can't be enabled for version %s", c.Version)
func (o *editOptions) Validate() error {
if !o.config.IsV2() && !o.config.IsV3() {
Copy link
Member

@camilamacedo86 camilamacedo86 Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !o.config.IsV2() && !o.config.IsV3() {
if o.config.IsV1() {

Copy link
Member

@camilamacedo86 camilamacedo86 Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make easier remove the if to clean the code if/when we remove V1 impl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this was the intent, but using !o.config.IsV2() && !o.config.IsV3() means that we would need to explicitly assert that a future version (e.g. v4) supports multi-group. This is probably safer than assuming that all future versions will support multi-group.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once #1355 is merged I will rebase to remove v1 checks.

if o.config.MultiGroup {
return fmt.Errorf("multiple group support can't be enabled for version %s", o.config.Version)
}
}

return nil
}

func (o *editOptions) scaffolder(c *config.Config) (scaffold.Scaffolder, error) { //nolint:unparam
return scaffold.NewEditScaffolder(c, o.multigroup), nil
func (o *editOptions) GetScaffolder() (scaffold.Scaffolder, error) {
return scaffold.NewEditScaffolder(&o.config.Config, o.multigroup), nil
}

func (o *editOptions) postScaffold(_ *config.Config) error {
return nil
func (o *editOptions) PostScaffold() error {
return o.config.Save()
}
Loading