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

feat: Direct controller for ComputeForwardingRule #2364

Merged

Conversation

gemmahou
Copy link
Collaborator

@gemmahou gemmahou commented Jul 26, 2024

Change description

Tests you have done

  • Run make ready-pr to ensure this PR is ready for review.
  • Perform necessary E2E testing for changed resources.

@gemmahou gemmahou force-pushed the direct-controller branch 8 times, most recently from 64c01cf to 8be07af Compare August 3, 2024 00:12
},
"loadBalancingScheme": "EXTERNAL",
"name": "computeregionalforwardingrule-${uniqueId}",
"region": "projects/${projectId}/global/regions/us-central1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This region looks problematic. I will investigate where the value comes from.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It may not be an issue because it's in the URL

@gemmahou gemmahou force-pushed the direct-controller branch from 8be07af to 9fdbedc Compare August 5, 2024 17:50
@gemmahou gemmahou force-pushed the direct-controller branch from 9fdbedc to eea1f1c Compare August 5, 2024 22:01
@gemmahou gemmahou marked this pull request as ready for review August 5, 2024 22:02
@gemmahou gemmahou force-pushed the direct-controller branch 3 times, most recently from 9925f9e to 6ee76cb Compare August 6, 2024 23:55
}
log.V(2).Info("successfully created ComputeForwardingRule", "name", a.fullyQualifiedName())
// Get the created resource
created := &computepb.ForwardingRule{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Insert returns a computepb.Operation, which op.Status could be either OpDone or OpPending Code. I think we shall probably only proceed the following GCP Get when we get a OpDone.

For OpPending, we probably want to return quietly and update the KCC .status in the next Reconcile, maybe Find/Update? @justinsb I'll vote for Update, do you have a preference?

Copy link
Collaborator Author

@gemmahou gemmahou Aug 28, 2024

Choose a reason for hiding this comment

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

I won't worry about this because we call op.Wait()(source code) a few lines above, and it makes sure that the operation is Done.

@gemmahou gemmahou mentioned this pull request Aug 20, 2024
2 tasks
@gemmahou gemmahou force-pushed the direct-controller branch 4 times, most recently from c51505c to 8c304c6 Compare August 22, 2024 22:59
@gemmahou gemmahou force-pushed the direct-controller branch 2 times, most recently from 924dd21 to 4588327 Compare August 23, 2024 21:55
@gemmahou gemmahou changed the title WIP: feat: Direct controller for ComputeForwardingRule feat: Direct controller for ComputeForwardingRule Aug 26, 2024
func (m *optionsRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
if m.config.UserAgent != "" {
req.Header.Set("User-Agent", m.config.UserAgent)
req.Header.Del("x-goog-request-params")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know what this header is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmmm I'm actually unsure why this added... and seems it's not deleted by Del. I also noticed that other direct resources(monitoringdashboard, cloudbuildworkerpool) have this header as well, I would guess it comes from the underlying GCP?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed!

return nil, err

}
obj.Spec.NetworkRef.External = networkRef.External
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: you may want to clear the other fields in the NetworkRef. But not a big deal, and we may be able to move all reference-resolution into a shared function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean cleaning up other fields like Name in obj.Spec.NetworkRef? I won't worry about other fields because we get value from External only, see the mapping function: code

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, it might be clearer/safer if you did clear all those other fields, it's a nit because I agree it shouldn't change functionality.

return nil, err
}

if id.project != projectID {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this equivalent to BuildID(...) != asID(externalRef) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but this way, we have a better idea (via separate error messages) of which specific field has been changed.

pkg/controller/direct/compute/forwardingrule_controller.go Outdated Show resolved Hide resolved
}
log.V(2).Info("successfully updated ComputeForwardingRule labels", "name", a.fullyQualifiedName())
// Get the updated resource
if a.id.location == "global" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have to get it here, we also get it a few lines down....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Call Get twice, once after updating labels and once after updating targets, to match the realGCP http log.

pkg/controller/direct/compute/forwardingrule_controller.go Outdated Show resolved Hide resolved
@@ -37,7 +22,6 @@ spec:
networkRef:
name: default
portRange: "80"
resourceID: computeglobalforwardingrule-${uniqueId}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm... maybe we don't then :-) I was worried about compatibility, but as it's not server-generated I don't think it will trip anyone up!

},
"loadBalancingScheme": "EXTERNAL",
"name": "computeregionalforwardingrule-${uniqueId}",
"region": "projects/${projectId}/global/regions/us-central1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may not be an issue because it's in the URL


{
"labelFingerprint": "abcdef0123A=",
"labels": {
"cnrm-test": "true",
"label-one": "value-one",
"label-one": "value-two",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the "always calls setLabels" behaviour you were talking about with the old controller?

@@ -776,10 +715,12 @@ X-Xss-Protection: 0

---

GET https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationID}?alt=json&prettyPrint=false
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had thought this looked like we weren't checking the LRO on delete, but ... we are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the log.
I think that's because I made a mistake in mockgcp/mockcompute/regionalforwardingrulev1.go: Should use return s.startRegionalLRO not return s.startGlobalLRO. I updated the mock as well.

@justinsb
Copy link
Collaborator

Looks good, a few questions but nothing blocking I don't think! Will LGTM but add hold, feel free to address questions here or in a separate PR as you see fit.

/approve
/lgtm
/hold

return nil, err

}
obj.Spec.NetworkRef.External = networkRef.External
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, it might be clearer/safer if you did clear all those other fields, it's a nit because I agree it shouldn't change functionality.

@google-oss-prow google-oss-prow bot added the lgtm label Aug 28, 2024
Copy link
Contributor

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

@google-oss-prow google-oss-prow bot merged commit 240941d into GoogleCloudPlatform:master Aug 28, 2024
13 checks passed
@gemmahou gemmahou deleted the direct-controller branch August 28, 2024 23:41
@yuwenma yuwenma added this to the 1.122 milestone Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants