def custom_resource_definition(self, request, k8s_version): additional_labels = None if len(request.param) == 2: fiaas_path, expected = request.param elif len(request.param) == 3: fiaas_path, expected, additional_labels = request.param skip_if_crd_not_supported(k8s_version) fiaas_yml = read_yml( request.fspath.dirpath().join("specs").join(fiaas_path).strpath) expected = { kind: read_yml(request.fspath.dirpath().join(path).strpath) for kind, path in expected.items() } name = sanitize_resource_name(fiaas_path) metadata = ObjectMeta(name=name, namespace="default", labels={"fiaas/deployment_id": DEPLOYMENT_ID1}) spec = FiaasApplicationSpec(application=name, image=IMAGE1, config=fiaas_yml, additional_labels=additional_labels) request.addfinalizer(lambda: self._ensure_clean(name, expected)) return name, FiaasApplication(metadata=metadata, spec=spec), expected
def test_bootstrap_crd(self, request, kubernetes, k8s_version, use_docker_for_e2e, kind_logger): with kind_logger(): skip_if_crd_not_supported(k8s_version) CrdWatcher.create_custom_resource_definitions() wait_until(crd_available(kubernetes, timeout=TIMEOUT), "CRD available", RuntimeError, patience=PATIENCE) def prepare_test_case(test_case): name, fiaas_application, expected = self.custom_resource_definition_test_case(*test_case) ensure_resources_not_exists(name, expected, fiaas_application.metadata.namespace) fiaas_application.save() return name, fiaas_application.metadata.namespace, expected expectations = [prepare_test_case(test_case) for test_case in TEST_CASES] exit_code = self.run_bootstrap(request, kubernetes, k8s_version, use_docker_for_e2e) assert exit_code == 0 def success(): all(deploy_successful(name, namespace, expected) for name, namespace, expected in expectations) wait_until(success, "CRD bootstrapping was successful", patience=PATIENCE) for name, namespace, expected in expectations: for kind in expected.keys(): try: kind.delete(name, namespace=namespace) except NotFound: pass # already missing