Skip to content

Commit

Permalink
Bump Lease Api to V1
Browse files Browse the repository at this point in the history
  • Loading branch information
palexster committed Jun 17, 2021
1 parent 878046e commit 22e12cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cmd/virtual-kubelet/root/root.go
Expand Up @@ -30,7 +30,7 @@ import (
"k8s.io/apimachinery/pkg/fields"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/kubernetes/typed/coordination/v1beta1"
coordv1 "k8s.io/client-go/kubernetes/typed/coordination/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
Expand Down Expand Up @@ -139,9 +139,9 @@ func runRootCommand(ctx context.Context, s *provider.Store, c *Opts) error {
return errors.Wrapf(err, "error initializing provider %s", c.Provider)
}

var leaseClient v1beta1.LeaseInterface
var leaseClient coordv1.LeaseInterface
if c.EnableNodeLease {
leaseClient = client.Client().CoordinationV1beta1().Leases(corev1.NamespaceNodeLease)
leaseClient = client.Client().CoordinationV1().Leases(corev1.NamespaceNodeLease)
}

advName := strings.Join([]string{virtualKubelet.AdvertisementPrefix, c.ForeignClusterId}, "")
Expand Down Expand Up @@ -177,7 +177,7 @@ func runRootCommand(ctx context.Context, s *provider.Store, c *Opts) error {
nodeProviderModule,
pNode,
client.Client().CoreV1().Nodes(),
module.WithNodeEnableLeaseV1Beta1(leaseClient, nil),
module.WithNodeEnableLeaseV1(leaseClient, nil),
module.WithNodeStatusUpdateErrorHandler(
func(ctx context.Context, err error) error {
klog.Info("node setting up")
Expand Down
14 changes: 7 additions & 7 deletions pkg/virtualKubelet/node/module/node.go
Expand Up @@ -24,13 +24,13 @@ import (
"k8s.io/klog/v2"

pkgerrors "github.com/pkg/errors"
coord "k8s.io/api/coordination/v1beta1"
coord "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/kubernetes/typed/coordination/v1beta1"
coordinationv1 "k8s.io/client-go/kubernetes/typed/coordination/v1"
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
)

Expand Down Expand Up @@ -76,7 +76,7 @@ func NewNodeController(p NodeProvider, node *corev1.Node, nodes v1.NodeInterface
// NodeControllerOpt are the functional options used for configuring a node.
type NodeControllerOpt func(*NodeController) error

// WithNodeEnableLeaseV1Beta1 enables support for v1beta1 leases.
// WithNodeEnableLeaseV1 enables support for v1beta1 leases.
// If client is nil, leases will not be enabled.
// If baseLease is nil, a default base lease will be used.
//
Expand All @@ -90,7 +90,7 @@ type NodeControllerOpt func(*NodeController) error
// - When node leases are enabled, node status updates are controlled by the
// node status update interval option.
// To set a custom node status update interval, see WithNodeStatusUpdateInterval().
func WithNodeEnableLeaseV1Beta1(client v1beta1.LeaseInterface, baseLease *coord.Lease) NodeControllerOpt {
func WithNodeEnableLeaseV1(client coordinationv1.LeaseInterface, baseLease *coord.Lease) NodeControllerOpt {
return func(n *NodeController) error {
n.leases = client
n.lease = baseLease
Expand Down Expand Up @@ -146,7 +146,7 @@ type NodeController struct {
p NodeProvider
n *corev1.Node

leases v1beta1.LeaseInterface
leases coordinationv1.LeaseInterface
nodes v1.NodeInterface

disableLease bool
Expand Down Expand Up @@ -353,7 +353,7 @@ func (n *NodeController) updateStatus(ctx context.Context, skipErrorCb bool) err
return nil
}

func ensureLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) {
func ensureLease(ctx context.Context, leases coordinationv1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) {
l, err := leases.Create(context.TODO(), lease, metav1.CreateOptions{})
if err != nil {
switch {
Expand All @@ -377,7 +377,7 @@ func ensureLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coor
// 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
// instead.
func updateNodeLease(ctx context.Context, leases v1beta1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) {
func updateNodeLease(ctx context.Context, leases coordinationv1.LeaseInterface, lease *coord.Lease) (*coord.Lease, error) {
l, err := leases.Update(context.TODO(), lease, metav1.UpdateOptions{})
if err != nil {
if errors.IsNotFound(err) {
Expand Down
10 changes: 5 additions & 5 deletions pkg/virtualKubelet/node/module/node_test.go
Expand Up @@ -22,7 +22,7 @@ import (

"gotest.tools/assert"
"gotest.tools/assert/cmp"
coord "k8s.io/api/coordination/v1beta1"
coord "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -44,15 +44,15 @@ func testNodeRun(t *testing.T, enableLease bool) {
testP := &testNodeProvider{NodeProvider: &NaiveNodeProvider{}}

nodes := c.CoreV1().Nodes()
leases := c.CoordinationV1beta1().Leases(corev1.NamespaceNodeLease)
leases := c.CoordinationV1().Leases(corev1.NamespaceNodeLease)

interval := 1 * time.Millisecond
opts := []NodeControllerOpt{
WithNodePingInterval(interval),
WithNodeStatusUpdateInterval(interval),
}
if enableLease {
opts = append(opts, WithNodeEnableLeaseV1Beta1(leases, nil))
opts = append(opts, WithNodeEnableLeaseV1(leases, nil))
}
testNode := testNode(t)
// We have to refer to testNodeCopy during the course of the test. testNode is modified by the node controller
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestNodeCustomUpdateStatusErrorHandler(t *testing.T) {
}

func TestEnsureLease(t *testing.T) {
c := testclient.NewSimpleClientset().CoordinationV1beta1().Leases(corev1.NamespaceNodeLease)
c := testclient.NewSimpleClientset().CoordinationV1().Leases(corev1.NamespaceNodeLease)
n := testNode(t)
ctx := context.Background()

Expand Down Expand Up @@ -280,7 +280,7 @@ func TestUpdateNodeStatus(t *testing.T) {
}

func TestUpdateNodeLease(t *testing.T) {
leases := testclient.NewSimpleClientset().CoordinationV1beta1().Leases(corev1.NamespaceNodeLease)
leases := testclient.NewSimpleClientset().CoordinationV1().Leases(corev1.NamespaceNodeLease)
lease := newLease(nil)
n := testNode(t)
setLeaseAttrs(lease, n, 0)
Expand Down

0 comments on commit 22e12cb

Please sign in to comment.