Skip to content

Commit 1c1079c

Browse files
committed
Testing consul-1.21-dev + consul-k8s-1.7.x with ocp-4.16
- Testing consul-1.21-dev + consul-k8s-1.7.x with ocp-4.16 + k8s-1.30.0 + kubectl 1.30.0 - Added OCP logging for error debugging and cluster stuck issues and finalizer issues
1 parent 0f94f93 commit 1c1079c

File tree

4 files changed

+80
-5
lines changed

4 files changed

+80
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Dispatch to the consul-k8s-workflows with a nightly cron
2+
name: pr-openshift-acceptance
3+
on:
4+
pull_request:
5+
branches:
6+
- release/1.7.0-rc1
7+
8+
# these should be the only settings that you will ever need to change
9+
env:
10+
BRANCH: ${{ github.event.pull_request.head.ref }}
11+
CONTEXT: "pr"
12+
13+
jobs:
14+
openshift-acceptance:
15+
name: openshift-acceptance
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: benc-uk/workflow-dispatch@25b02cc069be46d637e8fe2f1e8484008e9e9609 # v1.2.3
19+
name: cloud
20+
with:
21+
workflow: cloud.yml
22+
repo: hashicorp/consul-k8s-workflows
23+
ref: mukul/testing-ocp-compatibility
24+
token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
25+
inputs: '{ "context":"${{ env.CONTEXT }}", "repository":"${{ github.repository }}", "branch":"${{ env.BRANCH }}", "sha":"${{ github.sha }}", "token":"${{ secrets.ELEVATED_GITHUB_TOKEN }}", "test-integrations": "ocp" }'

.github/workflows/pr.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
name: pr
33
on:
44
pull_request:
5+
branches:
6+
- release/1.7.0-rc1
57

68
# these should be the only settings that you will ever need to change
79
env:
@@ -24,7 +26,7 @@ jobs:
2426
with:
2527
workflow: test.yml
2628
repo: hashicorp/consul-k8s-workflows
27-
ref: main
29+
ref: mukul/testing-ocp-compatibility
2830
token: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
2931
inputs: '{ "context":"${{ env.CONTEXT }}", "actor":"${{ github.actor }}", "repository":"${{ github.repository }}", "branch":"${{ env.BRANCH }}", "sha":"${{ env.SHA }}", "token":"${{ secrets.ELEVATED_GITHUB_TOKEN }}" }'
3032

acceptance/ci-inputs/kind-inputs.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# SPDX-License-Identifier: MPL-2.0
33

44
kindVersion: v0.23.0
5-
kindNodeImage: kindest/node:v1.30.2@sha256:ecfe5841b9bee4fe9690f49c118c33629fa345e3350a0c67a5a34482a99d6bba
6-
kubectlVersion: v1.30.2
5+
# digest for kindest/node:v1.30.0
6+
kindNodeImage: kindest/node:v1.30.0
7+
kubectlVersion: v1.30.0

acceptance/tests/openshift/openshift_test_runner.go

+49-2
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,67 @@ import (
1313
func newOpenshiftCluster(t *testing.T, cfg *config.TestConfig, secure, namespaceMirroring bool) {
1414
cmd := exec.Command("helm", "repo", "add", "hashicorp", "https://helm.releases.hashicorp.com")
1515
output, err := cmd.CombinedOutput()
16-
require.NoErrorf(t, err, "failed to add hashicorp helm repo: %s", string(output))
16+
require.NoErrorf(t, err, "failed to add hashicorp helm repo : %s", string(output))
17+
// Add diagnostic logging before attempting cleanup
18+
logCmd := exec.Command("kubectl", "get", "all", "-n", "consul")
19+
logOutput, _ := logCmd.CombinedOutput()
20+
t.Logf("Resources in consul namespace before cleanup:\n%s", string(logOutput))
21+
22+
// Check if namespace exists and its status
23+
nsCheckCmd := exec.Command("kubectl", "get", "namespace", "consul", "-o", "json")
24+
nsOutput, _ := nsCheckCmd.CombinedOutput()
25+
t.Logf("Consul namespace status before cleanup:\n%s", string(nsOutput))
1726

1827
// FUTURE for some reason NewHelmCluster creates a consul server pod that runs as root which
1928
// isn't allowed in OpenShift. In order to test OpenShift properly, we have to call helm and k8s
2029
// directly to bypass. Ideally we would just fix the framework that is running the pod as root.
30+
// First, try to delete the namespace if it exists (cleanup from previous runs)
31+
t.Log("Attempting to delete consul namespace if it exists...")
32+
cleanupCmd := exec.Command("kubectl", "delete", "namespace", "consul", "--ignore-not-found=true")
33+
cleanupOutput, cleanupErr := cleanupCmd.CombinedOutput()
34+
// We don't check error here since it's just precautionary cleanup
35+
t.Logf("Namespace deletion attempt result: %v\nOutput: %s", cleanupErr, string(cleanupOutput))
36+
37+
// Wait for namespace to be fully deleted before proceeding
38+
t.Log("Waiting for consul namespace to be fully deleted...")
39+
waitCmd := exec.Command("kubectl", "wait", "--for=delete", "namespace/consul", "--timeout=120s")
40+
waitOutput, waitErr := waitCmd.CombinedOutput() // Ignore errors, as this will error if the namespace doesn't exist at all
41+
t.Logf("Wait result: %v\nOutput: %s", waitErr, string(waitOutput))
42+
43+
// Force cleanup of any stuck resources in the namespace (if it still exists)
44+
t.Log("Checking for any stuck resources...")
45+
forceCleanupCmd := exec.Command("bash", "-c", `
46+
# Try to find finalizers on the namespace
47+
FINALIZERS=$(kubectl get namespace consul -o json 2>/dev/null | jq '.spec.finalizers' 2>/dev/null)
48+
if [ ! -z "$FINALIZERS" ] && [ "$FINALIZERS" != "null" ]; then
49+
echo "Found finalizers on namespace, attempting to remove them..."
50+
# Remove finalizers from namespace to force deletion
51+
kubectl get namespace consul -o json | jq '.spec.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/consul/finalize" -f -
52+
fi
53+
`)
54+
forceOutput, _ := forceCleanupCmd.CombinedOutput()
55+
t.Logf("Force cleanup result:\n%s", string(forceOutput))
56+
57+
// Now create the namespace
2158
cmd = exec.Command("kubectl", "create", "namespace", "consul")
2259
output, err = cmd.CombinedOutput()
60+
2361
helpers.Cleanup(t, cfg.NoCleanupOnFailure, cfg.NoCleanup, func() {
62+
if t.Failed() {
63+
t.Log("Test already failed, skipping cleanup assertions")
64+
cmd = exec.Command("kubectl", "delete", "namespace", "consul")
65+
if err := cmd.Run(); err != nil {
66+
t.Logf("Failed to delete namespace: %v", err)
67+
}
68+
return
69+
}
70+
2471
cmd = exec.Command("kubectl", "delete", "namespace", "consul")
2572
output, err = cmd.CombinedOutput()
2673
assert.NoErrorf(t, err, "failed to delete namespace: %s", string(output))
2774
})
2875

29-
require.NoErrorf(t, err, "failed to add hashicorp helm repo: %s", string(output))
76+
require.NoErrorf(t, err, "failed to create namespace: %s", string(output))
3077

3178
cmd = exec.Command("kubectl", "create", "secret", "generic",
3279
"consul-ent-license",

0 commit comments

Comments
 (0)