-
Notifications
You must be signed in to change notification settings - Fork 303
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
Refactor syncInternalImpl and toZoneNetworkEndpointMap #2044
Refactor syncInternalImpl and toZoneNetworkEndpointMap #2044
Conversation
Hi @sawsa307. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @bowei |
pkg/neg/types/sync_results.go
Outdated
ResultInProgress = "InProgress" | ||
ResultSuccess = "Success" | ||
ResultNegNotFound = Result("NegNotFound") | ||
ResultCurrentEPNotFound = Result("CurrentEPNotFound") |
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.
you need to document the Results that aren't obvious.
What is the difference between CurrentEPNotFound and EPSNotFound
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.
CurrentEPNotFound means we cannot get existing endpoints from NEG, while EPSNotFound means we fail to get EPS for this service.
For documenting the results
, do you mean expand what's in the Result("...") or I should add it at a separate place?
pkg/neg/types/sync_results.go
Outdated
ResultEPSEndpointCountZero = Result("EPSEndpointCountZero") | ||
ResultEPCalculationCountZero = Result("EPCalculationCountZero") | ||
ResultInvalidAPIResponse = Result("InvalidAPIResponse") | ||
ResultInvalidEPAttach = Result("InvalidEPAttach") |
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.
Invalid or error
Invalid means we sent an invalid argument to the API, error means we got an error, which could include invalid.
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 should be invalid. Endpoint update API calls would fail if the endpoint list we send contains endpoints with invalid fields.
pkg/neg/syncers/utils.go
Outdated
zoneNetworkEndpointMap := map[string]negtypes.NetworkEndpointSet{} | ||
networkEndpointPodMap := negtypes.EndpointPodMap{} | ||
dupCount := 0 | ||
if eds == nil { | ||
klog.Errorf("Endpoint object is nil") | ||
return zoneNetworkEndpointMap, networkEndpointPodMap, dupCount, nil | ||
return negtypes.ZoneNetworkEndpointMapResult{ |
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.
You shouldn't put all the types into the types package. This is an antipattern.
Just keep the return type struct next to the function that returns the struct.
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'll update this. Thanks!
pkg/neg/syncers/utils.go
Outdated
@@ -246,24 +257,44 @@ func toZoneNetworkEndpointMap(eds []negtypes.EndpointsData, zoneGetter negtypes. | |||
|
|||
for _, endpointAddress := range ed.Addresses { | |||
if endpointAddress.AddressType != discovery.AddressTypeIPv4 { | |||
klog.Infof("Skipping non IPv4 address: %q, in endpoint slice %s/%s", endpointAddress.Addresses, ed.Meta.Namespace, ed.Meta.Name) | |||
klog.Infof("Skipping non IPv4 address: %q, in endpoint slice %s/%s", |
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.
Remove extra newline here to make your diff smaller.
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.
Understood. I'll update this.
pkg/neg/syncers/utils.go
Outdated
NetworkEndpointSet: zoneNetworkEndpointMap, | ||
EndpointPodMap: networkEndpointPodMap, | ||
DupCount: dupCount, | ||
Err: 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.
you should probably leave err out of the struct. That way we use the common pattern:
result, err := foo()
if err != nil {
// Do something, we expect result to be nil or an empty value.
}
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.
Please try to keep your code using standard, well understood patterns.
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.
Understood. I'll update this.
776bb3f
to
e01bdb7
Compare
6ce18fb
to
18b97bb
Compare
/assign @swetharepakula |
516181f
to
397f4f2
Compare
1e89da1
to
db38c4d
Compare
3eee300
to
b79ead5
Compare
@@ -176,16 +188,18 @@ type L7EndpointsCalculator struct { | |||
zoneGetter types.ZoneGetter | |||
servicePortName string | |||
podLister cache.Indexer | |||
nodeLister cache.Indexer |
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.
instead of the indexer, use the lister like in the L4 case.
not in this PR, but we should change the podLister to also be the lister instead of the indexer.
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.
Got it. I'll create a separate PR for that
@@ -440,17 +440,17 @@ func validatePod(pod *apiv1.Pod, nodeLister cache.Indexer) bool { | |||
// Terminal Pod means a pod is in PodFailed or PodSucceeded phase | |||
phase := pod.Status.Phase | |||
if phase == apiv1.PodFailed || phase == apiv1.PodSucceeded { | |||
klog.V(2).Info("Pod %s/%s is a terminal pod with status %v, skipping", pod.ObjectMeta.Namespace, pod.ObjectMeta.Name, phase) | |||
klog.V(2).Infof("Pod %s/%s is a terminal pod with status %v, skipping", pod.ObjectMeta.Namespace, pod.ObjectMeta.Name, phase) |
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.
these log lines still do not make sense in terms of this utility function. We can leave for a followup PR, but this should probably return an error or just the bool and allow the caller to make a decision about whether to skip or not.
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.
Agree. The decision about skipping should be left to the caller. I'll do it in a separate PR.
I think we already define some errors like ErrEPNodeNotFound
(endpoint corresponds to an non-existing node), but here we are checking node using Pod.
If I want to consolidate it and use one error for both endpoints and pods, how should I phrase my error message?
b79ead5
to
a016de7
Compare
consolidate service name and namespace since we would include addPodsToLister() in tests for syncInternalImpl, and addPodsToLister uses testServiceNamespace instead of TestNamespace, and change testService to testServiceName to match the behavior in getDefaultEndpointSlices().
8b3ca95
to
59f53dc
Compare
2f57f03
to
c5c9ee8
Compare
c5c9ee8
to
6450e61
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sawsa307, swetharepakula 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 |
Refactor syncInternalImpl, toZoneNetworkEndpointMap, and toZoneNetworkEndpointMapDegradedMode.