Skip to content

Commit 4ba1f05

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 4ba1f05

File tree

6 files changed

+171
-6
lines changed

6 files changed

+171
-6
lines changed
+25
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+
cloud-acceptance:
15+
name: cloud-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": "eks, aks, gke" }'

.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

.github/workflows/weekly-acceptance-1-7-x.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
schedule:
77
# * is a special character in YAML so you have to quote this string
88
# Run weekly on Sunday at 3AM UTC/11PM EST/8PM PST
9-
- cron: '0 3 * * 7'
9+
- cron: '0 3 * * 0'
1010

1111
# these should be the only settings that you will ever need to change
1212
env:

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

+136-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,148 @@ import (
55
"github.com/hashicorp/consul-k8s/acceptance/framework/helpers"
66
"github.com/stretchr/testify/assert"
77
"github.com/stretchr/testify/require"
8+
"os"
89
"os/exec"
910
"strconv"
11+
"strings"
12+
"syscall"
1013
"testing"
1114
)
1215

16+
func interruptProcess(t *testing.T) {
17+
p, err := os.FindProcess(os.Getpid())
18+
if err != nil {
19+
t.Logf("Failed to find process: %v", err)
20+
return
21+
}
22+
err = p.Signal(syscall.SIGINT)
23+
if err != nil {
24+
t.Logf("Failed to send interrupt signal: %v", err)
25+
}
26+
}
27+
func removeNamespaceFinalizer(t *testing.T, namespace string) {
28+
cmd := exec.Command("kubectl", "patch", "namespace", namespace,
29+
"--type=json", "-p", `[{"op": "remove", "path": "/spec/finalizers"}]`)
30+
31+
if output, err := cmd.CombinedOutput(); err != nil {
32+
t.Logf("Error removing namespace finalizer: %v\nOutput: %s\n", err, output)
33+
}
34+
verifyNamespaceDeletion(t, namespace)
35+
}
36+
37+
func verifyNamespaceDeletion(t *testing.T, namespace string) {
38+
checkCmd := exec.Command("kubectl", "get", "ns", namespace)
39+
if checkErr := checkCmd.Run(); checkErr != nil {
40+
t.Logf("Namespace %s deleted successfully\n", namespace)
41+
return
42+
}
43+
44+
t.Logf("Namespace still exists. Additional cleanup might be required")
45+
interruptProcess(t)
46+
}
47+
48+
func gatewayControllerDiagnostic(t *testing.T, namespace string) {
49+
// Add diagnostic logging for pods for controller identification
50+
lsNamespaceCmd := exec.Command("oc", "get", "namespaces", "-o", "wide")
51+
lsNamespaceOutput, _ := lsNamespaceCmd.CombinedOutput()
52+
t.Logf("Namespaces in cluster:\n%s", string(lsNamespaceOutput))
53+
54+
podInfoCmd := exec.Command("kubectl", "get", "pods", "-n", namespace)
55+
podInfoOutput, _ := podInfoCmd.CombinedOutput()
56+
t.Logf("Pod status in namespace %s before cleanup:\n%s", namespace, string(podInfoOutput))
57+
58+
podInfoCmd = exec.Command("kubectl", "get", "pods", "-n", "kube-system")
59+
podInfoOutput, _ = podInfoCmd.CombinedOutput()
60+
t.Logf("Pod status in namespace %s before cleanup:\n%s", "kube-system", string(podInfoOutput))
61+
}
62+
63+
func checkAndDeleteNamespace(t *testing.T) {
64+
// There are some commands in this function
65+
//which are not being replaced with this variables and need manual replacement of namespace
66+
namespace := "consul"
67+
// Check if namespace exists and its status
68+
nsCheckCmd := exec.Command("kubectl", "get", "namespace", namespace, "-o", "json")
69+
nsOutput, _ := nsCheckCmd.CombinedOutput()
70+
t.Logf("Consul namespace status before cleanup:\n%s", string(nsOutput))
71+
72+
// Add diagnostic logging before attempting cleanup
73+
logCmd := exec.Command("kubectl", "get", "all", "-n", namespace)
74+
logOutput, _ := logCmd.CombinedOutput()
75+
t.Logf("Resources in consul namespace before cleanup:\n%s", string(logOutput))
76+
77+
// find gateway controller information and logs
78+
gatewayControllerDiagnostic(t, namespace)
79+
// Force cleanup of any stuck resources in the namespace (if it still exists)
80+
t.Log("Checking for any stuck resources...")
81+
forceCleanupCmd := exec.Command("bash", "-c", `
82+
# Try to find finalizers on the namespace
83+
FINALIZERS=$(kubectl get namespace consul -o json 2>/dev/null | jq '.spec.finalizers' 2>/dev/null)
84+
if [ ! -z "$FINALIZERS" ] && [ "$FINALIZERS" != "null" ]; then
85+
echo "Found finalizers on namespace consul"
86+
echo $FINALIZERS
87+
# Remove finalizers from namespace to force deletion
88+
# kubectl get namespace consul -o json | jq '.spec.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/consul/finalize" -f -
89+
fi
90+
if kubectl get namespace consul > /dev/null 2>&1; then
91+
# Check for gateway resources
92+
GATEWAYS=$(kubectl get gateways.gateway.networking.k8s.io -n consul -o json 2>/dev/null || echo "")
93+
echo $GATEWAYS
94+
fi
95+
`)
96+
forceOutput, _ := forceCleanupCmd.CombinedOutput()
97+
t.Logf("Force cleanup result:\n%s", string(forceOutput))
98+
99+
// Get remaining Gateways
100+
getCmd := exec.Command("kubectl", "get", "gateways.gateway.networking.k8s.io", "-n", namespace,
101+
"-o=jsonpath={.items[*].metadata.name}")
102+
output, err := getCmd.CombinedOutput()
103+
t.Logf("Gateway resource check result:\n%s", string(output))
104+
105+
if err != nil {
106+
t.Logf("Error getting gateways: %v\n", err)
107+
return
108+
}
109+
cleanedOutput := strings.TrimSpace(string(output))
110+
if cleanedOutput == "" {
111+
t.Logf("No gateways found, removing namespace finalizer")
112+
removeNamespaceFinalizer(t, namespace)
113+
return
114+
}
115+
if len(cleanedOutput) > 0 {
116+
// Remove finalizers from each gateway
117+
patchCmd := exec.Command("kubectl", "patch", "gateways.gateway.networking.k8s.io", string(output), "-n", namespace,
118+
"--type=json", "-p", `[{"op": "remove", "path": "/metadata/finalizers"}]`)
119+
patchOutput, patchErr := patchCmd.CombinedOutput()
120+
if patchErr != nil {
121+
t.Logf("Error patching gateway: %v\nOutput: %s\n", patchErr, patchOutput)
122+
return
123+
}
124+
t.Logf("Finalizers removed successfully")
125+
removeNamespaceFinalizer(t, namespace)
126+
}
127+
t.Log("Attempting to delete consul namespace if it exists...")
128+
cleanupCmd := exec.Command("kubectl", "delete", "namespace", "consul", "--ignore-not-found=true")
129+
cleanupOutput, cleanupErr := cleanupCmd.CombinedOutput()
130+
// We don't check error here since it's just precautionary cleanup
131+
t.Logf("Namespace deletion attempt result: %v\nOutput: %s", cleanupErr, string(cleanupOutput))
132+
133+
// Wait for namespace to be fully deleted before proceeding
134+
t.Log("Waiting for consul namespace to be fully deleted...")
135+
waitCmd := exec.Command("kubectl", "wait", "--for=delete", "namespace/consul", "--timeout=30s")
136+
waitOutput, waitErr := waitCmd.CombinedOutput() // Ignore errors, as this will error if the namespace doesn't exist at all
137+
t.Logf("Wait result: %v\nOutput: %s", waitErr, string(waitOutput))
138+
139+
// Verify namespace deletion
140+
verifyNamespaceDeletion(t, namespace)
141+
}
142+
13143
func newOpenshiftCluster(t *testing.T, cfg *config.TestConfig, secure, namespaceMirroring bool) {
14144
cmd := exec.Command("helm", "repo", "add", "hashicorp", "https://helm.releases.hashicorp.com")
15145
output, err := cmd.CombinedOutput()
16-
require.NoErrorf(t, err, "failed to add hashicorp helm repo: %s", string(output))
146+
require.NoErrorf(t, err, "failed to add hashicorp helm repo : %s", string(output))
147+
148+
// Check for any stuck resources in the namespace and force cleanup if necessary
149+
checkAndDeleteNamespace(t)
17150

18151
// FUTURE for some reason NewHelmCluster creates a consul server pod that runs as root which
19152
// isn't allowed in OpenShift. In order to test OpenShift properly, we have to call helm and k8s
@@ -26,7 +159,7 @@ func newOpenshiftCluster(t *testing.T, cfg *config.TestConfig, secure, namespace
26159
assert.NoErrorf(t, err, "failed to delete namespace: %s", string(output))
27160
})
28161

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

31164
cmd = exec.Command("kubectl", "create", "secret", "generic",
32165
"consul-ent-license",
@@ -62,6 +195,7 @@ func newOpenshiftCluster(t *testing.T, cfg *config.TestConfig, secure, namespace
62195
)
63196

64197
output, err = cmd.CombinedOutput()
198+
t.Logf("Output of the helm install command: %s", string(output))
65199
helpers.Cleanup(t, cfg.NoCleanupOnFailure, cfg.NoCleanup, func() {
66200
cmd := exec.Command("helm", "uninstall", "consul", "--namespace", "consul")
67201
output, err := cmd.CombinedOutput()

charts/consul/test/terraform/aks/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ terraform {
1111

1212
provider "azurerm" {
1313
features {}
14+
api_version_override = {
15+
"managedClusters" = "2025-01-01" # Use one of the supported versions from the error message
16+
}
1417
}
1518

1619
provider "local" {}

0 commit comments

Comments
 (0)