mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
some manual fixes
This commit is contained in:
@@ -17,12 +17,13 @@ limitations under the License.
|
||||
package cloud
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/informers"
|
||||
@@ -448,7 +449,7 @@ func Test_NodesShutdown(t *testing.T) {
|
||||
}
|
||||
|
||||
func syncNodeStore(nodeinformer coreinformers.NodeInformer, f *testutil.FakeNodeHandler) error {
|
||||
nodes, err := f.List(metav1.ListOptions{})
|
||||
nodes, err := f.List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -733,11 +734,11 @@ func TestRemoveTaintOffNode(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
node, _ := test.nodeHandler.Get(test.nodeName, metav1.GetOptions{})
|
||||
node, _ := test.nodeHandler.Get(context.TODO(), test.nodeName, metav1.GetOptions{})
|
||||
err := RemoveTaintOffNode(test.nodeHandler, test.nodeName, node, test.taintsToRemove...)
|
||||
assert.NoError(t, err, "%s: RemoveTaintOffNode() error = %v", test.name, err)
|
||||
|
||||
node, _ = test.nodeHandler.Get(test.nodeName, metav1.GetOptions{})
|
||||
node, _ = test.nodeHandler.Get(context.TODO(), test.nodeName, metav1.GetOptions{})
|
||||
assert.EqualValues(t, test.expectedTaints, node.Spec.Taints,
|
||||
"%s: failed to remove taint off node: expected %+v, got %+v",
|
||||
test.name, test.expectedTaints, node.Spec.Taints)
|
||||
@@ -912,7 +913,7 @@ func TestAddOrUpdateTaintOnNode(t *testing.T) {
|
||||
err := AddOrUpdateTaintOnNode(test.nodeHandler, test.nodeName, test.taintsToAdd...)
|
||||
assert.NoError(t, err, "%s: AddOrUpdateTaintOnNode() error = %v", test.name, err)
|
||||
|
||||
node, _ := test.nodeHandler.Get(test.nodeName, metav1.GetOptions{})
|
||||
node, _ := test.nodeHandler.Get(context.TODO(), test.nodeName, metav1.GetOptions{})
|
||||
assert.EqualValues(t, test.expectedTaints, node.Spec.Taints,
|
||||
"%s: failed to add taint to node: expected %+v, got %+v",
|
||||
test.name, test.expectedTaints, node.Spec.Taints)
|
||||
|
||||
@@ -17,11 +17,12 @@ limitations under the License.
|
||||
package ipam
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/informers"
|
||||
@@ -306,7 +307,7 @@ func TestOccupyPreExistingCIDR(t *testing.T) {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
// Initialize the range allocator.
|
||||
fakeNodeInformer := getFakeNodeInformer(tc.fakeNodeHandler)
|
||||
nodeList, _ := tc.fakeNodeHandler.List(metav1.ListOptions{})
|
||||
nodeList, _ := tc.fakeNodeHandler.List(context.TODO(), metav1.ListOptions{})
|
||||
_, err := NewCIDRRangeAllocator(tc.fakeNodeHandler, fakeNodeInformer, tc.allocatorParams, nodeList)
|
||||
if err == nil && tc.ctrlCreateFail {
|
||||
t.Fatalf("creating range allocator was expected to fail, but it did not")
|
||||
|
||||
@@ -135,7 +135,7 @@ func (nc *nodeLifecycleController) syncLeaseStore(lease *coordv1.Lease) error {
|
||||
}
|
||||
|
||||
func (nc *nodeLifecycleController) syncNodeStore(fakeNodeHandler *testutil.FakeNodeHandler) error {
|
||||
nodes, err := fakeNodeHandler.List(metav1.ListOptions{})
|
||||
nodes, err := fakeNodeHandler.List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2740,7 +2740,7 @@ func TestApplyNoExecuteTaints(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
nodeController.doNoExecuteTaintingPass()
|
||||
node0, err := fakeNodeHandler.Get("node0", metav1.GetOptions{})
|
||||
node0, err := fakeNodeHandler.Get(context.TODO(), "node0", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Can't get current node0...")
|
||||
return
|
||||
@@ -2748,7 +2748,7 @@ func TestApplyNoExecuteTaints(t *testing.T) {
|
||||
if !taintutils.TaintExists(node0.Spec.Taints, UnreachableTaintTemplate) {
|
||||
t.Errorf("Can't find taint %v in %v", originalTaint, node0.Spec.Taints)
|
||||
}
|
||||
node2, err := fakeNodeHandler.Get("node2", metav1.GetOptions{})
|
||||
node2, err := fakeNodeHandler.Get(context.TODO(), "node2", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Can't get current node2...")
|
||||
return
|
||||
@@ -2759,7 +2759,7 @@ func TestApplyNoExecuteTaints(t *testing.T) {
|
||||
|
||||
// Make node3 healthy again.
|
||||
node2.Status = healthyNodeNewStatus
|
||||
_, err = fakeNodeHandler.UpdateStatus(node2)
|
||||
_, err = fakeNodeHandler.UpdateStatus(context.TODO(), node2)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
return
|
||||
@@ -2772,7 +2772,7 @@ func TestApplyNoExecuteTaints(t *testing.T) {
|
||||
}
|
||||
nodeController.doNoExecuteTaintingPass()
|
||||
|
||||
node2, err = fakeNodeHandler.Get("node2", metav1.GetOptions{})
|
||||
node2, err = fakeNodeHandler.Get(context.TODO(), "node2", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Can't get current node2...")
|
||||
return
|
||||
@@ -2886,12 +2886,12 @@ func TestSwapUnreachableNotReadyTaints(t *testing.T) {
|
||||
}
|
||||
nodeController.doNoExecuteTaintingPass()
|
||||
|
||||
node0, err := fakeNodeHandler.Get("node0", metav1.GetOptions{})
|
||||
node0, err := fakeNodeHandler.Get(context.TODO(), "node0", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Can't get current node0...")
|
||||
return
|
||||
}
|
||||
node1, err := fakeNodeHandler.Get("node1", metav1.GetOptions{})
|
||||
node1, err := fakeNodeHandler.Get(context.TODO(), "node1", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Can't get current node1...")
|
||||
return
|
||||
@@ -2905,12 +2905,12 @@ func TestSwapUnreachableNotReadyTaints(t *testing.T) {
|
||||
|
||||
node0.Status = newNodeStatus
|
||||
node1.Status = healthyNodeNewStatus
|
||||
_, err = fakeNodeHandler.UpdateStatus(node0)
|
||||
_, err = fakeNodeHandler.UpdateStatus(context.TODO(), node0)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
return
|
||||
}
|
||||
_, err = fakeNodeHandler.UpdateStatus(node1)
|
||||
_, err = fakeNodeHandler.UpdateStatus(context.TODO(), node1)
|
||||
if err != nil {
|
||||
t.Errorf(err.Error())
|
||||
return
|
||||
@@ -2924,7 +2924,7 @@ func TestSwapUnreachableNotReadyTaints(t *testing.T) {
|
||||
}
|
||||
nodeController.doNoExecuteTaintingPass()
|
||||
|
||||
node0, err = fakeNodeHandler.Get("node0", metav1.GetOptions{})
|
||||
node0, err = fakeNodeHandler.Get(context.TODO(), "node0", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Errorf("Can't get current node0...")
|
||||
return
|
||||
@@ -3120,7 +3120,7 @@ func TestTaintsNodeByCondition(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
fakeNodeHandler.Update(test.Node)
|
||||
fakeNodeHandler.Update(context.TODO(), test.Node)
|
||||
if err := nodeController.syncNodeStore(fakeNodeHandler); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -3331,7 +3331,7 @@ func TestReconcileNodeLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
fakeNodeHandler.Update(test.Node)
|
||||
fakeNodeHandler.Update(context.TODO(), test.Node)
|
||||
if err := nodeController.syncNodeStore(fakeNodeHandler); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
@@ -203,19 +203,19 @@ type conversionClient struct {
|
||||
v1client.ReplicationControllerInterface
|
||||
}
|
||||
|
||||
func (c conversionClient) Create(rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(c.ReplicationControllerInterface.Create, rs)
|
||||
func (c conversionClient) Create(ctx context.Context, rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(ctx, c.ReplicationControllerInterface.Create, rs)
|
||||
}
|
||||
|
||||
func (c conversionClient) Update(rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(c.ReplicationControllerInterface.Update, rs)
|
||||
func (c conversionClient) Update(ctx context.Context, rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(ctx, c.ReplicationControllerInterface.Update, rs)
|
||||
}
|
||||
|
||||
func (c conversionClient) UpdateStatus(rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(c.ReplicationControllerInterface.UpdateStatus, rs)
|
||||
func (c conversionClient) UpdateStatus(ctx context.Context, rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(ctx, c.ReplicationControllerInterface.UpdateStatus, rs)
|
||||
}
|
||||
|
||||
func (c conversionClient) Get(name string, options metav1.GetOptions) (*apps.ReplicaSet, error) {
|
||||
func (c conversionClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*apps.ReplicaSet, error) {
|
||||
rc, err := c.ReplicationControllerInterface.Get(context.TODO(), name, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -223,7 +223,7 @@ func (c conversionClient) Get(name string, options metav1.GetOptions) (*apps.Rep
|
||||
return convertRCtoRS(rc, nil)
|
||||
}
|
||||
|
||||
func (c conversionClient) List(opts metav1.ListOptions) (*apps.ReplicaSetList, error) {
|
||||
func (c conversionClient) List(ctx context.Context, opts metav1.ListOptions) (*apps.ReplicaSetList, error) {
|
||||
rcList, err := c.ReplicationControllerInterface.List(context.TODO(), opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -231,22 +231,22 @@ func (c conversionClient) List(opts metav1.ListOptions) (*apps.ReplicaSetList, e
|
||||
return convertList(rcList)
|
||||
}
|
||||
|
||||
func (c conversionClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
func (c conversionClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
||||
// This is not used by RSC because we wrap the shared informer instead.
|
||||
return nil, errors.New("Watch() is not implemented for conversionClient")
|
||||
}
|
||||
|
||||
func (c conversionClient) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *apps.ReplicaSet, err error) {
|
||||
func (c conversionClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, subresources ...string) (result *apps.ReplicaSet, err error) {
|
||||
// This is not used by RSC.
|
||||
return nil, errors.New("Patch() is not implemented for conversionClient")
|
||||
}
|
||||
|
||||
func (c conversionClient) GetScale(name string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) {
|
||||
func (c conversionClient) GetScale(ctx context.Context, name string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) {
|
||||
// This is not used by RSC.
|
||||
return nil, errors.New("GetScale() is not implemented for conversionClient")
|
||||
}
|
||||
|
||||
func (c conversionClient) UpdateScale(name string, scale *autoscalingv1.Scale) (result *autoscalingv1.Scale, err error) {
|
||||
func (c conversionClient) UpdateScale(ctx context.Context, name string, scale *autoscalingv1.Scale) (result *autoscalingv1.Scale, err error) {
|
||||
// This is not used by RSC.
|
||||
return nil, errors.New("UpdateScale() is not implemented for conversionClient")
|
||||
}
|
||||
@@ -275,12 +275,12 @@ func convertList(rcList *v1.ReplicationControllerList) (*apps.ReplicaSetList, er
|
||||
return rsList, nil
|
||||
}
|
||||
|
||||
func convertCall(fn func(*v1.ReplicationController) (*v1.ReplicationController, error), rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
func convertCall(ctx context.Context, fn func(context.Context, *v1.ReplicationController) (*v1.ReplicationController, error), rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
rc, err := convertRStoRC(rs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := fn(rc)
|
||||
result, err := fn(ctx, rc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -37,7 +38,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
ref "k8s.io/client-go/tools/reference"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
@@ -110,7 +111,7 @@ func (m *FakeLegacyHandler) Nodes() v1core.NodeInterface {
|
||||
}
|
||||
|
||||
// Create adds a new Node to the fake store.
|
||||
func (m *FakeNodeHandler) Create(node *v1.Node) (*v1.Node, error) {
|
||||
func (m *FakeNodeHandler) Create(_ context.Context, node *v1.Node) (*v1.Node, error) {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -130,7 +131,7 @@ func (m *FakeNodeHandler) Create(node *v1.Node) (*v1.Node, error) {
|
||||
}
|
||||
|
||||
// Get returns a Node from the fake store.
|
||||
func (m *FakeNodeHandler) Get(name string, opts metav1.GetOptions) (*v1.Node, error) {
|
||||
func (m *FakeNodeHandler) Get(_ context.Context, name string, opts metav1.GetOptions) (*v1.Node, error) {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -152,7 +153,7 @@ func (m *FakeNodeHandler) Get(name string, opts metav1.GetOptions) (*v1.Node, er
|
||||
}
|
||||
|
||||
// List returns a list of Nodes from the fake store.
|
||||
func (m *FakeNodeHandler) List(opts metav1.ListOptions) (*v1.NodeList, error) {
|
||||
func (m *FakeNodeHandler) List(_ context.Context, opts metav1.ListOptions) (*v1.NodeList, error) {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -182,7 +183,7 @@ func (m *FakeNodeHandler) List(opts metav1.ListOptions) (*v1.NodeList, error) {
|
||||
}
|
||||
|
||||
// Delete deletes a Node from the fake store.
|
||||
func (m *FakeNodeHandler) Delete(id string, opt *metav1.DeleteOptions) error {
|
||||
func (m *FakeNodeHandler) Delete(_ context.Context, id string, opt *metav1.DeleteOptions) error {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -196,12 +197,12 @@ func (m *FakeNodeHandler) Delete(id string, opt *metav1.DeleteOptions) error {
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of Nodes from the fake store.
|
||||
func (m *FakeNodeHandler) DeleteCollection(opt *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
func (m *FakeNodeHandler) DeleteCollection(_ context.Context, opt *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Update updates a Node in the fake store.
|
||||
func (m *FakeNodeHandler) Update(node *v1.Node) (*v1.Node, error) {
|
||||
func (m *FakeNodeHandler) Update(_ context.Context, node *v1.Node) (*v1.Node, error) {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -220,7 +221,7 @@ func (m *FakeNodeHandler) Update(node *v1.Node) (*v1.Node, error) {
|
||||
}
|
||||
|
||||
// UpdateStatus updates a status of a Node in the fake store.
|
||||
func (m *FakeNodeHandler) UpdateStatus(node *v1.Node) (*v1.Node, error) {
|
||||
func (m *FakeNodeHandler) UpdateStatus(_ context.Context, node *v1.Node) (*v1.Node, error) {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -263,18 +264,18 @@ func (m *FakeNodeHandler) UpdateStatus(node *v1.Node) (*v1.Node, error) {
|
||||
}
|
||||
|
||||
// PatchStatus patches a status of a Node in the fake store.
|
||||
func (m *FakeNodeHandler) PatchStatus(nodeName string, data []byte) (*v1.Node, error) {
|
||||
func (m *FakeNodeHandler) PatchStatus(ctx context.Context, nodeName string, data []byte) (*v1.Node, error) {
|
||||
m.RequestCount++
|
||||
return m.Patch(nodeName, types.StrategicMergePatchType, data, "status")
|
||||
return m.Patch(ctx, nodeName, types.StrategicMergePatchType, data, "status")
|
||||
}
|
||||
|
||||
// Watch watches Nodes in a fake store.
|
||||
func (m *FakeNodeHandler) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
func (m *FakeNodeHandler) Watch(_ context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
||||
return watch.NewFake(), nil
|
||||
}
|
||||
|
||||
// Patch patches a Node in the fake store.
|
||||
func (m *FakeNodeHandler) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Node, error) {
|
||||
func (m *FakeNodeHandler) Patch(_ context.Context, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Node, error) {
|
||||
m.lock.Lock()
|
||||
defer func() {
|
||||
m.RequestCount++
|
||||
@@ -476,7 +477,7 @@ func contains(node *v1.Node, nodes []*v1.Node) bool {
|
||||
|
||||
// GetZones returns list of zones for all Nodes stored in FakeNodeHandler
|
||||
func GetZones(nodeHandler *FakeNodeHandler) []string {
|
||||
nodes, _ := nodeHandler.List(metav1.ListOptions{})
|
||||
nodes, _ := nodeHandler.List(context.TODO(), metav1.ListOptions{})
|
||||
zones := sets.NewString()
|
||||
for _, node := range nodes.Items {
|
||||
zones.Insert(utilnode.GetZoneKey(&node))
|
||||
|
||||
Reference in New Issue
Block a user