Skip to content

Commit

Permalink
Merge pull request #2294 from acpana/acpana/direct-template
Browse files Browse the repository at this point in the history
enh: some template changes
  • Loading branch information
google-oss-prow[bot] authored Jul 16, 2024
2 parents 85085e5 + 542c8ff commit 727fcd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions dev/tools/controllerbuilder/scaffold/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package scaffold

import (
"bytes"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/controllerbuilder/template/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 727fcd4

Please sign in to comment.