Skip to content

Commit 9ee7185

Browse files
authored
Merge pull request kubernetes#119501 from Songjoy/cleanup-e2e-node-framework-equal
e2e_node: stop using deprecated framework.ExpectEqual
2 parents 4d16694 + 63cf568 commit 9ee7185

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

test/e2e/node/events.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
admissionapi "k8s.io/pod-security-admission/api"
3333

3434
"github.com/onsi/ginkgo/v2"
35+
"github.com/onsi/gomega"
3536
)
3637

3738
var _ = SIGDescribe("Events", func() {
@@ -81,7 +82,7 @@ var _ = SIGDescribe("Events", func() {
8182
options := metav1.ListOptions{LabelSelector: selector.String()}
8283
pods, err := podClient.List(ctx, options)
8384
framework.ExpectNoError(err)
84-
framework.ExpectEqual(len(pods.Items), 1)
85+
gomega.Expect(pods.Items).To(gomega.HaveLen(1))
8586

8687
ginkgo.By("retrieving the pod")
8788
podWithUID, err := podClient.Get(ctx, pod.Name, metav1.GetOptions{})

test/e2e/node/mount_propagation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
admissionapi "k8s.io/pod-security-admission/api"
3333

3434
"github.com/onsi/ginkgo/v2"
35+
"github.com/onsi/gomega"
3536
)
3637

3738
func preparePod(name string, node *v1.Node, propagation *v1.MountPropagationMode, hostDir string) *v1.Pod {
@@ -178,7 +179,7 @@ var _ = SIGDescribe("Mount propagation", func() {
178179
shouldBeVisible := mounts.Has(mountName)
179180
if shouldBeVisible {
180181
framework.ExpectNoError(err, "%s: failed to run %q", msg, cmd)
181-
framework.ExpectEqual(stdout, mountName, msg)
182+
gomega.Expect(stdout).To(gomega.Equal(mountName), msg)
182183
} else {
183184
// We *expect* cat to return error here
184185
framework.ExpectError(err, msg)
@@ -191,7 +192,7 @@ var _ = SIGDescribe("Mount propagation", func() {
191192
kubeletPid, err := hostExec.IssueCommandWithResult(ctx, cmd, node)
192193
framework.ExpectNoError(err, "Checking kubelet pid")
193194
kubeletPid = strings.TrimSuffix(kubeletPid, "\n")
194-
framework.ExpectEqual(strings.Count(kubeletPid, " "), 0, "kubelet should only have a single PID in the system (pidof returned %q)", kubeletPid)
195+
gomega.Expect(strings.Count(kubeletPid, " ")).To(gomega.Equal(0), "kubelet should only have a single PID in the system (pidof returned %q)", kubeletPid)
195196
enterKubeletMountNS := fmt.Sprintf("nsenter -t %s -m", kubeletPid)
196197

197198
// Check that the master and host mounts are propagated to the container runtime's mount namespace
@@ -200,7 +201,7 @@ var _ = SIGDescribe("Mount propagation", func() {
200201
output, err := hostExec.IssueCommandWithResult(ctx, cmd, node)
201202
framework.ExpectNoError(err, "host container namespace should see mount from %s: %s", mountName, output)
202203
output = strings.TrimSuffix(output, "\n")
203-
framework.ExpectEqual(output, mountName, "host container namespace should see mount contents from %s", mountName)
204+
gomega.Expect(output).To(gomega.Equal(mountName), "host container namespace should see mount contents from %s", mountName)
204205
}
205206

206207
// Check that the slave, private, and default mounts are not propagated to the container runtime's mount namespace

test/e2e/node/node_problem_detector.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ var _ = SIGDescribe("NodeProblemDetector", func() {
121121
psCmd := "ps aux | grep [n]ode-problem-detector"
122122
result, err = e2essh.SSH(ctx, psCmd, host, framework.TestContext.Provider)
123123
framework.ExpectNoError(err)
124-
framework.ExpectEqual(result.Code, 0)
124+
gomega.Expect(result.Code).To(gomega.Equal(0))
125125
gomega.Expect(result.Stdout).To(gomega.ContainSubstring("node-problem-detector"))
126126

127127
ginkgo.By(fmt.Sprintf("Check node-problem-detector is running fine on node %q", host))
128128
journalctlCmd := "sudo journalctl -r -u node-problem-detector"
129129
result, err = e2essh.SSH(ctx, journalctlCmd, host, framework.TestContext.Provider)
130130
framework.ExpectNoError(err)
131-
framework.ExpectEqual(result.Code, 0)
131+
gomega.Expect(result.Code).To(gomega.Equal(0))
132132
gomega.Expect(result.Stdout).NotTo(gomega.ContainSubstring("node-problem-detector.service: Failed"))
133133

134134
// We only will check for the KubeletStart even if parsing of date here succeeded.
135135
ginkgo.By(fmt.Sprintf("Check when node-problem-detector started on node %q", host))
136136
npdStartTimeCommand := "sudo systemctl show --timestamp=utc node-problem-detector -P ActiveEnterTimestamp"
137137
result, err = e2essh.SSH(ctx, npdStartTimeCommand, host, framework.TestContext.Provider)
138138
framework.ExpectNoError(err)
139-
framework.ExpectEqual(result.Code, 0)
139+
gomega.Expect(result.Code).To(gomega.Equal(0))
140140

141141
// The time format matches the systemd format.
142142
// 'utc': 'Day YYYY-MM-DD HH:MM:SS UTC (see https://www.freedesktop.org/software/systemd/man/systemd.time.html)
@@ -157,7 +157,7 @@ var _ = SIGDescribe("NodeProblemDetector", func() {
157157
injectLogCmd := "sudo sh -c \"echo 'kernel: " + log + "' >> /dev/kmsg\""
158158
result, err = e2essh.SSH(ctx, injectLogCmd, host, framework.TestContext.Provider)
159159
framework.ExpectNoError(err)
160-
framework.ExpectEqual(result.Code, 0)
160+
gomega.Expect(result.Code).To(gomega.Equal(0))
161161
}
162162

163163
ginkgo.By("Check node-problem-detector can post conditions and events to API server")
@@ -297,7 +297,7 @@ func getMemoryStat(ctx context.Context, f *framework.Framework, host string) (rs
297297

298298
result, err := e2essh.SSH(ctx, memCmd, host, framework.TestContext.Provider)
299299
framework.ExpectNoError(err)
300-
framework.ExpectEqual(result.Code, 0)
300+
gomega.Expect(result.Code).To(gomega.Equal(0))
301301
lines := strings.Split(result.Stdout, "\n")
302302

303303
memoryUsage, err := strconv.ParseFloat(lines[0], 64)
@@ -351,7 +351,7 @@ func getCPUStat(ctx context.Context, f *framework.Framework, host string) (usage
351351

352352
result, err := e2essh.SSH(ctx, cpuCmd, host, framework.TestContext.Provider)
353353
framework.ExpectNoError(err)
354-
framework.ExpectEqual(result.Code, 0)
354+
gomega.Expect(result.Code).To(gomega.Equal(0))
355355
lines := strings.Split(result.Stdout, "\n")
356356

357357
usage, err = strconv.ParseFloat(lines[0], 64)
@@ -367,7 +367,7 @@ func getCPUStat(ctx context.Context, f *framework.Framework, host string) (usage
367367
func isHostRunningCgroupV2(ctx context.Context, f *framework.Framework, host string) bool {
368368
result, err := e2essh.SSH(ctx, "stat -fc %T /sys/fs/cgroup/", host, framework.TestContext.Provider)
369369
framework.ExpectNoError(err)
370-
framework.ExpectEqual(result.Code, 0)
370+
gomega.Expect(result.Code).To(gomega.Equal(0))
371371

372372
// 0x63677270 == CGROUP2_SUPER_MAGIC
373373
// https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html

test/e2e/node/pod_resize.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func verifyPodResizePolicy(pod *v1.Pod, tcInfo []TestContainerInfo) {
241241
gomega.Expect(cMap).Should(gomega.HaveKey(ci.Name))
242242
c := cMap[ci.Name]
243243
tc, _ := makeTestContainer(ci)
244-
framework.ExpectEqual(tc.ResizePolicy, c.ResizePolicy)
244+
gomega.Expect(tc.ResizePolicy).To(gomega.Equal(c.ResizePolicy))
245245
}
246246
}
247247

@@ -254,7 +254,7 @@ func verifyPodResources(pod *v1.Pod, tcInfo []TestContainerInfo) {
254254
gomega.Expect(cMap).Should(gomega.HaveKey(ci.Name))
255255
c := cMap[ci.Name]
256256
tc, _ := makeTestContainer(ci)
257-
framework.ExpectEqual(tc.Resources, c.Resources)
257+
gomega.Expect(tc.Resources).To(gomega.Equal(c.Resources))
258258
}
259259
}
260260

@@ -279,7 +279,7 @@ func verifyPodAllocations(pod *v1.Pod, tcInfo []TestContainerInfo, flagError boo
279279

280280
_, tcStatus := makeTestContainer(ci)
281281
if flagError {
282-
framework.ExpectEqual(tcStatus.AllocatedResources, cStatus.AllocatedResources)
282+
gomega.Expect(tcStatus.AllocatedResources).To(gomega.Equal(cStatus.AllocatedResources))
283283
}
284284
if !cmp.Equal(cStatus.AllocatedResources, tcStatus.AllocatedResources) {
285285
return false
@@ -297,8 +297,8 @@ func verifyPodStatusResources(pod *v1.Pod, tcInfo []TestContainerInfo) {
297297
gomega.Expect(csMap).Should(gomega.HaveKey(ci.Name))
298298
cs := csMap[ci.Name]
299299
tc, _ := makeTestContainer(ci)
300-
framework.ExpectEqual(tc.Resources, *cs.Resources)
301-
//framework.ExpectEqual(cs.RestartCount, ci.RestartCount)
300+
gomega.Expect(tc.Resources).To(gomega.Equal(*cs.Resources))
301+
//gomega.Expect(cs.RestartCount).To(gomega.Equal(ci.RestartCount))
302302
}
303303
}
304304

@@ -1555,13 +1555,13 @@ func doPodResizeSchedulerTests() {
15551555

15561556
ginkgo.By(fmt.Sprintf("TEST1: Create pod '%s' that fits the node '%s'", testPod1.Name, node.Name))
15571557
testPod1 = podClient.CreateSync(ctx, testPod1)
1558-
framework.ExpectEqual(testPod1.Status.Phase, v1.PodRunning)
1558+
gomega.Expect(testPod1.Status.Phase).To(gomega.Equal(v1.PodRunning))
15591559

15601560
ginkgo.By(fmt.Sprintf("TEST1: Create pod '%s' that won't fit node '%s' with pod '%s' on it", testPod2.Name, node.Name, testPod1.Name))
15611561
testPod2 = podClient.Create(ctx, testPod2)
15621562
err = e2epod.WaitForPodNameUnschedulableInNamespace(ctx, f.ClientSet, testPod2.Name, testPod2.Namespace)
15631563
framework.ExpectNoError(err)
1564-
framework.ExpectEqual(testPod2.Status.Phase, v1.PodPending)
1564+
gomega.Expect(testPod2.Status.Phase).To(gomega.Equal(v1.PodPending))
15651565

15661566
ginkgo.By(fmt.Sprintf("TEST1: Resize pod '%s' to fit in node '%s'", testPod2.Name, node.Name))
15671567
testPod2, pErr := f.ClientSet.CoreV1().Pods(testPod2.Namespace).Patch(ctx,
@@ -1610,7 +1610,7 @@ func doPodResizeSchedulerTests() {
16101610
testPod3 = podClient.Create(ctx, testPod3)
16111611
p3Err := e2epod.WaitForPodNameUnschedulableInNamespace(ctx, f.ClientSet, testPod3.Name, testPod3.Namespace)
16121612
framework.ExpectNoError(p3Err, "failed to create pod3 or pod3 did not become pending!")
1613-
framework.ExpectEqual(testPod3.Status.Phase, v1.PodPending)
1613+
gomega.Expect(testPod3.Status.Phase).To(gomega.Equal(v1.PodPending))
16141614

16151615
ginkgo.By(fmt.Sprintf("TEST2: Resize pod '%s' to make enough space for pod '%s'", testPod1.Name, testPod3.Name))
16161616
testPod1, p1Err := f.ClientSet.CoreV1().Pods(testPod1.Namespace).Patch(context.TODO(),

test/e2e/node/pods.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
utilpointer "k8s.io/utils/pointer"
4949

5050
"github.com/onsi/ginkgo/v2"
51+
"github.com/onsi/gomega"
5152
"github.com/prometheus/client_golang/prometheus"
5253
"github.com/prometheus/common/expfmt"
5354
)
@@ -82,7 +83,7 @@ var _ = SIGDescribe("Pods Extended", func() {
8283
options := metav1.ListOptions{LabelSelector: selector.String()}
8384
pods, err := podClient.List(ctx, options)
8485
framework.ExpectNoError(err, "failed to query for pod")
85-
framework.ExpectEqual(len(pods.Items), 0)
86+
gomega.Expect(pods.Items).To(gomega.BeEmpty())
8687

8788
ginkgo.By("submitting the pod to kubernetes")
8889
podClient.Create(ctx, pod)
@@ -92,7 +93,7 @@ var _ = SIGDescribe("Pods Extended", func() {
9293
options = metav1.ListOptions{LabelSelector: selector.String()}
9394
pods, err = podClient.List(ctx, options)
9495
framework.ExpectNoError(err, "failed to query for pod")
95-
framework.ExpectEqual(len(pods.Items), 1)
96+
gomega.Expect(pods.Items).To(gomega.HaveLen(1))
9697

9798
// We need to wait for the pod to be running, otherwise the deletion
9899
// may be carried out immediately rather than gracefully.
@@ -106,7 +107,7 @@ var _ = SIGDescribe("Pods Extended", func() {
106107
var statusCode int
107108
err = f.ClientSet.CoreV1().RESTClient().Delete().AbsPath("/api/v1/namespaces", pod.Namespace, "pods", pod.Name).Param("gracePeriodSeconds", "30").Do(ctx).StatusCode(&statusCode).Into(&lastPod)
108109
framework.ExpectNoError(err, "failed to use http client to send delete")
109-
framework.ExpectEqual(statusCode, http.StatusOK, "failed to delete gracefully by client request")
110+
gomega.Expect(statusCode).To(gomega.Equal(http.StatusOK), "failed to delete gracefully by client request")
110111

111112
ginkgo.By("verifying the kubelet observed the termination notice")
112113

@@ -144,8 +145,7 @@ var _ = SIGDescribe("Pods Extended", func() {
144145
options = metav1.ListOptions{LabelSelector: selector.String()}
145146
pods, err = podClient.List(ctx, options)
146147
framework.ExpectNoError(err, "failed to query for pods")
147-
framework.ExpectEqual(len(pods.Items), 0)
148-
148+
gomega.Expect(pods.Items).To(gomega.BeEmpty())
149149
})
150150
})
151151

@@ -197,7 +197,7 @@ var _ = SIGDescribe("Pods Extended", func() {
197197
ginkgo.By("verifying QOS class is set on the pod")
198198
pod, err := podClient.Get(ctx, name, metav1.GetOptions{})
199199
framework.ExpectNoError(err, "failed to query for pod")
200-
framework.ExpectEqual(pod.Status.QOSClass, v1.PodQOSGuaranteed)
200+
gomega.Expect(pod.Status.QOSClass).To(gomega.Equal(v1.PodQOSGuaranteed))
201201
})
202202
})
203203

test/e2e/node/runtimeclass.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ var _ = SIGDescribe("RuntimeClass", func() {
123123
// check that pod got scheduled on specified node.
124124
scheduledPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, pod.Name, metav1.GetOptions{})
125125
framework.ExpectNoError(err)
126-
framework.ExpectEqual(nodeName, scheduledPod.Spec.NodeName)
127-
framework.ExpectEqual(nodeSelector, pod.Spec.NodeSelector)
126+
gomega.Expect(nodeName).To(gomega.Equal(scheduledPod.Spec.NodeName))
127+
gomega.Expect(nodeSelector).To(gomega.Equal(pod.Spec.NodeSelector))
128128
gomega.Expect(pod.Spec.Tolerations).To(gomega.ContainElement(tolerations[0]))
129129
})
130130

@@ -169,8 +169,8 @@ var _ = SIGDescribe("RuntimeClass", func() {
169169
// check that pod got scheduled on specified node.
170170
scheduledPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(ctx, pod.Name, metav1.GetOptions{})
171171
framework.ExpectNoError(err)
172-
framework.ExpectEqual(nodeName, scheduledPod.Spec.NodeName)
173-
framework.ExpectEqual(nodeSelector, pod.Spec.NodeSelector)
172+
gomega.Expect(nodeName).To(gomega.Equal(scheduledPod.Spec.NodeName))
173+
gomega.Expect(nodeSelector).To(gomega.Equal(pod.Spec.NodeSelector))
174174
})
175175
})
176176

0 commit comments

Comments
 (0)