Skip to content

Commit 99767fe

Browse files
authored
Increasing retry time at multiple places and force delete of consul namespace on cluster (#4596)
* Fixing flaky tests * Setting eks version to 1.32 * Addition of force namespace deletion on cleanup of openshift * Changing retry conditions for api_gateway_sink_test * Fixing linting issue of return value not checked
1 parent 28c31cb commit 99767fe

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

acceptance/tests/api-gateway/api_gateway_kitchen_sink_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestAPIGateway_KitchenSink(t *testing.T) {
133133
httpRoute gwv1beta1.HTTPRoute
134134
)
135135

136-
counter = &retry.Counter{Count: 60, Wait: 2 * time.Second}
136+
counter = &retry.Counter{Count: 60, Wait: 60 * time.Second}
137137
retry.RunWith(counter, t, func(r *retry.R) {
138138
var gateway gwv1beta1.Gateway
139139
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: "gateway", Namespace: "default"}, &gateway)
@@ -149,7 +149,7 @@ func TestAPIGateway_KitchenSink(t *testing.T) {
149149
require.Len(r, gateway.Status.Listeners, 2)
150150

151151
// http route checks
152-
counter = &retry.Counter{Count: 60, Wait: 10 * time.Second}
152+
counter = &retry.Counter{Count: 60, Wait: 60 * time.Second}
153153
retry.RunWith(counter, t, func(r *retry.R) {
154154
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: "http-route", Namespace: "default"}, &httpRoute)
155155
require.NoError(r, err)

acceptance/tests/openshift/basic_openshift_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ func TestOpenshift_Basic(t *testing.T) {
3333
logf.SetLogger(logr.New(nil))
3434
logger.Log(t, "creating resources for OpenShift test")
3535

36-
cmd := exec.Command("kubectl", "apply", "-f", "../fixtures/cases/openshift/basic")
37-
output, err := cmd.CombinedOutput()
36+
counter := &retry.Counter{Count: 10, Wait: 120 * time.Second}
37+
var err error
38+
var output []byte
39+
retry.RunWith(counter, t, func(r *retry.R) {
40+
cmd := exec.Command("kubectl", "apply", "-f", "../fixtures/cases/openshift/basic")
41+
output, err = cmd.CombinedOutput()
42+
require.NoErrorf(r, err, "failed to create resources: %s", string(output))
43+
})
44+
3845
helpers.Cleanup(t, cfg.NoCleanupOnFailure, cfg.NoCleanup, func() {
3946
cmd := exec.Command("kubectl", "delete", "-f", "../fixtures/cases/openshift/basic")
4047
output, err := cmd.CombinedOutput()
4148
assert.NoErrorf(t, err, "failed to delete resources: %s", string(output))
4249
})
4350

44-
require.NoErrorf(t, err, "failed to create resources: %s", string(output))
45-
4651
// Grab a kubernetes client so that we can verify binding
4752
// behavior prior to issuing requests through the gateway.
4853
ctx := suite.Environment().DefaultContext(t)
@@ -53,7 +58,7 @@ func TestOpenshift_Basic(t *testing.T) {
5358
// On startup, the controller can take upwards of 1m to perform leader election,
5459
// so we may need to wait a long time for the reconcile loop to run (hence the timeout).
5560
var gatewayIP string
56-
counter := &retry.Counter{Count: 120, Wait: 2 * time.Second}
61+
counter = &retry.Counter{Count: 10, Wait: 120 * time.Second}
5762
retry.RunWith(counter, t, func(r *retry.R) {
5863
var gateway gwv1beta1.Gateway
5964
err := k8sClient.Get(context.Background(), types.NamespacedName{Name: "api-gateway", Namespace: "consul"}, &gateway)
@@ -73,7 +78,7 @@ func TestOpenshift_Basic(t *testing.T) {
7378
}}
7479

7580
var resp *http.Response
76-
counter = &retry.Counter{Count: 120, Wait: 2 * time.Second}
81+
counter = &retry.Counter{Count: 10, Wait: 120 * time.Second}
7782
retry.RunWith(counter, t, func(r *retry.R) {
7883
resp, err = client.Get("https://" + gatewayIP)
7984
require.NoErrorf(r, err, "request to API gateway failed: %s", err)

acceptance/tests/openshift/openshift_test_runner.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
package openshift
22

33
import (
4+
"os/exec"
5+
"strconv"
6+
"testing"
7+
48
"github.com/hashicorp/consul-k8s/acceptance/framework/config"
59
"github.com/hashicorp/consul-k8s/acceptance/framework/helpers"
610
"github.com/stretchr/testify/assert"
711
"github.com/stretchr/testify/require"
8-
"os/exec"
9-
"strconv"
10-
"testing"
1112
)
1213

1314
func newOpenshiftCluster(t *testing.T, cfg *config.TestConfig, secure, namespaceMirroring bool) {
14-
cmd := exec.Command("helm", "repo", "add", "hashicorp", "https://helm.releases.hashicorp.com")
15+
// Cleanup of old consul secret
16+
cmd := exec.Command("kubectl", "delete", "secret", "-n", "consul", "consul-ent-license")
17+
_, _ = cmd.CombinedOutput()
18+
19+
// Cleanup of old consul helm installtion and namespace
20+
cmd = exec.Command("helm", "uninstall", "consul", "--namespace", "consul")
21+
_, _ = cmd.CombinedOutput()
22+
23+
// Bypass finalizers for the consul namespace deletion.
24+
ns := "consul"
25+
cmd = exec.Command("bash", "-c", `kubectl get ns "`+ns+`" -o json | jq 'del(.spec.finalizers)' | kubectl replace --raw "/api/v1/namespaces/`+ns+`/finalize" -f -`)
26+
_ = cmd.Run()
27+
28+
// Cleanup of old consul namespace
29+
cmd = exec.Command("kubectl", "delete", "namespace", "consul")
30+
_, _ = cmd.CombinedOutput()
31+
32+
// Add the hashicorp helm repo
33+
cmd = exec.Command("helm", "repo", "add", "hashicorp", "https://helm.releases.hashicorp.com")
1534
output, err := cmd.CombinedOutput()
1635
require.NoErrorf(t, err, "failed to add hashicorp helm repo: %s", string(output))
1736

@@ -59,6 +78,7 @@ func newOpenshiftCluster(t *testing.T, cfg *config.TestConfig, secure, namespace
5978
"--set", "global.imageConsulDataplane="+cfg.ConsulDataplaneImage,
6079
"--set", "global.enterpriseLicense.secretName=consul-ent-license",
6180
"--set", "global.enterpriseLicense.secretKey=key",
81+
"--set", "connectInject.apiGateway.manageExternalCRDs=true",
6282
)
6383

6484
output, err = cmd.CombinedOutput()

0 commit comments

Comments
 (0)