This is an automated email from the ASF dual-hosted git repository.

wilfreds pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git


The following commit(s) were added to refs/heads/master by this push:
     new 7b08702f [YUNIKORN-2029] remove deprecated function (#688)
7b08702f is described below

commit 7b08702fb873018892a563f5a63cb6601182248d
Author: PoAn Yang <[email protected]>
AuthorDate: Wed Oct 18 18:22:44 2023 +1100

    [YUNIKORN-2029] remove deprecated function (#688)
    
    cleanup of deprecated functions in multiple packages
    * rand seed (go 1.20+ no longer needed)
    * ioutils (go 1.19)
    * K8s Poll & PollImmediate
    * ginkgo test description
    
    Signed-off-by: PoAn Yang <[email protected]>
    
    Closes: #688
    
    Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
 test/e2e/framework/helpers/common/utils.go         | 11 +++----
 test/e2e/framework/helpers/k8s/events.go           |  2 +-
 test/e2e/framework/helpers/k8s/k8s_utils.go        | 38 +++++++++++-----------
 .../framework/helpers/yunikorn/rest_api_utils.go   | 14 ++++----
 .../resource_fairness/resource_fairness_test.go    |  3 +-
 .../spark_jobs_scheduling_test.go                  |  3 +-
 .../drip_feed_schedule_test.go                     |  3 +-
 7 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/test/e2e/framework/helpers/common/utils.go 
b/test/e2e/framework/helpers/common/utils.go
index 022875c1..66c5c3f1 100644
--- a/test/e2e/framework/helpers/common/utils.go
+++ b/test/e2e/framework/helpers/common/utils.go
@@ -22,14 +22,12 @@ import (
        "bytes"
        "errors"
        "fmt"
-       "io/ioutil"
        "math/rand"
        "os"
        "os/exec"
        "path/filepath"
        "reflect"
        "strings"
-       "time"
 
        "github.com/google/uuid"
        "github.com/onsi/ginkgo/v2"
@@ -56,8 +54,8 @@ func GetAbsPath(p string) (string, error) {
 // GetTestName returns the test Name in a single string without spaces or /
 func GetTestName() string {
        //nolint
-       testDesc := ginkgo.CurrentGinkgoTestDescription()
-       name := strings.Replace(testDesc.FullTestText, " ", "_", -1)
+       testReport := ginkgo.CurrentSpecReport()
+       name := strings.ReplaceAll(testReport.FullText(), " ", "_")
        name = strings.Trim(name, "*")
        return strings.Replace(name, "/", "-", -1)
 }
@@ -101,12 +99,12 @@ func CreateLogFile(filename string, data []byte) error {
        }
 
        finalPath := filepath.Join(path, filename)
-       err = ioutil.WriteFile(finalPath, data, configmanager.LogPerm)
+       err = os.WriteFile(finalPath, data, configmanager.LogPerm)
        return err
 }
 
 func GetFileContents(filename string) ([]byte, error) {
-       data, err := ioutil.ReadFile(filename)
+       data, err := os.ReadFile(filename)
        return data, err
 }
 
@@ -116,7 +114,6 @@ func GetUUID() string {
 
 func RandSeq(n int) string {
        var letters = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
-       rand.Seed(time.Now().UnixNano())
        b := make([]rune, n)
        for i := range b {
                b[i] = letters[rand.Intn(len(letters))]
diff --git a/test/e2e/framework/helpers/k8s/events.go 
b/test/e2e/framework/helpers/k8s/events.go
index e8a5c454..06940f53 100644
--- a/test/e2e/framework/helpers/k8s/events.go
+++ b/test/e2e/framework/helpers/k8s/events.go
@@ -107,7 +107,7 @@ func ObserveEventAfterAction(c clientset.Interface, ns 
string, eventPredicate fu
        // Wait up 2 minutes polling every second.
        timeout := 2 * time.Minute
        interval := 1 * time.Second
-       err = wait.Poll(interval, timeout, func() (bool, error) {
+       err = wait.PollUntilContextTimeout(context.TODO(), interval, timeout, 
false, func(context.Context) (bool, error) {
                return observedMatchingEvent, nil
        })
        return err == nil, err
diff --git a/test/e2e/framework/helpers/k8s/k8s_utils.go 
b/test/e2e/framework/helpers/k8s/k8s_utils.go
index 6070d477..742a580b 100644
--- a/test/e2e/framework/helpers/k8s/k8s_utils.go
+++ b/test/e2e/framework/helpers/k8s/k8s_utils.go
@@ -361,7 +361,7 @@ func (k *KubeCtl) UpdateNamespace(namespace string, 
annotations map[string]strin
 }
 
 func (k *KubeCtl) WaitForServiceAccountPresent(namespace string, svcAcctName 
string, timeout time.Duration) error {
-       return wait.PollImmediate(time.Second, timeout, 
k.isServiceAccountPresent(namespace, svcAcctName))
+       return wait.PollUntilContextTimeout(context.TODO(), time.Second, 
timeout, false, k.isServiceAccountPresent(namespace, svcAcctName).WithContext())
 }
 
 func (k *KubeCtl) isServiceAccountPresent(namespace string, svcAcctName 
string) wait.ConditionFunc {
@@ -720,47 +720,47 @@ func (k *KubeCtl) isNumPod(namespace string, wanted int) 
wait.ConditionFunc {
 }
 
 func (k *KubeCtl) WaitForJobPods(namespace string, jobName string, numPods 
int, timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isNumJobPodsInDesiredState(jobName, namespace, numPods, v1.PodRunning))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isNumJobPodsInDesiredState(jobName, 
namespace, numPods, v1.PodRunning).WithContext())
 }
 func (k *KubeCtl) WaitForPodEvent(namespace string, podName string, 
expectedReason string, timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodEventTriggered(namespace, podName, expectedReason))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodEventTriggered(namespace, podName, 
expectedReason).WithContext())
 }
 
 func (k *KubeCtl) WaitForPodTerminated(namespace string, podName string, 
timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodNotInNS(podName, namespace))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodNotInNS(podName, 
namespace).WithContext())
 }
 
 func (k *KubeCtl) WaitForJobTerminated(namespace string, jobName string, 
timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isJobNotInNS(jobName, namespace))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isJobNotInNS(jobName, 
namespace).WithContext())
 }
 
 // Poll up to timeout seconds for pod to enter running state.
 // Returns an error if the pod never enters the running state.
 func (k *KubeCtl) WaitForPodRunning(namespace string, podName string, timeout 
time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodInDesiredState(podName, namespace, v1.PodRunning))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodInDesiredState(podName, namespace, 
v1.PodRunning).WithContext())
 }
 
 func (k *KubeCtl) WaitForPodPending(namespace string, podName string, timeout 
time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodInDesiredState(podName, namespace, v1.PodPending))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodInDesiredState(podName, namespace, 
v1.PodPending).WithContext())
 }
 
 func (k *KubeCtl) WaitForPodSucceeded(namespace string, podName string, 
timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodInDesiredState(podName, namespace, v1.PodSucceeded))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodInDesiredState(podName, namespace, 
v1.PodSucceeded).WithContext())
 }
 
 func (k *KubeCtl) WaitForPodFailed(namespace string, podName string, timeout 
time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodInDesiredState(podName, namespace, v1.PodFailed))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodInDesiredState(podName, namespace, 
v1.PodFailed).WithContext())
 }
 
 func (k *KubeCtl) WaitForPodCount(namespace string, wanted int, timeout 
time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isNumPod(namespace, wanted))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isNumPod(namespace, 
wanted).WithContext())
 }
 
 func (k *KubeCtl) WaitForPodStateStable(namespace string, podName string, 
timeout time.Duration) (error, v1.PodPhase) {
        var lastPhase v1.PodPhase
        samePhases := 0
 
-       err := wait.PollImmediate(time.Second, timeout, 
k.isPodStable(namespace, podName, &samePhases, 3, &lastPhase))
+       err := wait.PollUntilContextTimeout(context.TODO(), time.Second, 
timeout, false, k.isPodStable(namespace, podName, &samePhases, 3, 
&lastPhase).WithContext())
        return err, lastPhase
 }
 
@@ -818,7 +818,7 @@ func (k *KubeCtl) WaitForPodBySelectorRunning(namespace 
string, selector string,
 
 // Wait up to timeout seconds for a pod in 'namespace' with given 'selector' 
to exist
 func (k *KubeCtl) WaitForPodBySelector(namespace string, selector string, 
timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isPodSelectorInNs(selector, namespace))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isPodSelectorInNs(selector, 
namespace).WithContext())
 }
 
 func (k *KubeCtl) CreateSecret(secret *v1.Secret, namespace string) 
(*v1.Secret, error) {
@@ -920,7 +920,7 @@ func (k *KubeCtl) PodScheduled(podNamespace, podName 
string) wait.ConditionFunc
 }
 
 func (k *KubeCtl) WaitForPodScheduled(namespace string, podName string, 
timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.PodScheduled(namespace, podName))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.PodScheduled(namespace, 
podName).WithContext())
 }
 
 // PodUnschedulable returns a condition function that returns true if the 
given pod
@@ -941,7 +941,7 @@ func (k *KubeCtl) PodUnschedulable(podNamespace, podName 
string) wait.ConditionF
 // WaitForPodUnschedulable waits for a pod to fail scheduling and returns
 // an error if it does not become unschedulable within the given timeout.
 func (k *KubeCtl) WaitForPodUnschedulable(pod *v1.Pod, timeout time.Duration) 
error {
-       return wait.PollImmediate(100*time.Millisecond, timeout, 
k.PodUnschedulable(pod.Namespace, pod.Name))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.PodUnschedulable(pod.Namespace, 
pod.Name).WithContext())
 }
 
 func (k *KubeCtl) CreatePriorityClass(pc *schedulingv1.PriorityClass) 
(*schedulingv1.PriorityClass, error) {
@@ -957,19 +957,19 @@ func (k *KubeCtl) CreateJob(job *batchv1.Job, namespace 
string) (*batchv1.Job, e
 }
 
 func (k *KubeCtl) WaitForJobPodsCreated(namespace string, jobName string, 
numPods int, timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isNumJobPodsCreated(jobName, namespace, numPods))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isNumJobPodsCreated(jobName, namespace, 
numPods).WithContext())
 }
 
 func (k *KubeCtl) WaitForJobPodsRunning(namespace string, jobName string, 
numPods int, timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isNumJobPodsInDesiredState(jobName, namespace, numPods, v1.PodRunning))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isNumJobPodsInDesiredState(jobName, 
namespace, numPods, v1.PodRunning).WithContext())
 }
 
 func (k *KubeCtl) WaitForJobPodsSucceeded(namespace string, jobName string, 
numPods int, timeout time.Duration) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isNumJobPodsInDesiredState(jobName, namespace, numPods, v1.PodSucceeded))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isNumJobPodsInDesiredState(jobName, 
namespace, numPods, v1.PodSucceeded).WithContext())
 }
 
 func (k *KubeCtl) WaitForPlaceholders(namespace string, podPrefix string, 
numPods int, timeout time.Duration, podPhase *v1.PodPhase) error {
-       return wait.PollImmediate(time.Millisecond*100, timeout, 
k.isNumPlaceholdersRunning(namespace, podPrefix, numPods, podPhase))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, timeout, false, k.isNumPlaceholdersRunning(namespace, 
podPrefix, numPods, podPhase).WithContext())
 }
 
 func (k *KubeCtl) ListPlaceholders(namespace string, podPrefix string) 
([]v1.Pod, error) {
@@ -991,7 +991,7 @@ func (k *KubeCtl) ListPlaceholders(namespace string, 
podPrefix string) ([]v1.Pod
 func (k *KubeCtl) WaitForPlaceholdersStableState(namespace string, podPrefix 
string, timeout time.Duration) error {
        samePhases := 0
        podPhases := make(map[string]v1.PodPhase)
-       return wait.PollImmediate(time.Second, timeout, 
k.arePlaceholdersStable(namespace, podPrefix, &samePhases, 3, podPhases))
+       return wait.PollUntilContextTimeout(context.TODO(), time.Second, 
timeout, false, k.arePlaceholdersStable(namespace, podPrefix, &samePhases, 3, 
podPhases).WithContext())
 }
 
 func (k *KubeCtl) isNumPlaceholdersRunning(namespace string, podPrefix string, 
num int, podPhase *v1.PodPhase) wait.ConditionFunc {
diff --git a/test/e2e/framework/helpers/yunikorn/rest_api_utils.go 
b/test/e2e/framework/helpers/yunikorn/rest_api_utils.go
index 26289dff..3487e810 100644
--- a/test/e2e/framework/helpers/yunikorn/rest_api_utils.go
+++ b/test/e2e/framework/helpers/yunikorn/rest_api_utils.go
@@ -20,6 +20,7 @@ package yunikorn
 
 import (
        "bytes"
+       "context"
        "encoding/json"
        "errors"
        "fmt"
@@ -107,10 +108,7 @@ func (c *RClient) GetHealthCheck() 
(dao.SchedulerHealthDAOInfo, error) {
 }
 
 func (c *RClient) WaitforQueueToAppear(partition string, queueName string, 
timeout int) error {
-       if err := wait.PollImmediate(300*time.Millisecond, 
time.Duration(timeout)*time.Second, c.IsQueuePresent(partition, queueName)); 
err != nil {
-               return err
-       }
-       return nil
+       return wait.PollUntilContextTimeout(context.TODO(), 
300*time.Microsecond, time.Duration(timeout)*time.Second, false, 
c.IsQueuePresent(partition, queueName).WithContext())
 }
 
 func (c *RClient) IsQueuePresent(partition string, queueName string) 
wait.ConditionFunc {
@@ -198,7 +196,7 @@ func (c *RClient) isAllocLogPresent(partition string, 
queueName string, appID st
 }
 
 func (c *RClient) WaitForAllocationLog(partition string, queueName string, 
appID string, podName string, timeout int) error {
-       if err := wait.PollImmediate(time.Second, 
time.Duration(timeout)*time.Second, c.isAllocLogPresent(partition, queueName, 
appID, podName)); err != nil {
+       if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, 
time.Duration(timeout)*time.Second, false, c.isAllocLogPresent(partition, 
queueName, appID, podName).WithContext()); err != nil {
                return err
        }
 
@@ -234,7 +232,7 @@ func (c *RClient) GetNodes(partition string) 
(*[]dao.NodeDAOInfo, error) {
 }
 
 func (c *RClient) WaitForAppStateTransition(partition string, queue string, 
appID string, state string, timeout int) error {
-       return wait.PollImmediate(time.Millisecond*300, 
time.Duration(timeout)*time.Second, c.isAppInDesiredState(partition, queue, 
appID, state))
+       return wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*300, time.Duration(timeout)*time.Second, false, 
c.isAppInDesiredState(partition, queue, appID, state).WithContext())
 }
 
 func (c *RClient) AreAllExecPodsAllotted(partition string, queueName string, 
appID string, execPodCount int) wait.ConditionFunc {
@@ -285,7 +283,7 @@ func isRootSched(policy string) wait.ConditionFunc {
 }
 
 func WaitForSchedPolicy(policy string, timeout time.Duration) error {
-       return wait.PollImmediate(2*time.Second, timeout, isRootSched(policy))
+       return wait.PollUntilContextTimeout(context.TODO(), 2*time.Second, 
timeout, false, isRootSched(policy).WithContext())
 }
 
 func GetFailedHealthChecks() (string, error) {
@@ -339,7 +337,7 @@ func compareQueueTS(queuePathStr string, ts string) 
wait.ConditionFunc {
 
 // Expects queuePath to use periods as delimiters. ie "root.queueA.child"
 func WaitForQueueTS(queuePathStr string, ts string, timeout time.Duration) 
error {
-       return wait.PollImmediate(2*time.Second, timeout, 
compareQueueTS(queuePathStr, ts))
+       return wait.PollUntilContextTimeout(context.TODO(), 2*time.Second, 
timeout, false, compareQueueTS(queuePathStr, ts).WithContext())
 }
 
 func AllocLogToStrings(log []*dao.AllocationAskLogDAOInfo) []string {
diff --git a/test/e2e/resource_fairness/resource_fairness_test.go 
b/test/e2e/resource_fairness/resource_fairness_test.go
index fff4104e..b846dd25 100644
--- a/test/e2e/resource_fairness/resource_fairness_test.go
+++ b/test/e2e/resource_fairness/resource_fairness_test.go
@@ -19,6 +19,7 @@
 package resourcefairness_test
 
 import (
+       "context"
        "fmt"
        "math/rand"
        "time"
@@ -153,7 +154,7 @@ var _ = Describe("FairScheduling:", func() {
                        Ω(err).NotTo(HaveOccurred())
 
                        // Wait till requests has been added to application
-                       err := wait.PollImmediate(300*time.Millisecond, 
60*time.Second, func() (bool, error) {
+                       err := wait.PollUntilContextTimeout(context.TODO(), 
300*time.Millisecond, 60*time.Second, false, func(context.Context) (bool, 
error) {
                                app, err := restClient.GetAppInfo("default", 
queuePath, appID)
                                if err != nil {
                                        return false, nil
diff --git a/test/e2e/spark_jobs_scheduling/spark_jobs_scheduling_test.go 
b/test/e2e/spark_jobs_scheduling/spark_jobs_scheduling_test.go
index 24efb46e..375e9f9a 100644
--- a/test/e2e/spark_jobs_scheduling/spark_jobs_scheduling_test.go
+++ b/test/e2e/spark_jobs_scheduling/spark_jobs_scheduling_test.go
@@ -19,6 +19,7 @@
 package spark_jobs_scheduling
 
 import (
+       "context"
        "fmt"
        "net/url"
        "os"
@@ -117,7 +118,7 @@ var _ = Describe("", func() {
                By(fmt.Sprintf("Get apps from specific queue: %s", sparkNS))
                var appsFromQueue []*dao.ApplicationDAOInfo
                // Poll for apps to appear in the queue
-               err = wait.PollImmediate(time.Millisecond*100, 
time.Duration(120)*time.Second, func() (done bool, err error) {
+               err = wait.PollUntilContextTimeout(context.TODO(), 
time.Millisecond*100, time.Duration(120)*time.Second, false, 
func(context.Context) (done bool, err error) {
                        appsFromQueue, err = 
restClient.GetApps(configmanager.DefaultPartition, 
configmanager.RootQueue+"."+sparkNS)
                        if len(appsFromQueue) == 3 {
                                return true, nil
diff --git a/test/e2e/state_aware_app_scheduling/drip_feed_schedule_test.go 
b/test/e2e/state_aware_app_scheduling/drip_feed_schedule_test.go
index 2a479fdc..49d5719d 100644
--- a/test/e2e/state_aware_app_scheduling/drip_feed_schedule_test.go
+++ b/test/e2e/state_aware_app_scheduling/drip_feed_schedule_test.go
@@ -19,6 +19,7 @@
 package stateawareappscheduling_test
 
 import (
+       "context"
        "fmt"
        "time"
 
@@ -72,7 +73,7 @@ var _ = Describe("DripFeedSchedule:", func() {
                By(fmt.Sprintf("Get apps from specific queue: %s", ns))
                var appsFromQueue []*dao.ApplicationDAOInfo
                // Poll for apps to appear in the queue
-               err = wait.PollImmediate(time.Second, 
time.Duration(60)*time.Second, func() (done bool, err error) {
+               err = wait.PollUntilContextTimeout(context.TODO(), time.Second, 
time.Duration(60)*time.Second, false, func(context.Context) (done bool, err 
error) {
                        appsFromQueue, err = restClient.GetApps("default", 
"root."+ns)
                        if len(appsFromQueue) == 3 {
                                return true, nil


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to