Skip to content

Commit

Permalink
revert naming change
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Aug 14, 2024
1 parent b2759c1 commit 8e98e75
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dev/tools/controllerbuilder/template/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions dev/tools/controllerbuilder/template/externalresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions pkg/controller/direct/cloudbuild/workerpool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 8e98e75

Please sign in to comment.