-
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
Filter pods that don't belong to the service in question #1966
Filter pods that don't belong to the service in question #1966
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 @swetharepakula |
pkg/neg/syncers/transaction.go
Outdated
if !isNode { | ||
return false | ||
} | ||
_, podCIDR, err := netset.ParseCIDRSloppy(node.Spec.PodCIDR) |
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 don't need to use the custom parsers, and is more complete if you iterate over all the PodCIDRs, you can add a helper for that
func nodeContainsPodIP(node *v1.Node, pod *v1.Pod) bool {
if node == nil || pod == nil {
return false
}
ipnets := []*net.IPNet{}
for _, podCIDR := range node.Spec.PodCIDRs {
podCIDR = strings.TrimSpace(podCIDR)
_, ipnet, err := net.ParseCIDR(podCIDR)
if err != nil {
// swallow errors for CIDRs that are invalid
continue
}
ipnets = append(ipnets, ipnet)
}
_, ipnet, err := net.ParseCIDR(node.Spec.PodCIDR)
if err == nil {
// swallow errors for CIDRs that are invalid
ipnets = append(ipnets, ipnet)
}
podIP := net.ParseIP(pod.Status.PodIP)
for _, net := range ipnets {
if net.Contains(podIP) {
return true
}
}
return false
}
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.
Yes I saw your comment in the other PR #1963, and I was about to address it there, but thank you for writing this out!
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.
since node.Spec.PodCIDR is guaranteed to be the zeroth entry in node.Spec.PodCIDRs, I think we can skip the check outside the loop
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.
since node.Spec.PodCIDR is guaranteed to be the zeroth entry in node.Spec.PodCIDRs
good catch
pkg/neg/syncers/transaction.go
Outdated
@@ -351,6 +352,21 @@ func (s *transactionSyncer) isValidPod(pod *apiv1.Pod) bool { | |||
if !podCIDR.Contains(podIP) { | |||
return false | |||
} | |||
podLabels := pod.ObjectMeta.Labels |
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.
hmm, how can we end in this situation?
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.
Hi Antonio, could you elaborate on which situation you are referring to?
If you are talking about a service has a pod, and this pod's label doesn't match the label selector of the service, it is indeed a case that is unlikely to happen, but we are doing this check to make sure if in the future, anything goes wrong in other part of code, NEG controller is still able to make correct decisions.
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.
fair enough, this should be like a panic kind of thing but we don't want to crash ...then just log it but I suggest to be verbose
log. "this can not happen, pod %s/%s labels %v doesn't match service %s/%s selector %v", pod.Namespace, pod.Name, pod.Labels, service.Namespace, service.Name, service.spec.Selector)
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.
Definitely! I'll add logging to this. Thank you!
/ok-to-test |
6bb7f21
to
a4605aa
Compare
a4605aa
to
e252bf1
Compare
/retest |
pkg/neg/syncers/utils.go
Outdated
return false | ||
} | ||
// for custom endpoint slice, we won't check the pod's labels | ||
if !isCustomEPS && !podBelongsToService(pod, service) { |
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.
refactor so continue if custom EPS
e252bf1
to
4d1964a
Compare
4d1964a
to
903ba31
Compare
97c1776
to
b96225c
Compare
b96225c
to
b473908
Compare
/retest |
646798b
to
3faf446
Compare
3faf446
to
08cba5e
Compare
daf13f4
to
f559eb4
Compare
pkg/neg/syncers/utils.go
Outdated
@@ -387,6 +387,8 @@ func toZoneNetworkEndpointMapDegradedMode(eds []negtypes.EndpointsData, zoneGett | |||
if len(matchPort) == 0 { | |||
continue | |||
} | |||
serviceName := ed.Meta.Labels[discovery.LabelServiceName] | |||
isCustomEPS := ed.Meta.Labels[discovery.LabelManagedBy] != "endpointslice-controller.k8s.io" |
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.
is there a constant we can use? otherwise define this as a constant
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 check and the only place we define this const is in endpoint slice controller repo as an not exported const, so I create one in this file.
pkg/neg/syncers/utils.go
Outdated
serviceLabels := service.Spec.Selector | ||
for key, val1 := range serviceLabels { | ||
if val2, contains := podLabels[key]; !contains || val1 != val2 { | ||
return fmt.Errorf("%w: pod %s has labels not match to its service %s's label selector", negtypes.ErrEPPodLabelMismatch, pod.Name, service.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.
Perhaps this as the msg instead: "%w: pod %s/%s has labels that do not match the service %s/%s's label selector"
Include the namespace for both the pod and service
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.
Updated. Thanks!
pkg/neg/syncers/utils_test.go
Outdated
@@ -2354,13 +2499,15 @@ func getTestEndpointSlices(name, namespace string) []*discovery.EndpointSlice { | |||
port81 := int32(81) | |||
port8081 := int32(8081) | |||
protocolTCP := v1.ProtocolTCP | |||
managedByController := "endpointslice-controller.k8s.io" |
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.
use a constant instead
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.
Updated. Thanks!
f559eb4
to
4ae2ec2
Compare
4ae2ec2
to
1e085ca
Compare
pkg/neg/syncers/utils.go
Outdated
|
||
// controllerName is a unique value used with LabelManagedBy to indicated | ||
// the EndpointSlice is managed by the endpoint slice controller. | ||
controllerName = "endpointslice-controller.k8s.io" |
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.
maybe managedByEPSControllerValue
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.
Updated. Thanks!
1e085ca
to
1228926
Compare
pkg/neg/syncers/utils.go
Outdated
@@ -48,6 +48,10 @@ const ( | |||
minRetryDelay = 5 * time.Second | |||
maxRetryDelay = 600 * time.Second | |||
separator = "||" | |||
|
|||
// managedByEPSControllerValue is a unique value used with LabelManagedBy to indicated |
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.
typo: to indicate
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.
Updated!
Filter pods that don't have labels match to its service label selector.
1228926
to
9c75049
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.
/lgtm
/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 |
Filter pods that don't have labels match to its service label selector.