-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve resource reference(initial PR) #2337
Resolve resource reference(initial PR) #2337
Conversation
apis/refs/v1beta1/resourceref.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to get rid of a generic resourceRef
but using more dedicated kind. Any reasons to switch it back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by reading the code, I think this is just a naming thing. Maybe move the functions to the computenetoworkref.go file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed generic resourceRef
apis/refs/v1beta1/util.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big fan of util.go
. How about adapter.go
(convert from the alpha resourceRef to beta Ref)? And move the GetResourceID
and location
to another file. And I think the GetResourceID
and GetLocation
shall not be under the ref dir eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved GetResourceID
GetLocation
and GetProjectID
(not resolve project) to helper.go
(or maybe a better name), those methods can be reused.
apis/refs/v1beta1/resourceref.go
Outdated
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func ComputeNetworkRef_ConvertToExternal(ctx context.Context, reader client.Reader, src client.Object, ref *v1alpha1.ResourceRef) (*v1alpha1.ResourceRef, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this name! And I also think we can actually having our tools to auto-generate this functions when adding new resources from proto!
apis/refs/v1beta1/resourceref.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by reading the code, I think this is just a naming thing. Maybe move the functions to the computenetoworkref.go file
0e8e619
to
009d76b
Compare
@@ -90,7 +91,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u | |||
} | |||
|
|||
// Get GCP Project | |||
projectRef, err := refs.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef) | |||
projectRef, err := resolverefs.ResolveProjectRef(ctx, reader, obj, obj.Spec.ProjectRef) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I moved the resolver functions into the API package recently. The intent was that we could then have the resolvers implement an interface, and make a lot of this generic.
WDYT - can we put the resolver functions into the refs package? (We could even just add a ResolveRef
function to each ref in this PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the placement of resolver functions, I don't have a strong preference. It could be api/refs/projectref.go
or direct/refs/projectref.go
. I think we should maintain consistency in the future. I'm open to moving the resolver functions to api/refs
if that's preferable.
My main concern here is avoiding placing these functions in individual controller packages, for example direct/compute/networkref.go
. Some references are used in multiple resources, like ComputeNetWork
, which is referenced by CloudBuildWorkerPool
and ComputeForwardingRule
(and potentially others).
return location, nil | ||
} | ||
|
||
func GetProjectID(ctx context.Context, reader client.Reader, obj *unstructured.Unstructured) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this was called something like "ResolveProjectID" as a hint that we might have to go chase down some references etc. I don't mind renaming it if it's confusing, but maybe add a comment to the function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted it back to ResolveProjectID, will address in another PR if needed.
if len(tokens) == 5 && tokens[0] == "projects" && tokens[2] == "global" && tokens[3] == "targetHttpProxies" { | ||
return &ComputeTargetHTTPProxy{ | ||
Project: tokens[1], | ||
ComputeTargetHTTPProxyID: tokens[4]}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we should set Location == global here, so it round trips?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed!
ProjectID string | ||
} | ||
|
||
// ResolveProjectRef will resolve a ProjectRef to a Project, with the ProjectID. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBD if this should actually just return a ProjectRef, to follow the pattern we seem to have built since. But no need to address in this PR (unless you want to)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted it back, will address in another PR if needed.
d69b507
to
48a7303
Compare
Chatted with @yuwenma offline and reverted the function name change. I will have a followup PR to resolve other refs(i.e. compute address, subnetwork etc), and a tool to auto-generate the resolver functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
apis/refs/v1beta1/helper.go
Outdated
@@ -30,3 +29,16 @@ func GetResourceID(u *unstructured.Unstructured) (string, error) { | |||
} | |||
return resourceID, nil | |||
} | |||
|
|||
// TODO(yuhou): Location can be optional. Use provider default location when it's unset. | |||
func GetLocation(obj *unstructured.Unstructured) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only called once, it is better to put the code inside ResolveTargetHTTPProxy
or change this to a private function, in case it is misused by other functions (more context, I think more work needs to be done for location so it may not be ready to share yet)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I think we'll eventually make GetLocation
a helper function because it will be used in resolving more references. I agree that we need to do so when it's fully functional.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Ooops ... didn't realize @yuwenma was looking at this also. /hold (for yuwen's reviews) |
/hold cancel |
2b0f384
into
GoogleCloudPlatform:master
Change description
Rebased on #2352
resolve<resource>
functions intoapis/refs/
package.GetResourceID
,GetLocation
helper functions.TODO:
Draft a tool to auto-generate the resolve logic.
Note:
I only include ComputeNetworkRef and ComputeTargetHTTPProxyRef in this PR. More references will be required for ComputeForwardingRule.
Tests you have done
make ready-pr
to ensure this PR is ready for review.