diff --git a/dev/tools/controllerbuilder/scaffold/controller.go b/dev/tools/controllerbuilder/scaffold/controller.go index d440adec9f..3adf7011d6 100644 --- a/dev/tools/controllerbuilder/scaffold/controller.go +++ b/dev/tools/controllerbuilder/scaffold/controller.go @@ -16,7 +16,9 @@ package scaffold import ( "bytes" + "errors" "fmt" + "io/fs" "os" "path/filepath" "strings" @@ -70,10 +72,15 @@ func BuildControllerPath(service, kind string) (string, error) { return "", fmt.Errorf("create controller directory %s: %w", controllerDir, err) } controllerFilePath := filepath.Join(controllerDir, strings.ToLower(kind)+"_controller.go") - if _, err := os.Stat(controllerFilePath); err == nil { - return "", fmt.Errorf("controller file %s may already exist: %w", controllerFilePath, err) + if _, err = os.Stat(controllerFilePath); err != nil { + if !errors.Is(err, fs.ErrNotExist) { + return "", fmt.Errorf("could not stat path %s: %w", controllerFilePath, err) + } + // otherwise create the file + return controllerFilePath, nil } - return controllerFilePath, nil + + return "", fmt.Errorf("controller file %s may already exist:", controllerFilePath) } func FormatImports(path string, out []byte) error { diff --git a/dev/tools/controllerbuilder/template/controller.go b/dev/tools/controllerbuilder/template/controller.go index 0bb18f973f..0c0f8b2a1c 100644 --- a/dev/tools/controllerbuilder/template/controller.go +++ b/dev/tools/controllerbuilder/template/controller.go @@ -129,7 +129,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u func (m *model) AdapterForURL(ctx context.Context, url string) (directbase.Adapter, error) { // TODO: Support URLs - return nil, nil + return nil, fmt.Errorf("AdapterForURL not supported for {{.Kind}} yet") } type Adapter struct { @@ -247,7 +247,7 @@ func (a *Adapter) Update(ctx context.Context, u *unstructured.Unstructured) erro func (a *Adapter) Export(ctx context.Context) (*unstructured.Unstructured, error) { // TODO(kcc) - return nil, nil + return nil, fmt.Errorf("Export not supported for {{.Kind}} yet") } // Delete implements the Adapter interface.