def create_crd_from_yaml(api_extensions_v1_beta1: ApiextensionsV1beta1Api, yaml_manifest) -> str: """ Create a CRD based on yaml file. :param api_extensions_v1_beta1: ApiextensionsV1beta1Api :param yaml_manifest: an absolute path to file :return: str """ print("Create CRD:") with open(yaml_manifest) as f: dep = yaml.safe_load(f) try: api_extensions_v1_beta1.create_custom_resource_definition(dep) except Exception as ex: # https://github.com/kubernetes-client/python/issues/376 if ex.args[0] == 'Invalid value for `conditions`, must not be `None`': print( "There was an insignificant exception during the CRD creation. Continue..." ) else: pytest.fail(f"An unexpected exception {ex} occurred. Exiting...") print(f"CRD created with name '{dep['metadata']['name']}'") return dep['metadata']['name']
def create_crd(api_extensions_v1_beta1: ApiextensionsV1beta1Api, body) -> None: """ Create a CRD based on a dict :param api_extensions_v1_beta1: ApiextensionsV1beta1Api :param body: a dict """ try: api_extensions_v1_beta1.create_custom_resource_definition(body) except ApiException as api_ex: raise api_ex except Exception as ex: # https://github.com/kubernetes-client/python/issues/376 if ex.args[0] == "Invalid value for `conditions`, must not be `None`": print("There was an insignificant exception during the CRD creation. Continue...") else: pytest.fail(f"An unexpected exception {ex} occurred. Exiting...")