-
Notifications
You must be signed in to change notification settings - Fork 42k
Update kubelet node status report logic with node lease feature #69753
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
Conversation
|
/kind feature |
|
/cc @kubernetes/sig-cluster-lifecycle-pr-reviews |
wojtek-t
left a comment
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.
Looks good overall - minor comments mostly.
pkg/kubelet/kubelet_node_status.go
Outdated
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.
if there is any change or enough time passed from the last sync, right?
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.
same below
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/kubelet/kubelet_node_status.go
Outdated
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.
if updatePodCIDR would fail, theoretically node could not change.
But I'm assuming in that case, it doesn't cost us much to report status anyway, so better to be on the safe side.
Maybe worth adding a comment?
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 changed the logic here. PTAL
pkg/kubelet/kubelet_node_status.go
Outdated
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.
In general I'm not a fan of reflection if it's possible to avoid that.
How about something like that:
if nodeConditionsHaveChanged(originalStatus.Conditions, status.Conditions) {
return true
}
originalConditions, conditions := originalStatus.Conditions. status.Conditions
originalStatus.Conditions = nil
status.Conditions = nil
defer func() {
originalStatus.Conditions = originalConditions
status.Conditions = conditions
}
return !apiequality.Semantic.DeepEqual(originalStatus, status)
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.
Just curious, why is reflection not preferred?
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.
reflection is really slow - this is the reason why we autogenerate a bunch of code
pkg/kubelet/kubelet_node_status.go
Outdated
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.
Aren't we generating conditions in the same deterministic order?
If so, maybe we can avoid sorting them?
@yujuhong - wdyt?
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.
Kubelet does generate node conditions in a deterministic order, but there are other components that could patch the node status (e.g., NPD).
To be safe, I think we should still sort the conditions.
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.
ok - sgtm. thanks
pkg/kubelet/kubelet_node_status.go
Outdated
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 the assignment of nodeHasChanged to itself intentional here?
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.
Good catch!
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 think the assignment happens after ||. Anyway, I changed the logic here, so the original if statement is obsolete.
|
/milestone v1.13 |
pkg/kubelet/kubelet_node_status.go
Outdated
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.
Why do you still need to compare here if one of them is nil? Am I missing something?...
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.
The full version is:
if originalStatus == nil && status == nil {
return false
} else if originalStatus == nil && status != nil {
return true
} else if originalStatus != nil && status == nil {
return true
}
So we still need the comparison here if we use a shorter version of code.
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.
It feels quite unnecessary to invoke apiequality.Semantic.DeepEqual to check for the special cases (one of them is nil). I'd probably go with the code below, but I'll leave the decision to you.
if originalStatus == nil && status == nil {
return false
}
if originalStatus == nil || status == nil {
return true
}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/kubelet/kubelet_node_status.go
Outdated
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.
Kubelet does generate node conditions in a deterministic order, but there are other components that could patch the node status (e.g., NPD).
To be safe, I think we should still sort the conditions.
pkg/kubelet/kubelet_node_status.go
Outdated
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.
Good catch!
4bebbe9 to
5bbc125
Compare
wangzhen127
left a comment
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. PTAL
pkg/kubelet/kubelet_node_status.go
Outdated
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/kubelet/kubelet_node_status.go
Outdated
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 changed the logic here. PTAL
pkg/kubelet/kubelet_node_status.go
Outdated
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 think the assignment happens after ||. Anyway, I changed the logic here, so the original if statement is obsolete.
pkg/kubelet/kubelet_node_status.go
Outdated
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.
The full version is:
if originalStatus == nil && status == nil {
return false
} else if originalStatus == nil && status != nil {
return true
} else if originalStatus != nil && status == nil {
return true
}
So we still need the comparison here if we use a shorter version of code.
pkg/kubelet/kubelet_node_status.go
Outdated
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.
Just curious, why is reflection not preferred?
pkg/kubelet/kubelet_network.go
Outdated
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.
Also note the change here. We need this return value to know if pod CIDR is actually changed or not.
5bbc125 to
3979ed6
Compare
wangzhen127
left a comment
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.
@liggitt, thanks for the review! I have updated the PR. PTAL
/test pull-kubernetes-node-e2e-alpha
/test pull-kubernetes-e2e-gce-alpha-features
pkg/kubelet/apis/config/types.go
Outdated
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.
Ah, I see your point. Updated the comments to make it more clear.
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.
The update frequency and report frequency are independent according to KEP-0009. For example, when node lease feature is enabled, I think it is possible that one use wants to override update frequency to 20s and still keep the default (1 min) report frequency. In such case, the user would just specify the update frequency and the report frequency should not derive from the update frequency.
/cc @wojtek-t
pkg/kubelet/kubelet_node_status.go
Outdated
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.
tryUpdateNodeStatus does not touch label. I don't think we need to check labels here. Also confirmed with @yujuhong offline.
pkg/kubelet/kubelet_node_status.go
Outdated
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.
The conditions are merged by keys, where the keys are the type: "patchStrategy:"merge" patchMergeKey:"type"". See
| Conditions []NodeCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,4,rep,name=conditions"` |
pkg/kubelet/kubelet_node_status.go
Outdated
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 is done every update frequency, i.e., once every 10 sec with default configuration. I updated it to use the copy now.
|
/retest |
2b8cad8 to
1d148d0
Compare
|
/test pull-kubernetes-node-e2e-alpha |
1d148d0 to
07b242a
Compare
|
I have updated /test pull-kubernetes-node-e2e-alpha |
|
/lgtm |
|
/approve |
liggitt
left a comment
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.
/approve
/hold
noted a few documentation issues, @wojtek-t can re-lgtm once those are resolved
pkg/kubelet/apis/config/types.go
Outdated
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.
nit: nodeStatusReportFrequency, as this value is used in documentation
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
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.
document the default uses the explicit nodeStatusUpdateFrequency value if provided, otherwise, 1m
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.
include the improved documentation about what happens if a status update is computed in this comment as well
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
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: liggitt, wangzhen127, wojtek-t, yujuhong The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
When node lease feature is enabled, kubelet reports node status to api server only if there is some change or it didn't report over last report interval.
07b242a to
98fc4a1
Compare
wangzhen127
left a comment
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 the documentation. PTAL.
pkg/kubelet/apis/config/types.go
Outdated
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
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
|
/test pull-kubernetes-node-e2e-alpha |
|
/lgtm |
|
/hold cancel |
|
/lgtm |
|
/retest |
| for i := range conditionsCopy { | ||
| originalConditionsCopy[i].LastHeartbeatTime = replacedheartbeatTime | ||
| conditionsCopy[i].LastHeartbeatTime = replacedheartbeatTime | ||
| if !apiequality.Semantic.DeepEqual(&originalConditionsCopy[i], &conditionsCopy[i]) { |
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.
how does this work if additional conditions got added or removed in the node ?
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.
It should just work, right?
| }, | ||
| status: &v1.NodeStatus{ | ||
| Conditions: []v1.NodeCondition{readyCondition, memoryPressureCondition}, | ||
| }, |
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 we add a UT for a condition getting removed. So original has 2 or 3 and current node status has less or removed ?
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.
Sure. Do you want to add one? I can help review. :)
What this PR does / why we need it:
When node lease feature is enabled, kubelet reports node status to api server only if there is some change or it didn't report over last report interval. This is part of KEP-0009, feature #589 and issue #14733.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
Release note: