Skip to content

Commit

Permalink
🐛 regression - extracommands require a valid PROJECT file again
Browse files Browse the repository at this point in the history
* Handle failing on 3-alpha configs
* Set project fields to default if the stable version is registered
* Added IsRegistered command to registry

Signed-off-by: jesus m. rodriguez <jesusr@redhat.com>
  • Loading branch information
jmrodri committed Apr 8, 2021
1 parent 84f357b commit c10fa17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/kubebuilder/v3/pkg/config"
yamlstore "sigs.k8s.io/kubebuilder/v3/pkg/config/store/yaml"
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
)

Expand Down Expand Up @@ -144,8 +145,21 @@ func newCLI(options ...Option) (*CLI, error) {
func (c *CLI) buildCmd() error {
c.cmd = c.newRootCmd()

var uve config.UnsupportedVersionError

// Get project version and plugin keys.
if err := c.getInfo(); err != nil {
switch err := c.getInfo(); {
case err == nil:
case errors.As(err, &uve) && uve.Version.Compare(config.Version{Number: 3, Stage: stage.Alpha}) == 0:
// Check if the corresponding stable version exists, set c.projectVersion and break
stableVersion := config.Version{
Number: uve.Version.Number,
}
if config.IsRegistered(stableVersion) {
// Get project version and plugin info from defaults
c.getInfoFromDefaults()
}
default:
return err
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/config/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func Register(version Version, constructor func() Config) {
registry[version] = constructor
}

// IsRegistered returns true if the given version has been registered through Register
func IsRegistered(version Version) bool {
_, ok := registry[version]
return ok
}

// New creates Config instances from the previously registered implementations through Register
func New(version Version) (Config, error) {
if constructor, exists := registry[version]; exists {
Expand Down

0 comments on commit c10fa17

Please sign in to comment.