Skip to content

Commit 4472c8b

Browse files
committed
Fixed integration tests issue
1 parent 976c922 commit 4472c8b

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

.github/workflows/run-integration-tests-namespace-optional.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ jobs:
9494

9595
- name: Verify deployment in namespace1
9696
run: |
97-
python test/integration/k8s-deploy-test.py namespace=test-namespace kind=Deployment name=test-deployment containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app
97+
python test/integration/k8s-deploy-test.py namespace=test-namespace kind=Deployment name=test-deployment
9898
9999
- name: Verify deployment in default namespace
100100
run: |
101-
python test/integration/k8s-deploy-test.py namespace=default kind=Deployment name=test-deployment-no-ns containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app
101+
python test/integration/k8s-deploy-test.py namespace=default kind=Deployment name=test-deployment-no-ns
102102
103103
- name: Test - Deploys the same resource to two different namespaces without conflict
104104
uses: ./
@@ -111,8 +111,8 @@ jobs:
111111

112112
- name: Verify deployment in namespace2
113113
run: |
114-
python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE1 }} kind=Deployment name=test-deployment-no-ns containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app
115-
python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE2 }} kind=Deployment name=test-deployment-no-ns containerName=nginx:1.14.2 labels=app:test-app selectorLabels=app:test-app
114+
python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE1 }} kind=Deployment name=test-deployment-no-ns
115+
python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE2 }} kind=Deployment name=test-deployment-no-ns
116116
117117
- name: Cleanup
118118
run: |

test/integration/k8s-deploy-test.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ def validateKeyPresence(actualDict: dict, expectedKeys: list):
195195

196196
return True, ""
197197

198+
def verify_deployment_namespace(namespace, kind, name):
199+
try:
200+
# Retrieve the deployment
201+
result = subprocess.run(
202+
["kubectl", "get", kind, name, "-n", namespace, "-o", "jsonpath={.metadata.namespace}"],
203+
capture_output=True,
204+
text=True,
205+
check=True
206+
)
207+
actual_namespace = result.stdout.strip()
208+
209+
# Check if the namespace matches the expected namespace
210+
if actual_namespace == namespace:
211+
print(f"Deployment {name} is in the expected namespace: {namespace}")
212+
else:
213+
print(f"Deployment {name} is in the wrong namespace: {actual_namespace}. Expected: {namespace}")
214+
sys.exit(1)
215+
except subprocess.CalledProcessError as e:
216+
print(f"Failed to retrieve deployment {name} in namespace {namespace}: {e.stderr}")
217+
sys.exit(1)
218+
198219
def main():
199220
parsedArgs: dict = parseArgs(sys.argv[1:])
200221
RESULT = False
@@ -237,8 +258,8 @@ def main():
237258
sys.exit(msg + " " + suffix)
238259

239260
if kind == 'Deployment':
240-
RESULT, msg = verifyDeployment(
241-
k8_object, parsedArgs)
261+
verify_deployment_namespace(namespace, kind, name)
262+
RESULT, msg = verifyDeployment(k8_object, parsedArgs)
242263
if kind == 'Service':
243264
RESULT, msg = verifyService(
244265
k8_object, parsedArgs)

0 commit comments

Comments
 (0)