diff --git a/conformance/cluster-secrets.yaml b/conformance/cluster-secrets.yaml index 9356003..39bc380 100644 --- a/conformance/cluster-secrets.yaml +++ b/conformance/cluster-secrets.yaml @@ -2,7 +2,6 @@ apiVersion: clustersecret.io/v1 kind: ClusterSecret metadata: name: basic-cluster-secret - namespace: example-1 data: username: MTIzNDU2Cg== password: MTIzNDU2Cg== @@ -11,7 +10,6 @@ kind: ClusterSecret apiVersion: clustersecret.io/v1 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..d5470b0 100644 --- a/conformance/tests.py +++ b/conformance/tests.py @@ -181,7 +181,6 @@ def test_simple_cluster_secret_deleted(self): self.cluster_secret_manager.delete_cluster_secret( name=name, - namespace=USER_NAMESPACES[0], ) # We expect the secret to be in NO namespaces @@ -212,7 +211,6 @@ def test_value_from_cluster_secret(self): name=cluster_secret_name, secret_key_ref={ 'name': secret_name, - 'namespace': USER_NAMESPACES[0], }, ) @@ -245,7 +243,6 @@ def test_value_from_with_keys_cluster_secret(self): name=cluster_secret_name, secret_key_ref={ 'name': secret_name, - 'namespace': USER_NAMESPACES[0], 'keys': ['username', 'password'] }, ) diff --git a/src/tests/test_handlers.py b/src/tests/test_handlers.py index 6e7cb34..f7359c2 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, ) @@ -256,44 +250,6 @@ def read_namespace(name, **kwargs): ["myns2"], ) - def test_create_fn(self): - """Namespace name must be correct in the cache. - """ - - mock_v1 = Mock() - - body = { - "metadata": { - "name": "mysecret", - "namespace": "myclustersecretnamespace", - "uid": "mysecretuid" - }, - "data": {"key": "value"} - } - - # Define the predefined list of namespaces you want to use in the test - predefined_nss = [Mock(metadata=V1ObjectMeta(name=ns)) for ns in ["default", "myns"]] - - # Configure the mock's behavior to return the predefined namespaces when list_namespace is called - mock_v1.list_namespace.return_value.items = predefined_nss - - with patch("handlers.v1", mock_v1), \ - patch("handlers.sync_secret"): - asyncio.run( - create_fn( - logger=self.logger, - uid="mysecretuid", - name="mysecret", - namespace="myclustersecretnamespace", - body=body, - ) - ) - - # ClusterSecret with a correct namespace should be in the cache. - self.assertEqual( - csecs_cache.get_cluster_secret("mysecretuid").namespace, - "myclustersecretnamespace", - ) def test_ns_create(self): """A new namespace must get the cluster secrets. @@ -312,7 +268,6 @@ def test_ns_create(self): csec = BaseClusterSecret( uid="mysecretuid", name="mysecret", - namespace="", body={"metadata": {"name": "mysecret"}, "data": "mydata"}, synced_namespace=["default"], ) @@ -348,28 +303,3 @@ def test_ns_create(self): csecs_cache.get_cluster_secret("mysecretuid").synced_namespace, ["default", "myns"], ) - - def test_startup_fn(self): - """Must not fail on empty namespace in ClusterSecret metadata (it's cluster-wide after all). - """ - - get_custom_objects_by_kind = Mock() - - csec = BaseClusterSecret( - uid="mysecretuid", - name="mysecret", - namespace="", - body={"metadata": {"name": "mysecret", "uid": "mysecretuid"}, "data": "mydata"}, - synced_namespace=[], - ) - - get_custom_objects_by_kind.return_value = [csec.body] - - with patch("handlers.get_custom_objects_by_kind", get_custom_objects_by_kind): - asyncio.run(startup_fn(logger=self.logger)) - - # The secret should be in the cache. - self.assertEqual( - csecs_cache.get_cluster_secret("mysecretuid"), - csec, - )