Skip to content

Commit

Permalink
Wait if all CRDs are created in created_crd function
Browse files Browse the repository at this point in the history
  • Loading branch information
meffmadd committed Jul 29, 2024
1 parent 500516b commit b5a747f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/operator_tests/test_config_server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import kubernetes
from kubernetes import watch
from kubernetes.client import ApiClient, CustomObjectsApi, CoreV1Api, V1ConfigMap, V1Volume, V1Pod
from kubernetes.client import ApiClient, CustomObjectsApi, CoreV1Api, V1ConfigMap, V1Volume, V1Pod, ApiextensionsV1Api
from kopf.testing import KopfRunner

from . import random_namespace, operator_file
Expand Down Expand Up @@ -40,10 +40,10 @@ def test_config_server_custom_resource(random_namespace, operator_file):
config_map_watch = watch.Watch()
config_server_stream = config_server_watch.stream(custom_objects_api.list_namespaced_custom_object,
"datalab.tuwien.ac.at", "v1", random_namespace,
"configservers")
"configservers", timeout_seconds=30)
pod_stream = pod_watch.stream(core_api.list_namespaced_pod, random_namespace, timeout_seconds=30)
config_map_stream = config_map_watch.stream(core_api.list_namespaced_config_map, random_namespace,
timeout_seconds=10)
timeout_seconds=30)

create_config_server(client, random_namespace)

Expand Down
24 changes: 22 additions & 2 deletions tests/operator_tests/test_crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,35 @@
import pytest
import kubernetes
from kubernetes.client import ApiClient, ApiextensionsV1Api, V1CustomResourceDefinition
from kubernetes import utils
from kubernetes import utils, watch


def create_crd(client: ApiClient):
def _create_crd(client: ApiClient):
yaml_file = os.path.join(os.path.dirname(__file__), '../../opr/crd.yaml')
assert os.path.exists(yaml_file)
utils.create_from_yaml(client, yaml_file)


def create_crd(client: ApiClient):
extensions_api = ApiextensionsV1Api(api_client=client)

config_server_crds = ["configservers.datalab.tuwien.ac.at", "keyvaluepairs.datalab.tuwien.ac.at"]

crd_watch = watch.Watch()
crd_stream = crd_watch.stream(extensions_api.list_custom_resource_definition, timeout_seconds=30)

_create_crd(client)

created_crds = set()
for event in crd_stream:
obj = event['object']
if obj.metadata.name in config_server_crds:
created_crds.add(obj.metadata.name)

if created_crds.issubset(config_server_crds):
crd_watch.stop()


def test_create_crd():
client = ApiClient(configuration=kubernetes.config.load_kube_config())
extensions_api = ApiextensionsV1Api(api_client=client)
Expand Down
7 changes: 4 additions & 3 deletions tests/operator_tests/test_key_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ def test_key_value_custom_resource_before_server(random_namespace, operator_file
config_map_watch = watch.Watch()

key_value_stream = key_value_watch.stream(custom_objects_api.list_namespaced_custom_object,
"datalab.tuwien.ac.at", "v1", random_namespace, "keyvaluepairs")
"datalab.tuwien.ac.at", "v1", random_namespace, "keyvaluepairs",
timeout_seconds=30)
config_server_stream = config_server_watch.stream(custom_objects_api.list_namespaced_custom_object,
"datalab.tuwien.ac.at", "v1", random_namespace,
"configservers")
"configservers", timeout_seconds=30)
config_map_stream = config_map_watch.stream(core_api.list_namespaced_config_map, random_namespace,
timeout_seconds=10)
timeout_seconds=30)

create_key_value_pair(client, random_namespace)

Expand Down

0 comments on commit b5a747f

Please sign in to comment.