Skip to content
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

Merged
merged 2 commits into from
Oct 8, 2019

Conversation

prameshj
Copy link
Contributor

Current usecase is for using NetworkEndpointGroups.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 25, 2019
@prameshj
Copy link
Contributor Author

@spencerhance @bowei

@k8s-ci-robot k8s-ci-robot requested review from bowei and MrHohn July 25, 2019 21:54
Copy link
Contributor

@spencerhance spencerhance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@spencerhance spencerhance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@prameshj
Copy link
Contributor Author

prameshj commented Aug 2, 2019

/assign @bowei

}

{{if .HasUpdate}}
func Update{{.Name}}(gceCloud *gce.Cloud, key *meta.Key, {{.VarName}} *{{.Name}}) error {
Copy link
Member

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

Copy link
Contributor Author

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.

@prameshj prameshj force-pushed the composite-zonal branch 4 times, most recently from 64d1412 to 05c8073 Compare October 3, 2019 19:48
@prameshj
Copy link
Contributor Author

prameshj commented Oct 3, 2019

@spencerhance @bowei I have modified the template text to a single block for regional/global/zonal cases. PTAL, thanks.

// 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)
Copy link
Member

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)

Copy link
Contributor Author

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.

switch key.Type() {
case meta.Zonal:
default:
return fmt.Errorf("Key %v not valid for zonal resource NetworkEndpointGroup %v", key.Type(), key.Name)
Copy link
Member

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return nil, err
}
compositeType.Scope = meta.Zonal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete \n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Copy link
Member

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

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)
Copy link
Member

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

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)
Copy link
Member

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

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)
Copy link
Member

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

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)
Copy link
Member

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

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)
Copy link
Member

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

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)
Copy link
Member

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

@bowei
Copy link
Member

bowei commented Oct 7, 2019

looks pretty good, just a few cleanups

@prameshj
Copy link
Contributor Author

prameshj commented Oct 8, 2019

looks pretty good, just a few cleanups

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
@bowei
Copy link
Member

bowei commented Oct 8, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 8, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 8, 2019
@k8s-ci-robot k8s-ci-robot merged commit 577c0e4 into kubernetes:master Oct 8, 2019
@prameshj prameshj deleted the composite-zonal branch October 9, 2019 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants