From 8493cbb42ab8615fa424b12b34c1d8e4a868ec7b Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Fri, 5 Jul 2019 11:24:46 -0700 Subject: [PATCH 1/2] Unexport node update helper functions (#701) Thinking these maybe should either not be exposed or in a separate package. For 1.0 let's unexport them and we may re-introduce later. --- node/node.go | 24 +++++++++++------------- node/node_test.go | 12 ++++++------ 2 files changed, 17 insertions(+), 19 deletions(-) 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) From d3ff785e081537b4c9271a8e77795cbee73e371a Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Fri, 5 Jul 2019 14:42:56 -0700 Subject: [PATCH 2/2] Add godoc to the repo root. (#702) --- doc.go | 24 ++++++++++++++++++++++++ errdefs/doc.go | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 doc.go create mode 100644 errdefs/doc.go diff --git a/doc.go b/doc.go new file mode 100644 index 000000000..ab91877f2 --- /dev/null +++ b/doc.go @@ -0,0 +1,24 @@ +/* +Package virtualkubelet is currently just for providing docs for godoc. + +Virtual Kubelet is a project which aims to provide a library that can be +consumed by other projects to build a Kubernetes node agent that performs the +same basic role as the Kubelet, but fully customize the behavior. + +*Note*: Virtual Kubelet is not the Kubelet. + +All of the business logic for virtual-kubelet is in the `node` package. The +node package has controllers for managing the node in Kubernetes and running +scheduled pods against a backend service. The backend service along with the +code wrapping what is provided in the node package is what consumers of this +project would implement. In the interest of not duplicating examples, please +see that package on how to get started using virtual kubelet. + +Virtual Kubelet supports propgagation of logging and traces through a context. +See the "log" and "trace" packages for how to use this. + +Errors produced by and consumed from the node package are expected to conform to +error types defined in the "errdefs" package in order to be able to understand +the kind of failure that occurred and react accordingly. +*/ +package virtualkubelet diff --git a/errdefs/doc.go b/errdefs/doc.go new file mode 100644 index 000000000..e078f9096 --- /dev/null +++ b/errdefs/doc.go @@ -0,0 +1,4 @@ +// Package errdefs defines the error types that are understood by other packages +// in this project. Consumers of this project should look here to know how to +// produce and consume erors for this project. +package errdefs