diff --git a/node/node.go b/node/node.go index b64b4e2c5..50d165b89 100644 --- a/node/node.go +++ b/node/node.go @@ -312,7 +312,7 @@ func (n *NodeController) handlePing(ctx context.Context) (retErr error) { } func (n *NodeController) updateLease(ctx context.Context) error { - l, err := UpdateNodeLease(ctx, n.leases, newLease(n.lease)) + l, err := updateNodeLease(ctx, n.leases, newLease(n.lease)) if err != nil { return err } @@ -324,7 +324,7 @@ func (n *NodeController) updateLease(ctx context.Context) error { func (n *NodeController) updateStatus(ctx context.Context, skipErrorCb bool) error { updateNodeStatusHeartbeat(n.n) - node, err := UpdateNodeStatus(ctx, n.nodes, n.n) + node, err := updateNodeStatus(ctx, n.nodes, n.n) if err != nil { if skipErrorCb || n.nodeStatusUpdateErrorHandler == nil { return err @@ -333,7 +333,7 @@ func (n *NodeController) updateStatus(ctx context.Context, skipErrorCb bool) err return err } - node, err = UpdateNodeStatus(ctx, n.nodes, n.n) + node, err = updateNodeStatus(ctx, n.nodes, n.n) if err != nil { return err } @@ -362,14 +362,12 @@ func ensureLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coor return l, err } -// UpdateNodeLease updates the node lease. +// updateNodeLease updates the node lease. // // If this function returns an errors.IsNotFound(err) error, this likely means -// that node leases are not supported, if this is the case, call UpdateNodeStatus +// that node leases are not supported, if this is the case, call updateNodeStatus // instead. -// -// If you use this function, it is up to you to syncronize this with other operations. -func UpdateNodeLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) { +func updateNodeLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) { ctx, span := trace.StartSpan(ctx, "node.UpdateNodeLease") defer span.End() @@ -403,9 +401,9 @@ func UpdateNodeLease(ctx context.Context, leases v1beta1.LeaseInterface, lease * // just so we don't have to allocate this on every get request var emptyGetOptions = metav1.GetOptions{} -// PatchNodeStatus patches node status. +// patchNodeStatus patches node status. // Copied from github.com/kubernetes/kubernetes/pkg/util/node -func PatchNodeStatus(nodes v1.NodeInterface, nodeName types.NodeName, oldNode *corev1.Node, newNode *corev1.Node) (*corev1.Node, []byte, error) { +func patchNodeStatus(nodes v1.NodeInterface, nodeName types.NodeName, oldNode *corev1.Node, newNode *corev1.Node) (*corev1.Node, []byte, error) { patchBytes, err := preparePatchBytesforNodeStatus(nodeName, oldNode, newNode) if err != nil { return nil, nil, err @@ -441,13 +439,13 @@ func preparePatchBytesforNodeStatus(nodeName types.NodeName, oldNode *corev1.Nod return patchBytes, nil } -// UpdateNodeStatus triggers an update to the node status in Kubernetes. +// updateNodeStatus triggers an update to the node status in Kubernetes. // It first fetches the current node details and then sets the status according // to the passed in node object. // // If you use this function, it is up to you to syncronize this with other operations. // This reduces the time to second-level precision. -func UpdateNodeStatus(ctx context.Context, nodes v1.NodeInterface, n *corev1.Node) (_ *corev1.Node, retErr error) { +func updateNodeStatus(ctx context.Context, nodes v1.NodeInterface, n *corev1.Node) (_ *corev1.Node, retErr error) { ctx, span := trace.StartSpan(ctx, "UpdateNodeStatus") defer func() { span.End() @@ -469,7 +467,7 @@ func UpdateNodeStatus(ctx context.Context, nodes v1.NodeInterface, n *corev1.Nod ctx = addNodeAttributes(ctx, span, node) // Patch the node status to merge other changes on the node. - updated, _, err := PatchNodeStatus(nodes, types.NodeName(n.Name), oldNode, node) + updated, _, err := patchNodeStatus(nodes, types.NodeName(n.Name), oldNode, node) if err != nil { return nil, err } diff --git a/node/node_test.go b/node/node_test.go index d31e6113a..d7ba849cc 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -242,20 +242,20 @@ func TestUpdateNodeStatus(t *testing.T) { nodes := testclient.NewSimpleClientset().CoreV1().Nodes() ctx := context.Background() - updated, err := UpdateNodeStatus(ctx, nodes, n.DeepCopy()) + updated, err := updateNodeStatus(ctx, nodes, n.DeepCopy()) assert.Equal(t, errors.IsNotFound(err), true, err) _, err = nodes.Create(n) assert.NilError(t, err) - updated, err = UpdateNodeStatus(ctx, nodes, n.DeepCopy()) + updated, err = updateNodeStatus(ctx, nodes, n.DeepCopy()) assert.NilError(t, err) assert.NilError(t, err) assert.Check(t, cmp.DeepEqual(n.Status, updated.Status)) n.Status.Phase = corev1.NodeRunning - updated, err = UpdateNodeStatus(ctx, nodes, n.DeepCopy()) + updated, err = updateNodeStatus(ctx, nodes, n.DeepCopy()) assert.NilError(t, err) assert.Check(t, cmp.DeepEqual(n.Status, updated.Status)) @@ -265,7 +265,7 @@ func TestUpdateNodeStatus(t *testing.T) { _, err = nodes.Get(n.Name, metav1.GetOptions{}) assert.Equal(t, errors.IsNotFound(err), true, err) - _, err = UpdateNodeStatus(ctx, nodes, updated.DeepCopy()) + _, err = updateNodeStatus(ctx, nodes, updated.DeepCopy()) assert.Equal(t, errors.IsNotFound(err), true, err) } @@ -276,7 +276,7 @@ func TestUpdateNodeLease(t *testing.T) { setLeaseAttrs(lease, n, 0) ctx := context.Background() - l, err := UpdateNodeLease(ctx, leases, lease) + l, err := updateNodeLease(ctx, leases, lease) assert.NilError(t, err) assert.Equal(t, l.Name, lease.Name) assert.Assert(t, cmp.DeepEqual(l.Spec.HolderIdentity, lease.Spec.HolderIdentity)) @@ -289,7 +289,7 @@ func TestUpdateNodeLease(t *testing.T) { l.Spec.RenewTime.Time = time.Now().Add(10 * time.Second) - compare, err = UpdateNodeLease(ctx, leases, l.DeepCopy()) + compare, err = updateNodeLease(ctx, leases, l.DeepCopy()) assert.NilError(t, err) assert.Equal(t, compare.Spec.RenewTime.Time.Unix(), l.Spec.RenewTime.Time.Unix()) assert.Equal(t, compare.Name, lease.Name)