From b9f2831760ddafe053127a07ae968bed956f41da Mon Sep 17 00:00:00 2001 From: tymuraheiev Date: Sun, 19 Jan 2025 02:37:38 +0200 Subject: [PATCH] Removed unnecessary namespace references from tests --- .gitignore | 1 + conformance/cluster-secrets.yaml | 5 +---- conformance/k8s_utils.py | 3 +-- conformance/tests.py | 3 +-- src/tests/test_handlers.py | 16 +++------------- 5 files changed, 7 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 5a9be51..d8442c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +conformance/__pycache__/ src/__pycache__/ src/tests/__pycache__/ yaml/Object_example/debug-* diff --git a/conformance/cluster-secrets.yaml b/conformance/cluster-secrets.yaml index 9356003..91c4b89 100644 --- a/conformance/cluster-secrets.yaml +++ b/conformance/cluster-secrets.yaml @@ -2,16 +2,14 @@ apiVersion: clustersecret.io/v1 kind: ClusterSecret metadata: name: basic-cluster-secret - namespace: example-1 data: username: MTIzNDU2Cg== password: MTIzNDU2Cg== --- -kind: ClusterSecret apiVersion: clustersecret.io/v1 +kind: ClusterSecret metadata: name: typed-secret - namespace: example-1 type: kubernetes.io/tls data: tls.crt: MTIzNDU2Cg== @@ -21,7 +19,6 @@ apiVersion: clustersecret.io/v1 kind: ClusterSecret metadata: name: basic-cluster-secret - namespace: example-1 avoidNamespaces: - example-3 --- \ No newline at end of file diff --git a/conformance/k8s_utils.py b/conformance/k8s_utils.py index b53394b..92f7dd4 100644 --- a/conformance/k8s_utils.py +++ b/conformance/k8s_utils.py @@ -153,8 +153,7 @@ def update_data_cluster_secret( def delete_cluster_secret( self, - name: str, - namespace: str + name: str ): self.custom_objects_api.delete_cluster_custom_object( name=name, diff --git a/conformance/tests.py b/conformance/tests.py index 0e70577..d58edd0 100644 --- a/conformance/tests.py +++ b/conformance/tests.py @@ -180,8 +180,7 @@ def test_simple_cluster_secret_deleted(self): ) self.cluster_secret_manager.delete_cluster_secret( - name=name, - namespace=USER_NAMESPACES[0], + name=name ) # We expect the secret to be in NO namespaces diff --git a/src/tests/test_handlers.py b/src/tests/test_handlers.py index 6e7cb34..1a6f5b4 100644 --- a/src/tests/test_handlers.py +++ b/src/tests/test_handlers.py @@ -26,7 +26,6 @@ def test_on_field_data_cache(self): csec = BaseClusterSecret( uid="mysecretuid", name="mysecret", - namespace="", body={"metadata": {"name": "mysecret", "uid": "mysecretuid"}, "data": {"key": "oldvalue"}}, synced_namespace=[], ) @@ -42,7 +41,6 @@ def test_on_field_data_cache(self): body=new_body, meta=kopf.Meta({"metadata": {"name": "mysecret"}}), name="mysecret", - namespace=None, uid="mysecretuid", logger=self.logger, ) @@ -75,7 +73,6 @@ def test_on_field_data_sync(self): csec = BaseClusterSecret( uid="mysecretuid", name="mysecret", - namespace="", body={ "metadata": {"name": "mysecret", "uid": "mysecretuid"}, "data": {"key": "oldvalue"}, @@ -100,7 +97,6 @@ def test_on_field_data_sync(self): body=new_body, meta=kopf.Meta({"metadata": {"name": "mysecret"}}), name="mysecret", - namespace=None, uid="mysecretuid", logger=self.logger, ) @@ -203,7 +199,6 @@ def read_namespace(name, **kwargs): csec = BaseClusterSecret( uid="mysecretuid", name="mysecret", - namespace="", body={ "metadata": {"name": "mysecret", "uid": "mysecretuid"}, "data": {"key": "oldvalue"}, @@ -229,7 +224,6 @@ def read_namespace(name, **kwargs): body=new_body, meta=kopf.Meta({"metadata": {"name": "mysecret"}}), name="mysecret", - namespace=None, uid="mysecretuid", logger=self.logger, ) @@ -265,7 +259,6 @@ def test_create_fn(self): body = { "metadata": { "name": "mysecret", - "namespace": "myclustersecretnamespace", "uid": "mysecretuid" }, "data": {"key": "value"} @@ -284,15 +277,14 @@ def test_create_fn(self): logger=self.logger, uid="mysecretuid", name="mysecret", - namespace="myclustersecretnamespace", body=body, ) ) - # ClusterSecret with a correct namespace should be in the cache. + # The secrets should be in all namespaces of the cache. self.assertEqual( - csecs_cache.get_cluster_secret("mysecretuid").namespace, - "myclustersecretnamespace", + csecs_cache.get_cluster_secret("mysecretuid").synced_namespace, + ["default", "myns"], ) def test_ns_create(self): @@ -312,7 +304,6 @@ def test_ns_create(self): csec = BaseClusterSecret( uid="mysecretuid", name="mysecret", - namespace="", body={"metadata": {"name": "mysecret"}, "data": "mydata"}, synced_namespace=["default"], ) @@ -358,7 +349,6 @@ def test_startup_fn(self): csec = BaseClusterSecret( uid="mysecretuid", name="mysecret", - namespace="", body={"metadata": {"name": "mysecret", "uid": "mysecretuid"}, "data": "mydata"}, synced_namespace=[], )