Skip to content

Commit 727fcd4

Browse files
Merge pull request GoogleCloudPlatform#2294 from acpana/acpana/direct-template
enh: some template changes
2 parents 85085e5 + 542c8ff commit 727fcd4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

dev/tools/controllerbuilder/scaffold/controller.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ package scaffold
1616

1717
import (
1818
"bytes"
19+
"errors"
1920
"fmt"
21+
"io/fs"
2022
"os"
2123
"path/filepath"
2224
"strings"
@@ -70,10 +72,15 @@ func BuildControllerPath(service, kind string) (string, error) {
7072
return "", fmt.Errorf("create controller directory %s: %w", controllerDir, err)
7173
}
7274
controllerFilePath := filepath.Join(controllerDir, strings.ToLower(kind)+"_controller.go")
73-
if _, err := os.Stat(controllerFilePath); err == nil {
74-
return "", fmt.Errorf("controller file %s may already exist: %w", controllerFilePath, err)
75+
if _, err = os.Stat(controllerFilePath); err != nil {
76+
if !errors.Is(err, fs.ErrNotExist) {
77+
return "", fmt.Errorf("could not stat path %s: %w", controllerFilePath, err)
78+
}
79+
// otherwise create the file
80+
return controllerFilePath, nil
7581
}
76-
return controllerFilePath, nil
82+
83+
return "", fmt.Errorf("controller file %s may already exist:", controllerFilePath)
7784
}
7885

7986
func FormatImports(path string, out []byte) error {

dev/tools/controllerbuilder/template/controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
129129
130130
func (m *model) AdapterForURL(ctx context.Context, url string) (directbase.Adapter, error) {
131131
// TODO: Support URLs
132-
return nil, nil
132+
return nil, fmt.Errorf("AdapterForURL not supported for {{.Kind}} yet")
133133
}
134134
135135
type Adapter struct {
@@ -247,7 +247,7 @@ func (a *Adapter) Update(ctx context.Context, u *unstructured.Unstructured) erro
247247
248248
func (a *Adapter) Export(ctx context.Context) (*unstructured.Unstructured, error) {
249249
// TODO(kcc)
250-
return nil, nil
250+
return nil, fmt.Errorf("Export not supported for {{.Kind}} yet")
251251
}
252252
253253
// Delete implements the Adapter interface.

0 commit comments

Comments
 (0)