Patch the node status instead of updating it. (#557)

* Patch the node status instead of updating it.

Virtual-kubelet updates the node status periodically.
This change proposes we use the `Patch` API instead of `Update`,
to update the node status.
This avoids overwriting any node updates made by other controllers
in the system, for example a attach-detach controller.
Patch API does a strategic merge instead of overwriting
the entire object, which ensures parallel updates don't overwrite
each other.

Note: `PatchNodeStatus` reduces the time precision to the seconds-level
and therefore I corrected the test for this.

consider two controllers:
CONTROLLER 1 (virtual kubelet)                       | CONTROLLER 2
oldNode := nodes.Get(nodename)                       |
                                                     | node := nodes.Get(nodename)
                                                     | // update status with attached volumes info
                                                     | updateNode := Nodes.UpdateStatus(node)
// update vkubelet info on node status               |
latestNode := Nodes.UpdateStatus(oldNode)            |
<-- latestNode does not contain the volume info added by second controller.

with my patch change:

CONTROLLER 1 (virtual kubelet)                       | CONTROLLER 2
oldNode := Nodes.Get(nodename)                       |
                                                     | node := Nodes.Get(nodename)
                                                     | // update status with attached volumes info
                                                     | updateNode := Nodes.UpdateStatus(node)
node := oldNode.DeepCopy()                           |
// update vkubelet info on node status               |
latestNode := util.PatchNodeStatus(oldNode, node)    |
<-- latestNode contains the volume info added by second controller.

Testing Done: make test

* Introduce PatchNodeStatus into vkubelet.

* Pass only the node interface.
This commit is contained in:
Yash Desai
2019-04-03 10:40:57 -07:00
committed by Brian Goff
parent bab9c59ac8
commit 85292ef4ef
3 changed files with 54 additions and 6 deletions

View File

@@ -111,7 +111,7 @@ func testNodeRun(t *testing.T, enableLease bool) {
n := node.n.DeepCopy()
newCondition := corev1.NodeCondition{
Type: corev1.NodeConditionType("UPDATED"),
LastTransitionTime: metav1.NewTime(time.Now()),
LastTransitionTime: metav1.Now().Rfc3339Copy(),
}
n.Status.Conditions = append(n.Status.Conditions, newCondition)
@@ -170,7 +170,7 @@ func TestEnsureLease(t *testing.T) {
func TestUpdateNodeStatus(t *testing.T) {
n := testNode(t)
n.Status.Conditions = append(n.Status.Conditions, corev1.NodeCondition{
LastHeartbeatTime: metav1.NewTime(time.Now()),
LastHeartbeatTime: metav1.Now().Rfc3339Copy(),
})
n.Status.Phase = corev1.NodePending
nodes := testclient.NewSimpleClientset().CoreV1().Nodes()