Skip to content

Commit 5417407

Browse files
committed
fix: proxy test poll to avoid flakes
1 parent 1f90bed commit 5417407

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

pkg/internal/integration/service_test.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,8 @@ func (s *IntegrationTestSuite) TestFloatingIPConflicts() {
10881088

10891089
func (s *IntegrationTestSuite) TestServiceProxyProtocol() {
10901090

1091+
const curlImage = "docker.io/curlimages/curl@sha256:b3f1fb2a51d923260350d21b8654bbc607164a987e2f7c84a0ac199a67df812a"
1092+
10911093
// Deploy our http-echo server to check for proxy connections
10921094
httpEchoImage := os.Getenv("HTTP_ECHO_IMAGE")
10931095
if httpEchoImage == "" {
@@ -1143,7 +1145,7 @@ func (s *IntegrationTestSuite) TestServiceProxyProtocol() {
11431145
// Sending a request from inside the cluster does not work, unless we
11441146
// use a workaround.
11451147
s.T().Log("Testing PROXY protocol from inside")
1146-
used = s.RunJob("docker.io/curlimages/curl@sha256:b3f1fb2a51d923260350d21b8654bbc607164a987e2f7c84a0ac199a67df812a", 90*time.Second, "curl", "-s", url)
1148+
used = s.RunJob(curlImage, 90*time.Second, "curl", "-s", url)
11471149
s.Assert().Equal("false\n", used)
11481150

11491151
// The workaround works by using an IP that needs to be reolved via name
@@ -1156,8 +1158,14 @@ func (s *IntegrationTestSuite) TestServiceProxyProtocol() {
11561158
),
11571159
}, WithServicePort(ServicePortSpec{Protocol: v1.ProtocolTCP, Port: 80, TargetPort: 80}))
11581160

1161+
// The CCM needs to reconcile the annotation change and flip the service
1162+
// status. Poll until we observe the workaround taking effect.
11591163
s.T().Log("Testing PROXY protocol from inside with workaround")
1160-
used = s.RunJob("docker.io/curlimages/curl@sha256:b3f1fb2a51d923260350d21b8654bbc607164a987e2f7c84a0ac199a67df812a", 90*time.Second, "curl", "-s", url)
1164+
s.Assert().Eventually(func() bool {
1165+
used = s.RunJob(curlImage, 90*time.Second, "curl", "-s", url)
1166+
s.T().Logf("PROXY protocol used: %q", strings.TrimSpace(used))
1167+
return used == "true\n"
1168+
}, 3*time.Minute, 1*time.Second)
11611169
s.Assert().Equal("true\n", used)
11621170

11631171
// On newer Kubernetes releases, the defaults just work
@@ -1169,8 +1177,14 @@ func (s *IntegrationTestSuite) TestServiceProxyProtocol() {
11691177
"k8s.cloudscale.ch/loadbalancer-pool-protocol": "proxy",
11701178
}, WithServicePort(ServicePortSpec{Protocol: v1.ProtocolTCP, Port: 80, TargetPort: 80}))
11711179

1180+
// Same as above: wait for CCM to converge on the
1181+
// new state before asserting.
11721182
s.T().Log("Testing PROXY protocol on newer Kubernetes releases")
1173-
used = s.RunJob("docker.io/curlimages/curl@sha256:b3f1fb2a51d923260350d21b8654bbc607164a987e2f7c84a0ac199a67df812a", 90*time.Second, "curl", "-s", url)
1183+
s.Assert().Eventually(func() bool {
1184+
used = s.RunJob(curlImage, 90*time.Second, "curl", "-s", url)
1185+
s.T().Logf("PROXY protocol used: %q", strings.TrimSpace(used))
1186+
return used == "true\n"
1187+
}, 3*time.Minute, 1*time.Second)
11741188
s.Assert().Equal("true\n", used)
11751189
}
11761190
}

0 commit comments

Comments
 (0)