-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add support for composite types for zonal resources #804
Conversation
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
5554093
to
a22326a
Compare
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.
👍
/assign @bowei |
} | ||
|
||
{{if .HasUpdate}} | ||
func Update{{.Name}}(gceCloud *gce.Cloud, key *meta.Key, {{.VarName}} *{{.Name}}) 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.
this feels like a lot of cut and paste.
can we make this more succinct by parametrizing this on <scope, version> (e.g. <global, alpha>) etc so we only need to maintain one block of template text
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.
Are you referring to the duplicate code in lines 210-239 and 247 to 275? Those are the same except the operation is Create vs Update. We are following the same pattern for RegionalDefault and GlobalDefault resources.
64d1412
to
05c8073
Compare
@spencerhance @bowei I have modified the template text to a single block for regional/global/zonal cases. PTAL, thanks. |
pkg/composite/gen.go
Outdated
// ToForwardingRuleList converts a list of compute alpha, beta or GA | ||
// ForwardingRule into a list of our composite type. | ||
func ToForwardingRuleList(objs interface{}) ([]*ForwardingRule, error) { | ||
result := []*ForwardingRule{} | ||
|
||
err := copyViaJSON(&result, objs) | ||
if err != nil { | ||
return nil, fmt.Errorf("Could not copy object %v to list of ForwardingRule via JSON: %v", objs, err) | ||
return nil, fmt.Errorf("could not copy object %v to list of ForwardingRule via JSON: %v", objs, err) |
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.
can do
return nil, fmt.Errorf("could not copy object %v to %T via JSON: %v", objs, results, err)
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.
We use the template variable substitution {{type.Name}} to generate this. Fixed it to use %T.
pkg/composite/gen.go
Outdated
switch key.Type() { | ||
case meta.Zonal: | ||
default: | ||
return fmt.Errorf("Key %v not valid for zonal resource NetworkEndpointGroup %v", key.Type(), key.Name) |
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.
print the whole key instead of key.Type()
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
pkg/composite/gen.go
Outdated
return nil, err | ||
} | ||
compositeType.Scope = meta.Zonal | ||
|
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.
delete \n
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
pkg/composite/gen.go
Outdated
alpha := &computealpha.NetworkEndpointGroup{} | ||
err := copyViaJSON(alpha, networkEndpointGroup) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting NetworkEndpointGroup to compute alpha type via JSON: %v", err) |
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.
see comment above about using %T instead of writing out each object type
pkg/composite/gen.go
Outdated
beta := &computebeta.NetworkEndpointGroup{} | ||
err := copyViaJSON(beta, networkEndpointGroup) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting NetworkEndpointGroup to compute beta type via JSON: %v", err) |
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.
see comment above about using %T instead of writing out each object type
pkg/composite/gen.go
Outdated
ga := &compute.NetworkEndpointGroupsAttachEndpointsRequest{} | ||
err := copyViaJSON(ga, networkEndpointGroupsAttachEndpointsRequest) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting NetworkEndpointGroupsAttachEndpointsRequest to compute ga type via JSON: %v", err) |
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.
see comment above about using %T instead of writing out each object type
pkg/composite/gen.go
Outdated
networkEndpointGroupsDetachEndpointsRequest := &NetworkEndpointGroupsDetachEndpointsRequest{} | ||
err := copyViaJSON(networkEndpointGroupsDetachEndpointsRequest, obj) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not copy object %+v to NetworkEndpointGroupsDetachEndpointsRequest via JSON: %v", obj, err) |
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.
see comment above about using %T instead of writing out each object type
pkg/composite/gen.go
Outdated
alpha := &computealpha.NetworkEndpointGroupsDetachEndpointsRequest{} | ||
err := copyViaJSON(alpha, networkEndpointGroupsDetachEndpointsRequest) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting NetworkEndpointGroupsDetachEndpointsRequest to compute alpha type via JSON: %v", err) |
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.
see comment above about using %T instead of writing out each object type
pkg/composite/gen.go
Outdated
beta := &computebeta.NetworkEndpointGroupsDetachEndpointsRequest{} | ||
err := copyViaJSON(beta, networkEndpointGroupsDetachEndpointsRequest) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting NetworkEndpointGroupsDetachEndpointsRequest to compute beta type via JSON: %v", err) |
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.
see comment above about using %T instead of writing out each object type
pkg/composite/gen.go
Outdated
ga := &compute.NetworkEndpointGroupsDetachEndpointsRequest{} | ||
err := copyViaJSON(ga, networkEndpointGroupsDetachEndpointsRequest) | ||
if err != nil { | ||
return nil, fmt.Errorf("error converting NetworkEndpointGroupsDetachEndpointsRequest to compute ga type via JSON: %v", err) |
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.
see comment above about using %T instead of writing out each object type
looks pretty good, just a few cleanups |
05c8073
to
7a4d70e
Compare
Thanks for the review, I have made the recommended changes. PTAL, thanks! |
Create "ServerResponse" field only for MainServices that require CRUD methods. Combined regional,global, zonal templates into one. Added comments
7a4d70e
to
af13535
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bowei, prameshj 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 |
Current usecase is for using NetworkEndpointGroups.