Skip to content

Commit b7c8d5c

Browse files
committed
Modified namespace optional test file
1 parent 4472c8b commit b7c8d5c

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

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

Lines changed: 7 additions & 6 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
97+
python test/integration/k8s-deploy-test.py namespace=test-namespace kind=Deployment name=test-deployment containerName=nginx labels=app:test-app selectorLabels=app:test-app
9898
99-
- name: Verify deployment in default namespace
99+
- name: Verify deployment in default namespace (test_no_ns.yaml)
100100
run: |
101-
python test/integration/k8s-deploy-test.py namespace=default kind=Deployment name=test-deployment-no-ns
101+
python test/integration/k8s-deploy-test.py namespace=default kind=Deployment name=test-deployment-no-ns containerName=nginx labels=app:test-app selectorLabels=app:test-app
102102
103103
- name: Test - Deploys the same resource to two different namespaces without conflict
104104
uses: ./
@@ -111,17 +111,18 @@ 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
115-
python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE2 }} kind=Deployment name=test-deployment-no-ns
114+
python test/integration/k8s-deploy-test.py namespace=${{ env.NAMESPACE1 }} kind=Deployment name=test-deployment-no-ns containerName=nginx 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 labels=app:test-app selectorLabels=app:test-app
116116
117117
- name: Cleanup
118118
run: |
119119
echo "Cleaning up resources..."
120-
python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment' ${{ env.NAMESPACE1 }}
120+
python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment' test-namespace
121121
python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment-no-ns' ${{ env.NAMESPACE1 }}
122122
python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment-no-ns' ${{ env.NAMESPACE2 }}
123123
python test/integration/k8s-deploy-delete.py 'Deployment' 'test-deployment-no-ns' default
124124
125125
kubectl delete ns ${{ env.NAMESPACE1 }}
126126
kubectl delete ns ${{ env.NAMESPACE2 }}
127+
kubectl delete ns test-namespace
127128
rm -rf test_with_ns.yaml test_no_ns.yaml

test/integration/k8s-deploy-test.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,6 @@ 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-
219198
def main():
220199
parsedArgs: dict = parseArgs(sys.argv[1:])
221200
RESULT = False
@@ -258,8 +237,8 @@ def main():
258237
sys.exit(msg + " " + suffix)
259238

260239
if kind == 'Deployment':
261-
verify_deployment_namespace(namespace, kind, name)
262-
RESULT, msg = verifyDeployment(k8_object, parsedArgs)
240+
RESULT, msg = verifyDeployment(
241+
k8_object, parsedArgs)
263242
if kind == 'Service':
264243
RESULT, msg = verifyService(
265244
k8_object, parsedArgs)
@@ -275,4 +254,4 @@ def main():
275254

276255

277256
if __name__ == "__main__":
278-
sys.exit(main())
257+
sys.exit(main())

0 commit comments

Comments
 (0)