Skip to content

Commit

Permalink
test: node: use Eventually() to check CiliumNode labels
Browse files Browse the repository at this point in the history
This should fix a flake that causes the test to fail as we are not
allowing enough time for the changes to the Node label to be applied to
the related CiliumNode object

Signed-off-by: Gilberto Bertin <jibi@cilium.io>
  • Loading branch information
jibi authored and gandro committed Sep 22, 2022
1 parent 69e0cce commit 570548a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/k8s/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package k8sTest

import (
"fmt"
"time"

. "github.com/onsi/gomega"

Expand Down Expand Up @@ -44,7 +45,9 @@ var _ = Describe("K8sNode", func() {
err = kubectl.Get(helpers.DefaultNamespace, fmt.Sprintf("ciliumnode %s", k8s1NodeName)).Unmarshal(&cn)
Expect(err).Should(BeNil(), "Can not retrieve %s CiliumNode %s", k8s1NodeName)

Expect(cn.ObjectMeta.Labels["test-label"]).To(Equal("test-value"))
Eventually(func() bool {
return cn.ObjectMeta.Labels["test-label"] == "test-value"
}, helpers.ShortCommandTimeout, time.Second).Should(BeTrue(), "%s CiliumNode labels are not in sync with Node object", helpers.K8s1)

res = kubectl.JsonPatch(helpers.DefaultNamespace, "node", k8s1NodeName, `[{"op": "remove", "path": "/metadata/labels/test-label"}]`)
Expect(res).Should(helpers.CMDSuccess(), "Error patching %s Node labels", k8s1NodeName)
Expand All @@ -53,6 +56,8 @@ var _ = Describe("K8sNode", func() {
err = kubectl.Get(helpers.DefaultNamespace, fmt.Sprintf("ciliumnode %s", k8s1NodeName)).Unmarshal(&cn2)
Expect(err).Should(BeNil(), "Can not retrieve %s CiliumNode %s", k8s1NodeName)

Expect(cn2.ObjectMeta.Labels["test-label"]).To(Equal(""))
Eventually(func() bool {
return cn2.ObjectMeta.Labels["test-label"] == ""
}, helpers.ShortCommandTimeout, time.Second).Should(BeTrue(), "%s CiliumNode labels are not in sync with Node object", helpers.K8s1)
})
})

0 comments on commit 570548a

Please sign in to comment.