Merge branch 'master' into jaeger_exporter_import
This commit is contained in:
24
doc.go
Normal file
24
doc.go
Normal file
@@ -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
|
||||||
4
errdefs/doc.go
Normal file
4
errdefs/doc.go
Normal file
@@ -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
|
||||||
24
node/node.go
24
node/node.go
@@ -312,7 +312,7 @@ func (n *NodeController) handlePing(ctx context.Context) (retErr error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *NodeController) updateLease(ctx context.Context) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -324,7 +324,7 @@ func (n *NodeController) updateLease(ctx context.Context) error {
|
|||||||
func (n *NodeController) updateStatus(ctx context.Context, skipErrorCb bool) error {
|
func (n *NodeController) updateStatus(ctx context.Context, skipErrorCb bool) error {
|
||||||
updateNodeStatusHeartbeat(n.n)
|
updateNodeStatusHeartbeat(n.n)
|
||||||
|
|
||||||
node, err := UpdateNodeStatus(ctx, n.nodes, n.n)
|
node, err := updateNodeStatus(ctx, n.nodes, n.n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if skipErrorCb || n.nodeStatusUpdateErrorHandler == nil {
|
if skipErrorCb || n.nodeStatusUpdateErrorHandler == nil {
|
||||||
return err
|
return err
|
||||||
@@ -333,7 +333,7 @@ func (n *NodeController) updateStatus(ctx context.Context, skipErrorCb bool) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err = UpdateNodeStatus(ctx, n.nodes, n.n)
|
node, err = updateNodeStatus(ctx, n.nodes, n.n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -362,14 +362,12 @@ func ensureLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coor
|
|||||||
return l, err
|
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
|
// 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.
|
// instead.
|
||||||
//
|
func updateNodeLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) {
|
||||||
// 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) {
|
|
||||||
ctx, span := trace.StartSpan(ctx, "node.UpdateNodeLease")
|
ctx, span := trace.StartSpan(ctx, "node.UpdateNodeLease")
|
||||||
defer span.End()
|
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
|
// just so we don't have to allocate this on every get request
|
||||||
var emptyGetOptions = metav1.GetOptions{}
|
var emptyGetOptions = metav1.GetOptions{}
|
||||||
|
|
||||||
// PatchNodeStatus patches node status.
|
// patchNodeStatus patches node status.
|
||||||
// Copied from github.com/kubernetes/kubernetes/pkg/util/node
|
// 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)
|
patchBytes, err := preparePatchBytesforNodeStatus(nodeName, oldNode, newNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@@ -441,13 +439,13 @@ func preparePatchBytesforNodeStatus(nodeName types.NodeName, oldNode *corev1.Nod
|
|||||||
return patchBytes, nil
|
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
|
// It first fetches the current node details and then sets the status according
|
||||||
// to the passed in node object.
|
// to the passed in node object.
|
||||||
//
|
//
|
||||||
// If you use this function, it is up to you to syncronize this with other operations.
|
// If you use this function, it is up to you to syncronize this with other operations.
|
||||||
// This reduces the time to second-level precision.
|
// 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")
|
ctx, span := trace.StartSpan(ctx, "UpdateNodeStatus")
|
||||||
defer func() {
|
defer func() {
|
||||||
span.End()
|
span.End()
|
||||||
@@ -469,7 +467,7 @@ func UpdateNodeStatus(ctx context.Context, nodes v1.NodeInterface, n *corev1.Nod
|
|||||||
ctx = addNodeAttributes(ctx, span, node)
|
ctx = addNodeAttributes(ctx, span, node)
|
||||||
|
|
||||||
// Patch the node status to merge other changes on the 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,20 +242,20 @@ func TestUpdateNodeStatus(t *testing.T) {
|
|||||||
nodes := testclient.NewSimpleClientset().CoreV1().Nodes()
|
nodes := testclient.NewSimpleClientset().CoreV1().Nodes()
|
||||||
|
|
||||||
ctx := context.Background()
|
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)
|
assert.Equal(t, errors.IsNotFound(err), true, err)
|
||||||
|
|
||||||
_, err = nodes.Create(n)
|
_, err = nodes.Create(n)
|
||||||
assert.NilError(t, err)
|
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.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Check(t, cmp.DeepEqual(n.Status, updated.Status))
|
assert.Check(t, cmp.DeepEqual(n.Status, updated.Status))
|
||||||
|
|
||||||
n.Status.Phase = corev1.NodeRunning
|
n.Status.Phase = corev1.NodeRunning
|
||||||
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))
|
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{})
|
_, err = nodes.Get(n.Name, metav1.GetOptions{})
|
||||||
assert.Equal(t, errors.IsNotFound(err), true, err)
|
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)
|
assert.Equal(t, errors.IsNotFound(err), true, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ func TestUpdateNodeLease(t *testing.T) {
|
|||||||
setLeaseAttrs(lease, n, 0)
|
setLeaseAttrs(lease, n, 0)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
l, err := UpdateNodeLease(ctx, leases, lease)
|
l, err := updateNodeLease(ctx, leases, lease)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
assert.Equal(t, l.Name, lease.Name)
|
assert.Equal(t, l.Name, lease.Name)
|
||||||
assert.Assert(t, cmp.DeepEqual(l.Spec.HolderIdentity, lease.Spec.HolderIdentity))
|
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)
|
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.NilError(t, err)
|
||||||
assert.Equal(t, compare.Spec.RenewTime.Time.Unix(), l.Spec.RenewTime.Time.Unix())
|
assert.Equal(t, compare.Spec.RenewTime.Time.Unix(), l.Spec.RenewTime.Time.Unix())
|
||||||
assert.Equal(t, compare.Name, lease.Name)
|
assert.Equal(t, compare.Name, lease.Name)
|
||||||
|
|||||||
Reference in New Issue
Block a user