generated: run refactor
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package replicationcontroller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
@@ -155,14 +156,14 @@ func createRCsPods(t *testing.T, clientSet clientset.Interface, rcs []*v1.Replic
|
||||
var createdRCs []*v1.ReplicationController
|
||||
var createdPods []*v1.Pod
|
||||
for _, rc := range rcs {
|
||||
createdRC, err := clientSet.CoreV1().ReplicationControllers(rc.Namespace).Create(rc)
|
||||
createdRC, err := clientSet.CoreV1().ReplicationControllers(rc.Namespace).Create(context.TODO(), rc)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create replication controller %s: %v", rc.Name, err)
|
||||
}
|
||||
createdRCs = append(createdRCs, createdRC)
|
||||
}
|
||||
for _, pod := range pods {
|
||||
createdPod, err := clientSet.CoreV1().Pods(pod.Namespace).Create(pod)
|
||||
createdPod, err := clientSet.CoreV1().Pods(pod.Namespace).Create(context.TODO(), pod)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create pod %s: %v", pod.Name, err)
|
||||
}
|
||||
@@ -176,7 +177,7 @@ func createRCsPods(t *testing.T, clientSet clientset.Interface, rcs []*v1.Replic
|
||||
func waitRCStable(t *testing.T, clientSet clientset.Interface, rc *v1.ReplicationController) {
|
||||
rcClient := clientSet.CoreV1().ReplicationControllers(rc.Namespace)
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newRC, err := rcClient.Get(rc.Name, metav1.GetOptions{})
|
||||
newRC, err := rcClient.Get(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -198,12 +199,12 @@ func scaleRC(t *testing.T, c clientset.Interface, rc *v1.ReplicationController,
|
||||
func updatePod(t *testing.T, podClient typedv1.PodInterface, podName string, updateFunc func(*v1.Pod)) *v1.Pod {
|
||||
var pod *v1.Pod
|
||||
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
|
||||
newPod, err := podClient.Get(podName, metav1.GetOptions{})
|
||||
newPod, err := podClient.Get(context.TODO(), podName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateFunc(newPod)
|
||||
pod, err = podClient.Update(newPod)
|
||||
pod, err = podClient.Update(context.TODO(), newPod)
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to update pod %s: %v", podName, err)
|
||||
@@ -213,12 +214,12 @@ func updatePod(t *testing.T, podClient typedv1.PodInterface, podName string, upd
|
||||
|
||||
func updatePodStatus(t *testing.T, podClient typedv1.PodInterface, pod *v1.Pod, updateStatusFunc func(*v1.Pod)) {
|
||||
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
|
||||
newPod, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
||||
newPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateStatusFunc(newPod)
|
||||
_, err = podClient.UpdateStatus(newPod)
|
||||
_, err = podClient.UpdateStatus(context.TODO(), newPod)
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to update status of pod %s: %v", pod.Name, err)
|
||||
@@ -228,7 +229,7 @@ func updatePodStatus(t *testing.T, podClient typedv1.PodInterface, pod *v1.Pod,
|
||||
func getPods(t *testing.T, podClient typedv1.PodInterface, labelMap map[string]string) *v1.PodList {
|
||||
podSelector := labels.Set(labelMap).AsSelector()
|
||||
options := metav1.ListOptions{LabelSelector: podSelector.String()}
|
||||
pods, err := podClient.List(options)
|
||||
pods, err := podClient.List(context.TODO(), options)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed obtaining a list of pods that match the pod labels %v: %v", labelMap, err)
|
||||
}
|
||||
@@ -238,12 +239,12 @@ func getPods(t *testing.T, podClient typedv1.PodInterface, labelMap map[string]s
|
||||
func updateRC(t *testing.T, rcClient typedv1.ReplicationControllerInterface, rcName string, updateFunc func(*v1.ReplicationController)) *v1.ReplicationController {
|
||||
var rc *v1.ReplicationController
|
||||
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
|
||||
newRC, err := rcClient.Get(rcName, metav1.GetOptions{})
|
||||
newRC, err := rcClient.Get(context.TODO(), rcName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateFunc(newRC)
|
||||
rc, err = rcClient.Update(newRC)
|
||||
rc, err = rcClient.Update(context.TODO(), newRC)
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to update rc %s: %v", rcName, err)
|
||||
@@ -260,7 +261,7 @@ func testPodControllerRefPatch(t *testing.T, c clientset.Interface, pod *v1.Pod,
|
||||
})
|
||||
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newPod, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
||||
newPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -269,7 +270,7 @@ func testPodControllerRefPatch(t *testing.T, c clientset.Interface, pod *v1.Pod,
|
||||
t.Fatalf("Failed to verify ControllerRef for the pod %s is not nil: %v", pod.Name, err)
|
||||
}
|
||||
|
||||
newPod, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
||||
newPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to obtain pod %s: %v", pod.Name, err)
|
||||
}
|
||||
@@ -307,7 +308,7 @@ func setPodsReadyCondition(t *testing.T, clientSet clientset.Interface, pods *v1
|
||||
}
|
||||
pod.Status.Conditions = append(pod.Status.Conditions, *condition)
|
||||
}
|
||||
_, err := clientSet.CoreV1().Pods(pod.Namespace).UpdateStatus(pod)
|
||||
_, err := clientSet.CoreV1().Pods(pod.Namespace).UpdateStatus(context.TODO(), pod)
|
||||
if err != nil {
|
||||
// When status fails to be updated, we continue to next pod
|
||||
continue
|
||||
@@ -324,11 +325,11 @@ func setPodsReadyCondition(t *testing.T, clientSet clientset.Interface, pods *v1
|
||||
func testScalingUsingScaleSubresource(t *testing.T, c clientset.Interface, rc *v1.ReplicationController, replicas int32) {
|
||||
ns := rc.Namespace
|
||||
rcClient := c.CoreV1().ReplicationControllers(ns)
|
||||
newRC, err := rcClient.Get(rc.Name, metav1.GetOptions{})
|
||||
newRC, err := rcClient.Get(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to obtain rc %s: %v", rc.Name, err)
|
||||
}
|
||||
scale, err := c.CoreV1().ReplicationControllers(ns).GetScale(rc.Name, metav1.GetOptions{})
|
||||
scale, err := c.CoreV1().ReplicationControllers(ns).GetScale(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to obtain scale subresource for rc %s: %v", rc.Name, err)
|
||||
}
|
||||
@@ -337,18 +338,18 @@ func testScalingUsingScaleSubresource(t *testing.T, c clientset.Interface, rc *v
|
||||
}
|
||||
|
||||
if err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
|
||||
scale, err := c.CoreV1().ReplicationControllers(ns).GetScale(rc.Name, metav1.GetOptions{})
|
||||
scale, err := c.CoreV1().ReplicationControllers(ns).GetScale(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scale.Spec.Replicas = replicas
|
||||
_, err = c.CoreV1().ReplicationControllers(ns).UpdateScale(rc.Name, scale)
|
||||
_, err = c.CoreV1().ReplicationControllers(ns).UpdateScale(context.TODO(), rc.Name, scale)
|
||||
return err
|
||||
}); err != nil {
|
||||
t.Fatalf("Failed to set .Spec.Replicas of scale subresource for rc %s: %v", rc.Name, err)
|
||||
}
|
||||
|
||||
newRC, err = rcClient.Get(rc.Name, metav1.GetOptions{})
|
||||
newRC, err = rcClient.Get(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to obtain rc %s: %v", rc.Name, err)
|
||||
}
|
||||
@@ -417,14 +418,14 @@ func TestAdoption(t *testing.T) {
|
||||
rcClient := clientSet.CoreV1().ReplicationControllers(ns.Name)
|
||||
podClient := clientSet.CoreV1().Pods(ns.Name)
|
||||
const rcName = "rc"
|
||||
rc, err := rcClient.Create(newRC(rcName, ns.Name, 1))
|
||||
rc, err := rcClient.Create(context.TODO(), newRC(rcName, ns.Name, 1))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create replication controllers: %v", err)
|
||||
}
|
||||
podName := fmt.Sprintf("pod%d", i)
|
||||
pod := newMatchingPod(podName, ns.Name)
|
||||
pod.OwnerReferences = tc.existingOwnerReferences(rc)
|
||||
_, err = podClient.Create(pod)
|
||||
_, err = podClient.Create(context.TODO(), pod)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create Pod: %v", err)
|
||||
}
|
||||
@@ -432,7 +433,7 @@ func TestAdoption(t *testing.T) {
|
||||
stopCh := runControllerAndInformers(t, rm, informers, 1)
|
||||
defer close(stopCh)
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
updatedPod, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
||||
updatedPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -483,7 +484,7 @@ func TestSpecReplicasChange(t *testing.T) {
|
||||
}
|
||||
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newRC, err := rcClient.Get(rc.Name, metav1.GetOptions{})
|
||||
newRC, err := rcClient.Get(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -519,7 +520,7 @@ func TestDeletingAndFailedPods(t *testing.T) {
|
||||
updatePod(t, podClient, deletingPod.Name, func(pod *v1.Pod) {
|
||||
pod.Finalizers = []string{"fake.example.com/blockDeletion"}
|
||||
})
|
||||
if err := c.CoreV1().Pods(ns.Name).Delete(deletingPod.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
if err := c.CoreV1().Pods(ns.Name).Delete(context.TODO(), deletingPod.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
t.Fatalf("Error deleting pod %s: %v", deletingPod.Name, err)
|
||||
}
|
||||
|
||||
@@ -583,7 +584,7 @@ func TestOverlappingRCs(t *testing.T) {
|
||||
|
||||
// Expect both RCs have .status.replicas = .spec.replicas
|
||||
for i := 0; i < 2; i++ {
|
||||
newRC, err := c.CoreV1().ReplicationControllers(ns.Name).Get(fmt.Sprintf("rc-%d", i+1), metav1.GetOptions{})
|
||||
newRC, err := c.CoreV1().ReplicationControllers(ns.Name).Get(context.TODO(), fmt.Sprintf("rc-%d", i+1), metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to obtain rc rc-%d: %v", i+1, err)
|
||||
}
|
||||
@@ -623,7 +624,7 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
pod.Labels = newLabelMap
|
||||
})
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newPod, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
||||
newPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -638,7 +639,7 @@ func TestPodOrphaningAndAdoptionWhenLabelsChange(t *testing.T) {
|
||||
pod.Labels = labelMap()
|
||||
})
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newPod, err := podClient.Get(pod.Name, metav1.GetOptions{})
|
||||
newPod, err := podClient.Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
// If the pod is not found, it means the RC picks the pod for deletion (it is extra)
|
||||
// Verify there is only one pod in namespace and it has ControllerRef to the RC
|
||||
@@ -743,7 +744,7 @@ func TestReadyAndAvailableReplicas(t *testing.T) {
|
||||
|
||||
rcClient := c.CoreV1().ReplicationControllers(ns.Name)
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newRC, err := rcClient.Get(rc.Name, metav1.GetOptions{})
|
||||
newRC, err := rcClient.Get(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -838,7 +839,7 @@ func TestFullyLabeledReplicas(t *testing.T) {
|
||||
|
||||
// Verify only one pod is fully labeled
|
||||
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
newRC, err := rcClient.Get(rc.Name, metav1.GetOptions{})
|
||||
newRC, err := rcClient.Get(context.TODO(), rc.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user