diff --git a/pkg/plugin/external/types.go b/pkg/plugin/external/types.go index 35200eb10f9..0e708aec0fe 100644 --- a/pkg/plugin/external/types.go +++ b/pkg/plugin/external/types.go @@ -17,7 +17,7 @@ limitations under the License. package external import ( - v3cfg "sigs.k8s.io/kubebuilder/v3/pkg/config/v3" + "sigs.k8s.io/kubebuilder/v3/pkg/config" "sigs.k8s.io/kubebuilder/v3/pkg/plugin" ) @@ -40,7 +40,7 @@ type PluginRequest struct { Universe map[string]string `json:"universe"` // Config stores the project configuration file. - Config v3cfg.Cfg `json:"config"` + Config config.Config `json:"config"` } // PluginResponse is returned to kubebuilder by the plugin and contains all files @@ -71,7 +71,7 @@ type PluginResponse struct { Flags []Flag `json:"flags,omitempty"` // Config stores the project configuration file. - Config v3cfg.Cfg `json:"config"` + Config config.Config `json:"config"` } // Flag is meant to represent a CLI flag that is used by Kubebuilder to define flags that are parsed diff --git a/pkg/plugins/external/api.go b/pkg/plugins/external/api.go index 6ea00fa7fdf..dac2de1791b 100644 --- a/pkg/plugins/external/api.go +++ b/pkg/plugins/external/api.go @@ -17,10 +17,11 @@ limitations under the License. package external import ( + "github.com/spf13/afero" "github.com/spf13/pflag" "sigs.k8s.io/kubebuilder/v3/pkg/config" - v3cfg "sigs.k8s.io/kubebuilder/v3/pkg/config/v3" + "sigs.k8s.io/kubebuilder/v3/pkg/config/store/yaml" "sigs.k8s.io/kubebuilder/v3/pkg/machinery" "sigs.k8s.io/kubebuilder/v3/pkg/model/resource" "sigs.k8s.io/kubebuilder/v3/pkg/plugin" @@ -53,13 +54,16 @@ func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) { } func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error { - cfg := p.config.(*v3cfg.Cfg) + cfg := yaml.New(machinery.Filesystem{FS: afero.NewOsFs()}) + if err := cfg.Load(); err != nil { + return err + } req := external.PluginRequest{ APIVersion: defaultAPIVersion, Command: "create api", Args: p.Args, - Config: *cfg, + Config: cfg.Config(), } err := handlePluginResponse(fs, req, p.Path, p) diff --git a/pkg/plugins/external/helpers.go b/pkg/plugins/external/helpers.go index 15b5147c9ad..b6acfae1531 100644 --- a/pkg/plugins/external/helpers.go +++ b/pkg/plugins/external/helpers.go @@ -176,7 +176,7 @@ func handlePluginResponse(fs machinery.Filesystem, req external.PluginRequest, p } // update the config - if err := p.InjectConfig(&res.Config); err != nil { + if err := p.InjectConfig(res.Config); err != nil { return fmt.Errorf("error injecting the updated config from PluginResponse: %w", err) } diff --git a/pkg/plugins/external/init.go b/pkg/plugins/external/init.go index 6a925c11291..ff706f44e00 100644 --- a/pkg/plugins/external/init.go +++ b/pkg/plugins/external/init.go @@ -17,10 +17,13 @@ limitations under the License. package external import ( + "os" + + "github.com/spf13/afero" "github.com/spf13/pflag" "sigs.k8s.io/kubebuilder/v3/pkg/config" - v3cfg "sigs.k8s.io/kubebuilder/v3/pkg/config/v3" + "sigs.k8s.io/kubebuilder/v3/pkg/config/store/yaml" "sigs.k8s.io/kubebuilder/v3/pkg/machinery" "sigs.k8s.io/kubebuilder/v3/pkg/plugin" "sigs.k8s.io/kubebuilder/v3/pkg/plugin/external" @@ -43,13 +46,28 @@ func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) { } func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error { - cfg := p.config.(*v3cfg.Cfg) + fileName := "PROJECT" + + if _, err := os.Stat(fileName); os.IsNotExist(err) { + file, err := os.Create(fileName) + if err != nil { + return err + } + defer file.Close() + } + + cfg := yaml.New(machinery.Filesystem{FS: afero.NewOsFs()}) + // cfg.Config().SetVersion(3) + + if err := cfg.Load(); err != nil { + return err + } req := external.PluginRequest{ APIVersion: defaultAPIVersion, Command: "init", Args: p.Args, - Config: *cfg, + Config: cfg.Config(), } err := handlePluginResponse(fs, req, p.Path, p)