Skip to content

Commit

Permalink
remove namespace from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyler-W committed Jan 6, 2025
1 parent 16dc195 commit e9e09a9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 79 deletions.
5 changes: 1 addition & 4 deletions conformance/cluster-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apiVersion: clustersecret.io/v1
kind: ClusterSecret
metadata:
name: basic-cluster-secret
namespace: example-1
data:
username: MTIzNDU2Cg==
password: MTIzNDU2Cg==
Expand All @@ -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==
Expand All @@ -21,7 +19,6 @@ apiVersion: clustersecret.io/v1
kind: ClusterSecret
metadata:
name: basic-cluster-secret
namespace: example-1
avoidNamespaces:
- example-3
---
---
3 changes: 1 addition & 2 deletions conformance/k8s_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions conformance/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
},
)

Expand Down Expand Up @@ -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']
},
)
Expand Down
70 changes: 0 additions & 70 deletions src/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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"},
Expand All @@ -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,
)
Expand Down Expand Up @@ -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"},
Expand All @@ -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,
)
Expand All @@ -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.
Expand All @@ -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"],
)
Expand Down Expand Up @@ -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,
)

0 comments on commit e9e09a9

Please sign in to comment.