diff --git a/pkg/scaffold/api.go b/pkg/scaffold/api.go index cf2ee108a09..3e0ed4f9d38 100644 --- a/pkg/scaffold/api.go +++ b/pkg/scaffold/api.go @@ -228,9 +228,13 @@ func (api *API) scaffoldV2() error { if api.DoController { fmt.Println(filepath.Join("controllers", fmt.Sprintf("%s_controller.go", strings.ToLower(r.Kind)))) + scaffold := &Scaffold{ + Plugins: api.Plugins, + } + ctrlScaffolder := &resourcev2.Controller{Resource: r} testsuiteScaffolder := &resourcev2.ControllerSuiteTest{Resource: r} - err := (&Scaffold{}).Execute( + err := scaffold.Execute( api.buildUniverse(), input.Options{}, testsuiteScaffolder, diff --git a/plugins/addon/channel.go b/plugins/addon/channel.go index f07a6100af1..8a7ce16158d 100644 --- a/plugins/addon/channel.go +++ b/plugins/addon/channel.go @@ -32,8 +32,9 @@ func ExampleChannel(u *model.Universe) error { m := &model.File{ Path: filepath.Join("channels", "stable"), Contents: exampleChannel, - IfExistsAction: input.Error, + IfExistsAction: input.Skip, } - return AddFile(u, m) + _, err := AddFile(u, m) + return err } diff --git a/plugins/addon/helpers.go b/plugins/addon/helpers.go index e016f169f6d..bd769b651b1 100644 --- a/plugins/addon/helpers.go +++ b/plugins/addon/helpers.go @@ -16,21 +16,24 @@ import ( type PluginFunc func(u *model.Universe) error -// AddFile adds the specified file to the model, returning a file if the file already exists -func AddFile(u *model.Universe, add *model.File) error { +// AddFile adds the specified file to the model. +// If the file exists the function returns false and does not modify the Universe +// If the file does not exist, the function returns true and adds the file to the Universe +// If there is a problem with the file the function returns an error +func AddFile(u *model.Universe, add *model.File) (bool, error) { p := add.Path if p == "" { - return fmt.Errorf("path must be set") + return false, fmt.Errorf("path must be set") } for _, f := range u.Files { if f.Path == p { - return fmt.Errorf("file already exists at path %q", p) + return false, nil } } u.Files = append(u.Files, add) - return nil + return true, nil } // ReplaceFileIfExists replaces the specified file in the model by path diff --git a/plugins/addon/manifest.go b/plugins/addon/manifest.go index 12dd6d71e39..2764f1b6fd2 100644 --- a/plugins/addon/manifest.go +++ b/plugins/addon/manifest.go @@ -35,10 +35,12 @@ func ExampleManifest(u *model.Universe) error { m := &model.File{ Path: filepath.Join("channels", "packages", packageName, exampleManifestVersion, "manifest.yaml"), Contents: exampleManifestContents, - IfExistsAction: input.Error, + IfExistsAction: input.Skip, } - return AddFile(u, m) + _, err := AddFile(u, m) + + return err } // getPackageName returns the (default) name of the declarative package diff --git a/plugins/addon/type.go b/plugins/addon/type.go index de59ae58fda..cd2fc5914a8 100644 --- a/plugins/addon/type.go +++ b/plugins/addon/type.go @@ -19,7 +19,7 @@ func ReplaceTypes(u *model.Universe) error { } m := &model.File{ - Path: filepath.Join("controllers", strings.ToLower(u.Resource.Kind)+"_controller.go"), + Path: filepath.Join("api", u.Resource.Version, strings.ToLower(u.Resource.Kind)+"_types.go"), Contents: contents, IfExistsAction: input.Error, }