def view_endpoint(endpoint_name: str, namespace: str, id_token: str): if not tenant_exists(namespace, id_token=id_token): raise TenantDoesNotExistException(tenant_name=namespace) if not endpoint_exists(endpoint_name, namespace, id_token): raise EndpointDoesNotExistException(endpoint_name=endpoint_name) custom_api_instance = get_k8s_api_custom_client(id_token) api_instance = get_k8s_api_client(id_token) apps_api_instance = get_k8s_apps_api_client(id_token) endpoint_status = get_endpoint_status(api_instance=api_instance, namespace=namespace, endpoint_name=endpoint_name) model_path = create_url_to_service(endpoint_name, namespace) subject_name, resources = get_crd_subject_name_and_resources( custom_api_instance=custom_api_instance, namespace=namespace, endpoint_name=endpoint_name) replicas = get_replicas(apps_api_instance=apps_api_instance, namespace=namespace, endpoint_name=endpoint_name) view_dict = {'Endpoint status': endpoint_status, 'Model path': model_path, 'Subject name': subject_name, 'Resources': resources, 'Replicas': replicas, } message = f"Endpoint {endpoint_name} in {namespace} tenant: {view_dict}\n" logger.info(message) return message
def create_endpoint(parameters: dict, namespace: str, id_token: str): if not tenant_exists(namespace, id_token=id_token): raise TenantDoesNotExistException(tenant_name=namespace) metadata = {"name": parameters['endpointName']} body = {"apiVersion": CRD_API_VERSION, "kind": CRD_KIND, "spec": parameters, "metadata": metadata} api_instance = get_k8s_api_client(id_token) if 'resources' in parameters: validate_quota_compliance(api_instance, namespace=namespace, endpoint_quota=parameters['resources']) parameters['resources'] = transform_quota(parameters['resources']) apps_api_instance = get_k8s_apps_api_client(id_token) verify_endpoint_amount(api_instance, apps_api_instance, namespace) custom_obj_api_instance = get_k8s_api_custom_client(id_token) try: custom_obj_api_instance.create_namespaced_custom_object(CRD_GROUP, CRD_VERSION, namespace, CRD_PLURAL, body) except ApiException as apiException: raise KubernetesCreateException('endpoint', apiException) endpoint_url = create_url_to_service(parameters['endpointName'], namespace) logger.info('Endpoint {} created\n'.format(endpoint_url)) return endpoint_url
def update_endpoint(parameters: dict, namespace: str, endpoint_name: str, id_token: str): custom_obj_api_instance = get_k8s_api_custom_client(id_token) try: endpoint_object = custom_obj_api_instance. \ get_namespaced_custom_object(CRD_GROUP, CRD_VERSION, namespace, CRD_PLURAL, endpoint_name) except ApiException as apiException: raise KubernetesGetException('endpoint', apiException) if 'modelName' in parameters: endpoint_object['spec']['modelName'] = parameters['modelName'] if 'modelVersionPolicy' in parameters: endpoint_object['spec']['modelVersionPolicy'] = \ normalize_version_policy(parameters['modelVersionPolicy']) if 'resources' in parameters: endpoint_object['spec']['resources'] = transform_quota( parameters['resources']) if 'subjectName' in parameters: endpoint_object['spec']['subjectName'] = parameters['subjectName'] try: custom_obj_api_instance.patch_namespaced_custom_object( CRD_GROUP, CRD_VERSION, namespace, CRD_PLURAL, endpoint_name, endpoint_object) except ApiException as apiException: raise KubernetesUpdateException('endpoint', apiException) endpoint_url = create_url_to_service(endpoint_name, namespace) return endpoint_url
def delete_endpoint(parameters: dict, namespace: str, id_token: str): custom_obj_api_instance = get_k8s_api_custom_client(id_token) try: custom_obj_api_instance.delete_namespaced_custom_object( CRD_GROUP, CRD_VERSION, namespace, CRD_PLURAL, parameters['endpointName'], DELETE_BODY, grace_period_seconds=0) except ApiException as apiException: raise KubernetesDeleteException('endpoint', apiException) endpoint_url = create_url_to_service(parameters['endpointName'], namespace) logger.info('Endpoint {} deleted\n'.format(endpoint_url)) return endpoint_url
def scale_endpoint(parameters: dict, namespace: str, endpoint_name: str, id_token: str): custom_obj_api_instance = get_k8s_api_custom_client(id_token) try: endpoint_object = custom_obj_api_instance. \ get_namespaced_custom_object(CRD_GROUP, CRD_VERSION, namespace, CRD_PLURAL, endpoint_name) except ApiException as apiException: raise KubernetesGetException('endpoint', apiException) endpoint_object['spec']['replicas'] = parameters['replicas'] try: custom_obj_api_instance.patch_namespaced_custom_object( CRD_GROUP, CRD_VERSION, namespace, CRD_PLURAL, endpoint_name, endpoint_object) except ApiException as apiException: raise KubernetesUpdateException('endpoint', apiException) endpoint_url = create_url_to_service(endpoint_name, namespace) return endpoint_url