diff --git a/dev/tools/controllerbuilder/template/controller.go b/dev/tools/controllerbuilder/template/controller.go index 0eb13cf482..6b12d514ba 100644 --- a/dev/tools/controllerbuilder/template/controller.go +++ b/dev/tools/controllerbuilder/template/controller.go @@ -123,7 +123,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u if externalRef == "" { id = BuildID(projectID, location, resourceID) } else { - id, err = buildIDFromExternal(externalRef) + id, err = asID(externalRef) if err != nil { return nil, err } @@ -234,7 +234,7 @@ func (a *Adapter) Create(ctx context.Context, u *unstructured.Unstructured) erro if mapCtx.Err() != nil { return mapCtx.Err() } - status.ExternalRef = a.id.ExternalRef() + status.ExternalRef = a.id.AsExternalRef() return setStatus(u, status) } diff --git a/dev/tools/controllerbuilder/template/externalresource.go b/dev/tools/controllerbuilder/template/externalresource.go index aaf96ae143..bd36bcd3a5 100644 --- a/dev/tools/controllerbuilder/template/externalresource.go +++ b/dev/tools/controllerbuilder/template/externalresource.go @@ -39,14 +39,14 @@ func (c *{{.Kind}}Identity) FullyQualifiedName() string { // TODO(user): Define resource fully qualified name } -// ExternalRef builds a externalRef from a {{.Kind}} -func (c *{{.Kind}}Identity) ExternalRef() *string { +// AsExternalRef builds a externalRef from a {{.Kind}} +func (c *{{.Kind}}Identity) AsExternalRef() *string { e := serviceDomain + "/" + c.FullyQualifiedName() return &e } -// BuildIDFromExternal builds a {{.Kind}}Identity from a external reference -func BuildIDFromExternal(externalRef string) (*{{.Kind}}Identity, error) { +// asID builds a {{.Kind}}Identity from a external reference +func asID(externalRef string) (*{{.Kind}}Identity, error) { // TODO(user): Build resource identity from external reference if !strings.HasPrefix(externalRef, serviceDomain) { return nil, fmt.Errorf("externalRef should have prefix %s, got %s", serviceDomain, externalRef) diff --git a/pkg/controller/direct/cloudbuild/workerpool_controller.go b/pkg/controller/direct/cloudbuild/workerpool_controller.go index 7d295ee378..f7ec46d9b2 100644 --- a/pkg/controller/direct/cloudbuild/workerpool_controller.go +++ b/pkg/controller/direct/cloudbuild/workerpool_controller.go @@ -35,7 +35,6 @@ import ( "google.golang.org/protobuf/types/known/fieldmaskpb" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -106,7 +105,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u if externalRef == "" { id = BuildID(projectID, location, resourceID) } else { - id, err = BuildIDFromExternal(externalRef) + id, err = asID(externalRef) if err != nil { return nil, err } @@ -206,7 +205,7 @@ func (a *Adapter) Create(ctx context.Context, u *unstructured.Unstructured) erro if mapCtx.Err() != nil { return mapCtx.Err() } - status.ExternalRef = a.id.ExternalRef() + status.ExternalRef = a.id.AsExternalRef() return setStatus(u, status) } diff --git a/pkg/controller/direct/cloudbuild/workerpool_externalresource.go b/pkg/controller/direct/cloudbuild/workerpool_externalresource.go index e2d1e3e80b..86d91c96a8 100644 --- a/pkg/controller/direct/cloudbuild/workerpool_externalresource.go +++ b/pkg/controller/direct/cloudbuild/workerpool_externalresource.go @@ -41,14 +41,14 @@ func (c *CloudBuildWorkerPoolIdentity) FullyQualifiedName() string { return fmt.Sprintf("projects/%s/locations/%s/workerPools/%s", c.project, c.location, c.workerpool) } -// ExternalRef builds a externalRef from a CloudBuildWorkerPoolIdentity -func (c *CloudBuildWorkerPoolIdentity) ExternalRef() *string { +// AsExternalRef builds a externalRef from a CloudBuildWorkerPoolIdentity +func (c *CloudBuildWorkerPoolIdentity) AsExternalRef() *string { e := serviceDomain + "/" + c.FullyQualifiedName() return &e } -// BuildIDFromExternal builds a CloudBuildWorkerPoolIdentity from a externalRef -func BuildIDFromExternal(externalRef string) (*CloudBuildWorkerPoolIdentity, error) { +// asID builds a CloudBuildWorkerPoolIdentity from a externalRef +func asID(externalRef string) (*CloudBuildWorkerPoolIdentity, error) { if !strings.HasPrefix(externalRef, serviceDomain) { return nil, fmt.Errorf("externalRef should have prefix %s, got %s", serviceDomain, externalRef) }