Skip to content

Commit d86fa40

Browse files
committed
Restructure WaitForNodesWithResource function
Signed-off-by: Tuomas Katila <[email protected]>
1 parent cfbf82c commit d86fa40

File tree

10 files changed

+31
-30
lines changed

10 files changed

+31
-30
lines changed

test/e2e/dlb/dlb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func describe() {
8484
ginkgo.Context("When PF resources are available [Resource:pf]", func() {
8585
ginkgo.BeforeEach(func(ctx context.Context) {
8686
resource := v1.ResourceName("dlb.intel.com/pf")
87-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resource, 30*time.Second, utils.WaitOpGreater); err != nil {
87+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resource, 30*time.Second, utils.WaitForPositiveResource); err != nil {
8888
framework.Failf("unable to wait for nodes to have positive allocatable resource %s: %v", resource, err)
8989
}
9090
})
@@ -101,7 +101,7 @@ func describe() {
101101
ginkgo.Context("When VF resources are available [Resource:vf]", func() {
102102
ginkgo.BeforeEach(func(ctx context.Context) {
103103
resource := v1.ResourceName("dlb.intel.com/vf")
104-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resource, 30*time.Second, utils.WaitOpGreater); err != nil {
104+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resource, 30*time.Second, utils.WaitForPositiveResource); err != nil {
105105
framework.Failf("unable to wait for nodes to have positive allocatable resource %s: %v", resource, err)
106106
}
107107
})

test/e2e/dsa/dsa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func describe() {
9797
ginkgo.Context("When DSA resources are available [Resource:dedicated]", func() {
9898
ginkgo.BeforeEach(func(ctx context.Context) {
9999
ginkgo.By("checking if the resource is allocatable")
100-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "dsa.intel.com/wq-user-dedicated", 300*time.Second, utils.WaitOpGreater); err != nil {
100+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "dsa.intel.com/wq-user-dedicated", 300*time.Second, utils.WaitForPositiveResource); err != nil {
101101
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
102102
}
103103
})

test/e2e/fpga/fpga.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func runDevicePlugin(ctx context.Context, fmw *framework.Framework, pluginKustom
129129

130130
ginkgo.By("checking if the resource is allocatable")
131131

132-
if err = utils.WaitForNodesWithResource(ctx, fmw.ClientSet, resource, 30*time.Second, utils.WaitOpGreater); err != nil {
132+
if err = utils.WaitForNodesWithResource(ctx, fmw.ClientSet, resource, 30*time.Second, utils.WaitForPositiveResource); err != nil {
133133
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
134134
}
135135
}

test/e2e/gpu/gpu.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func createPluginAndVerifyExistence(f *framework.Framework, ctx context.Context,
6969
}
7070

7171
ginkgo.By("checking if the resource is allocatable")
72-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, v1.ResourceName(baseResource), 30*time.Second, utils.WaitOpGreater); err != nil {
72+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, v1.ResourceName(baseResource), 30*time.Second, utils.WaitForPositiveResource); err != nil {
7373
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
7474
}
7575
}
@@ -104,8 +104,10 @@ func describe() {
104104

105105
e2ekubectl.RunKubectlOrDie(f.Namespace.Name, "delete", "-k", filepath.Dir(vanillaPath))
106106

107+
framework.Logf("Waiting for i915 resources to go to zero")
108+
107109
// Wait for resources to go to zero
108-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915", 30*time.Second, utils.WaitOpZero); err != nil {
110+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915", 30*time.Second, utils.WaitForZeroResource); err != nil {
109111
framework.Failf("unable to wait for nodes to have no resources: %v", err)
110112
}
111113
})
@@ -186,7 +188,7 @@ func describe() {
186188
createPluginAndVerifyExistence(f, ctx, monitoringPath, "gpu.intel.com/i915")
187189

188190
ginkgo.By("checking if the monitoring resource is allocatable")
189-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915_monitoring", 30*time.Second, utils.WaitOpGreater); err != nil {
191+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/i915_monitoring", 30*time.Second, utils.WaitForPositiveResource); err != nil {
190192
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
191193
}
192194
})
@@ -202,12 +204,12 @@ func describe() {
202204
e2ekubectl.RunKubectlOrDie("node-feature-discovery", "rollout", "restart", "daemonset", "nfd-worker")
203205

204206
ginkgo.By("checking if the millicores resource is allocatable")
205-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/millicores", 30*time.Second, utils.WaitOpGreater); err != nil {
207+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/millicores", 30*time.Second, utils.WaitForPositiveResource); err != nil {
206208
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
207209
}
208210

209211
ginkgo.By("checking if the tiles resource is allocatable")
210-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/tiles", 30*time.Second, utils.WaitOpGreater); err != nil {
212+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "gpu.intel.com/tiles", 30*time.Second, utils.WaitForPositiveResource); err != nil {
211213
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
212214
}
213215
})

test/e2e/iaa/iaa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func describe() {
9797
ginkgo.Context("When IAA resources are available [Resource:dedicated]", func() {
9898
ginkgo.BeforeEach(func(ctx context.Context) {
9999
ginkgo.By("checking if the resource is allocatable")
100-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "iaa.intel.com/wq-user-dedicated", 300*time.Second, utils.WaitOpGreater); err != nil {
100+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "iaa.intel.com/wq-user-dedicated", 300*time.Second, utils.WaitForPositiveResource); err != nil {
101101
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
102102
}
103103
})

test/e2e/operator/operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func testPluginWithOperator(deviceName string, resourceNames []v1.ResourceName,
8989
}
9090

9191
for _, resourceName := range resourceNames {
92-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resourceName, timeout, utils.WaitOpGreater); err != nil {
92+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resourceName, timeout, utils.WaitForPositiveResource); err != nil {
9393
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
9494
}
9595
}

test/e2e/qat/qatplugin_dpdk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func describeQatDpdkPlugin() {
9898
}
9999

100100
ginkgo.By("checking if the resource is allocatable")
101-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resourceName, 30*time.Second, utils.WaitOpGreater); err != nil {
101+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, resourceName, 30*time.Second, utils.WaitForPositiveResource); err != nil {
102102
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
103103
}
104104
})

test/e2e/qat/qatplugin_kernel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func describeQatKernelPlugin() {
8282
ginkgo.Context("When QAT resources are available [Resource:cy1_dc0]", func() {
8383
ginkgo.BeforeEach(func(ctx context.Context) {
8484
ginkgo.By("checking if the resource is allocatable")
85-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "qat.intel.com/cy1_dc0", 30*time.Second, utils.WaitOpGreater); err != nil {
85+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "qat.intel.com/cy1_dc0", 30*time.Second, utils.WaitForPositiveResource); err != nil {
8686
framework.Failf("unable to wait for nodes to have positive allocatable resource: %v", err)
8787
}
8888
})

test/e2e/sgx/sgx.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ func describe() {
8282
ginkgo.Context("When SGX resources are available", func() {
8383
ginkgo.BeforeEach(func(ctx context.Context) {
8484
ginkgo.By("checking if the resource is allocatable")
85-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/epc", 150*time.Second, utils.WaitOpGreater); err != nil {
85+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/epc", 150*time.Second, utils.WaitForPositiveResource); err != nil {
8686
framework.Failf("unable to wait for nodes to have positive allocatable epc resource: %v", err)
8787
}
88-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/enclave", 30*time.Second, utils.WaitOpGreater); err != nil {
88+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/enclave", 30*time.Second, utils.WaitForPositiveResource); err != nil {
8989
framework.Failf("unable to wait for nodes to have positive allocatable enclave resource: %v", err)
9090
}
91-
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 30*time.Second, utils.WaitOpGreater); err != nil {
91+
if err := utils.WaitForNodesWithResource(ctx, f.ClientSet, "sgx.intel.com/provision", 30*time.Second, utils.WaitForPositiveResource); err != nil {
9292
framework.Failf("unable to wait for nodes to have positive allocatable provision resource: %v", err)
9393
}
9494
})

test/e2e/utils/utils.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ import (
4040

4141
const (
4242
poll = time.Second
43-
44-
WaitOpGreater = 1
45-
WaitOpZero = 2
4643
)
4744

4845
// GetPodLogs returns the log of the container. If not possible to get logs, it returns the error message.
@@ -55,16 +52,20 @@ func GetPodLogs(ctx context.Context, f *framework.Framework, podName, containerN
5552
return fmt.Sprintf("log output of the container %s in the pod %s:%s", containerName, podName, log)
5653
}
5754

55+
type WaitForResourceFunc func(resourceCount int) bool
56+
57+
func WaitForPositiveResource(resourceCount int) bool {
58+
return resourceCount > 0
59+
}
60+
61+
func WaitForZeroResource(resourceCount int) bool {
62+
return resourceCount == 0
63+
}
64+
5865
// WaitForNodesWithResource waits for node's resources to change.
5966
// Depending on the waitOperation, function waits for positive resource count or a zero resource count.
60-
func WaitForNodesWithResource(ctx context.Context, c clientset.Interface, res v1.ResourceName, timeout time.Duration, waitOperation int) error {
61-
if waitOperation == WaitOpGreater {
62-
framework.Logf("Waiting up to %s for any positive allocatable resource %q", timeout, res)
63-
} else if waitOperation == WaitOpZero {
64-
framework.Logf("Waiting up to %s for allocatable resource %q to go to zero", timeout, res)
65-
} else {
66-
framework.Fail("unknown wait operation given: %d", waitOperation)
67-
}
67+
func WaitForNodesWithResource(ctx context.Context, c clientset.Interface, res v1.ResourceName, timeout time.Duration, waitForResourceFunc WaitForResourceFunc) error {
68+
framework.Logf("Waiting up to %s for allocatable resource %q", timeout, res)
6869

6970
start := time.Now()
7071

@@ -84,9 +85,7 @@ func WaitForNodesWithResource(ctx context.Context, c clientset.Interface, res v1
8485
}
8586
framework.Logf("Found %d of %q. Elapsed: %s", resNum, res, time.Since(start))
8687

87-
if waitOperation == WaitOpGreater && resNum > 0 {
88-
return true, nil
89-
} else if waitOperation == WaitOpZero && resNum == 0 {
88+
if waitForResourceFunc(resNum) {
9089
return true, nil
9190
}
9291
}

0 commit comments

Comments
 (0)