diff --git a/backend/apps/common/__init__.py b/backend/apps/common/__init__.py index 10580f01..71ced1ea 100644 --- a/backend/apps/common/__init__.py +++ b/backend/apps/common/__init__.py @@ -8,11 +8,13 @@ log = logging.getLogger(__name__) -def create_app(name=__name__, static_folder="static", cfg: config.Config = None): +def create_app( + name=__name__, static_folder="static", configuration: config.Config = None +): """Create the WSGI app.""" - cfg = config.Config() if cfg is None else cfg + configuration = config.Config() if configuration is None else configuration - app = base.create_app(name, static_folder, cfg) + app = base.create_app(name, static_folder, configuration) # Register the app's blueprints app.register_blueprint(routes_bp) diff --git a/backend/apps/common/routes/delete.py b/backend/apps/common/routes/delete.py index 4d6317c9..e964f4ae 100644 --- a/backend/apps/common/routes/delete.py +++ b/backend/apps/common/routes/delete.py @@ -12,12 +12,14 @@ "/api/namespaces//inferenceservices/", methods=["DELETE"], ) -def delete_inference_service(inference_service, namespace): +def delete_inference_service(namespace, inference_service): """Handle DELETE requests and delete the provided InferenceService.""" - log.info("Deleting InferenceService %s/%s'", namespace, inference_service) - gvk = versions.inference_service_gvk() - api.delete_custom_rsrc(**gvk, name=inference_service, namespace=namespace) + log.info("Deleting InferenceService %s/%s", namespace, inference_service) + group_version_kind = versions.inference_service_group_version_kind() + api.delete_custom_rsrc( + **group_version_kind, name=inference_service, namespace=namespace + ) return api.success_response( "message", - "InferenceService %s/%s successfully deleted." % (namespace, inference_service), + f"InferenceService {namespace}/{inference_service} successfully deleted.", ) diff --git a/backend/apps/common/routes/get.py b/backend/apps/common/routes/get.py index 98305fad..c457c7b3 100644 --- a/backend/apps/common/routes/get.py +++ b/backend/apps/common/routes/get.py @@ -12,18 +12,20 @@ @bp.route("/api/namespaces//inferenceservices") def get_inference_services(namespace): - """Return a list of InferenceService CRs as json objects.""" - gvk = versions.inference_service_gvk() - inference_services = api.list_custom_rsrc(**gvk, namespace=namespace) + """Return a list of InferenceService custom resources as JSON objects.""" + group_version_kind = versions.inference_service_group_version_kind() + inference_services = api.list_custom_rsrc(**group_version_kind, namespace=namespace) return api.success_response("inferenceServices", inference_services["items"]) @bp.route("/api/namespaces//inferenceservices/") def get_inference_service(namespace, name): - """Return an InferenceService CR as a json object.""" + """Return an InferenceService custom resource as a JSON object.""" inference_service = api.get_custom_rsrc( - **versions.inference_service_gvk(), namespace=namespace, name=name + **versions.inference_service_group_version_kind(), + namespace=namespace, + name=name, ) if request.args.get("logs", "false") == "true": # find the logs @@ -39,74 +41,84 @@ def get_inference_service(namespace, name): return api.success_response("inferenceService", inference_service) -def get_inference_service_logs(svc): - """Return all logs for all isvc component pods.""" - namespace = svc["metadata"]["namespace"] +def get_inference_service_logs(inference_service): + """Return logs for each InferenceService component pod.""" + namespace = inference_service["metadata"]["namespace"] components = request.args.getlist("component") log.info(components) # Check deployment mode to determine how to get logs - deployment_mode = utils.get_deployment_mode(svc) + deployment_mode = utils.get_deployment_mode(inference_service) if deployment_mode == "ModelMesh": # For ModelMesh, get logs from modelmesh-serving deployment - component_pods_dict = utils.get_modelmesh_pods(svc, components) + component_pods_dict = utils.get_modelmesh_pods(inference_service, components) elif deployment_mode == "RawDeployment": - component_pods_dict = utils.get_raw_inference_service_pods(svc, components) + component_pods_dict = utils.get_raw_inference_service_pods( + inference_service, components + ) else: # Serverless mode - component_pods_dict = utils.get_inference_service_pods(svc, components) + component_pods_dict = utils.get_inference_service_pods( + inference_service, components + ) if len(component_pods_dict.keys()) == 0: return {} - resp = {} - logging.info("Component pods: %s", component_pods_dict) + logs_by_component = {} + log.info("Component pods: %s", component_pods_dict) for component, pods in component_pods_dict.items(): - if component not in resp: - resp[component] = [] + if component not in logs_by_component: + logs_by_component[component] = [] for pod in pods: logs = api.get_pod_logs(namespace, pod, "kserve-container", auth=False) - resp[component].append({"podName": pod, "logs": logs.split("\n")}) - return resp + logs_by_component[component].append( + {"podName": pod, "logs": logs.split("\n")} + ) + return logs_by_component @bp.route("/api/namespaces//knativeServices/") def get_knative_service(namespace, name): - """Return a Knative Services object as json.""" - svc = api.get_custom_rsrc( + """Return a Knative Service object as JSON.""" + service = api.get_custom_rsrc( **versions.KNATIVE_SERVICE, namespace=namespace, name=name ) - return api.success_response("knativeService", svc) + return api.success_response("knativeService", service) @bp.route("/api/namespaces//configurations/") def get_knative_configuration(namespace, name): - """Return a Knative Configurations object as json.""" - svc = api.get_custom_rsrc(**versions.KNATIVE_CONF, namespace=namespace, name=name) + """Return a Knative Configuration object as JSON.""" + configuration = api.get_custom_rsrc( + **versions.KNATIVE_CONFIGURATION, namespace=namespace, name=name + ) - return api.success_response("knativeConfiguration", svc) + return api.success_response("knativeConfiguration", configuration) @bp.route("/api/namespaces//revisions/") def get_knative_revision(namespace, name): - """Return a Knative Revision object as json.""" - svc = api.get_custom_rsrc( + """Return a Knative Revision object as JSON.""" + revision = api.get_custom_rsrc( **versions.KNATIVE_REVISION, namespace=namespace, name=name ) - return api.success_response("knativeRevision", svc) + return api.success_response("knativeRevision", revision) @bp.route("/api/namespaces//routes/") def get_knative_route(namespace, name): - """Return a Knative Route object as json.""" - svc = api.get_custom_rsrc(**versions.KNATIVE_ROUTE, namespace=namespace, name=name) + """Return a Knative Route object as JSON.""" + route = api.get_custom_rsrc( + **versions.KNATIVE_ROUTE, namespace=namespace, name=name + ) - return api.success_response("knativeRoute", svc) + return api.success_response("knativeRoute", route) @bp.route("/api/namespaces//inferenceservices//events") @@ -125,27 +137,33 @@ def get_inference_service_events(namespace, name): # RawDeployment mode endpoints @bp.route("/api/namespaces//deployments/") def get_kubernetes_deployment(namespace, name): - """Return a Kubernetes Deployment object as json.""" + """Return a Kubernetes Deployment object as JSON.""" deployment = api.get_custom_rsrc( - **versions.K8S_DEPLOYMENT, namespace=namespace, name=name + **versions.KUBERNETES_DEPLOYMENT_RESOURCE, + namespace=namespace, + name=name, ) return api.success_response("deployment", deployment) @bp.route("/api/namespaces//services/") def get_kubernetes_service(namespace, name): - """Return a Kubernetes Service object as json.""" + """Return a Kubernetes Service object as JSON.""" service = api.get_custom_rsrc( - **versions.K8S_SERVICE, namespace=namespace, name=name + **versions.KUBERNETES_SERVICE_RESOURCE, + namespace=namespace, + name=name, ) return api.success_response("service", service) @bp.route("/api/namespaces//hpas/") def get_kubernetes_hpa(namespace, name): - """Return a Kubernetes HPA object as json.""" - hpa = api.get_custom_rsrc(**versions.K8S_HPA, namespace=namespace, name=name) - return api.success_response("hpa", hpa) + """Return a Kubernetes HorizontalPodAutoscaler object as JSON.""" + horizontal_pod_autoscaler = api.get_custom_rsrc( + **versions.KUBERNETES_HPA_RESOURCE, namespace=namespace, name=name + ) + return api.success_response("hpa", horizontal_pod_autoscaler) @bp.route( @@ -155,7 +173,9 @@ def get_raw_deployment_objects(namespace, name, component): """Return all Kubernetes native resources for a RawDeployment component.""" inference_service = api.get_custom_rsrc( - **versions.inference_service_gvk(), namespace=namespace, name=name + **versions.inference_service_group_version_kind(), + namespace=namespace, + name=name, ) if not utils.is_raw_deployment(inference_service): @@ -172,7 +192,9 @@ def get_modelmesh_objects(namespace, name, component): """Return all ModelMesh-specific resources for a ModelMesh component.""" inference_service = api.get_custom_rsrc( - **versions.inference_service_gvk(), namespace=namespace, name=name + **versions.inference_service_group_version_kind(), + namespace=namespace, + name=name, ) if not utils.is_modelmesh_deployment(inference_service): diff --git a/backend/apps/common/utils.py b/backend/apps/common/utils.py index 4ac9478c..c6dedbe2 100644 --- a/backend/apps/common/utils.py +++ b/backend/apps/common/utils.py @@ -8,10 +8,10 @@ log = logging.getLogger(__name__) KNATIVE_REVISION_LABEL = "serving.knative.dev/revision" -FILE_ABS_PATH = os.path.abspath(os.path.dirname(__file__)) +ABSOLUTE_FILE_PATH = os.path.abspath(os.path.dirname(__file__)) -INFERENCESERVICE_TEMPLATE_YAML = os.path.join( - FILE_ABS_PATH, "yaml", "inference_service_template.yaml" +INFERENCE_SERVICE_TEMPLATE_YAML = os.path.join( + ABSOLUTE_FILE_PATH, "yaml", "inference_service_template.yaml" ) @@ -24,21 +24,21 @@ def load_inference_service_template(**kwargs): kwargs: the parameters to be replaced in the yaml """ - return helpers.load_param_yaml(INFERENCESERVICE_TEMPLATE_YAML, **kwargs) + return helpers.load_param_yaml(INFERENCE_SERVICE_TEMPLATE_YAML, **kwargs) # helper functions for accessing the logs of an InferenceService in raw # kubernetes mode -def get_raw_inference_service_pods(svc, components=[]): +def get_raw_inference_service_pods(inference_service, components=[]): """ Return a dictionary with (endpoint, component) keys i.e. ("default", "predictor") and a list of pod names as values """ - namespace = svc["metadata"]["namespace"] - svc_name = svc["metadata"]["name"] - label_selector = "serving.kubeflow.org/inferenceservice={}".format(svc_name) + namespace = inference_service["metadata"]["namespace"] + service_name = inference_service["metadata"]["name"] + label_selector = "serving.kubeflow.org/inferenceservice={}".format(service_name) pods = api.v1_core.list_namespaced_pod( namespace, label_selector=label_selector ).items @@ -48,12 +48,15 @@ def get_raw_inference_service_pods(svc, components=[]): if component not in components: continue - curr_pod_names = component_pods_dict.get(component, []) - curr_pod_names.append(pod.metadata.name) - component_pods_dict[component] = curr_pod_names + current_pod_names = component_pods_dict.get(component, []) + current_pod_names.append(pod.metadata.name) + component_pods_dict[component] = current_pod_names if len(component_pods_dict.keys()) == 0: - log.info("No pods are found for inference service: %s", svc["metadata"]["name"]) + log.info( + "No pods are found for inference service: %s", + inference_service["metadata"]["name"], + ) return component_pods_dict @@ -61,17 +64,17 @@ def get_raw_inference_service_pods(svc, components=[]): # helper functions for accessing the logs of an InferenceService -def get_inference_service_pods(svc, components=[]): +def get_inference_service_pods(inference_service, components=[]): """ - Return the Pod names for the different isvc components. + Return the Pod names for the different InferenceService components. Return a dictionary with (endpoint, component) keys, i.e. ("default", "predictor") and a list of pod names as values """ - namespace = svc["metadata"]["namespace"] + namespace = inference_service["metadata"]["namespace"] # dictionary{revisionName: (endpoint, component)} - revisions_dict = get_components_revisions_dict(components, svc) + revisions_dict = get_components_revisions_dict(components, inference_service) if len(revisions_dict.keys()) == 0: return {} @@ -87,24 +90,27 @@ def get_inference_service_pods(svc, components=[]): continue component = revisions_dict[revision] - curr_pod_names = component_pods_dict.get(component, []) - curr_pod_names.append(pod.metadata.name) - component_pods_dict[component] = curr_pod_names + current_pod_names = component_pods_dict.get(component, []) + current_pod_names.append(pod.metadata.name) + component_pods_dict[component] = current_pod_names if len(component_pods_dict.keys()) == 0: - log.info("No pods are found for inference service: %s", svc["metadata"]["name"]) + log.info( + "No pods are found for inference service: %s", + inference_service["metadata"]["name"], + ) return component_pods_dict -def get_modelmesh_pods(svc, components=[]): +def get_modelmesh_pods(inference_service, components=[]): """ Return a dictionary with component keys and ModelMesh pod names as values. For ModelMesh deployments, logs are typically found in the ModelMesh controller managed pods. """ - namespace = svc["metadata"]["namespace"] + namespace = inference_service["metadata"]["namespace"] # Use label selector to find ModelMesh pods label_selector = "app.kubernetes.io/managed-by=modelmesh-controller" @@ -125,7 +131,8 @@ def get_modelmesh_pods(svc, components=[]): if len(component_pods_dict.keys()) == 0: log.info( - "No ModelMesh pods found for inference service: %s", svc["metadata"]["name"] + "No ModelMesh pods found for inference service: %s", + inference_service["metadata"]["name"], ) return component_pods_dict @@ -133,9 +140,9 @@ def get_modelmesh_pods(svc, components=[]): # FIXME(elikatsis,kimwnasptd): Change the logic of this function according to # https://github.com/arrikto/dev/issues/867 -def get_components_revisions_dict(components, svc): +def get_components_revisions_dict(components, inference_service): """Return a dictionary{revisionId: component}.""" - status = svc["status"] + status = inference_service["status"] revisions_dict = {} for component in components: @@ -143,7 +150,7 @@ def get_components_revisions_dict(components, svc): log.info( "Component '%s' not in inference service '%s'", component, - svc["metadata"]["name"], + inference_service["metadata"]["name"], ) continue @@ -151,7 +158,7 @@ def get_components_revisions_dict(components, svc): log.info( "Component '%s' not in inference service '%s'", component, - svc["metadata"]["name"], + inference_service["metadata"]["name"], ) continue @@ -163,19 +170,19 @@ def get_components_revisions_dict(components, svc): if len(revisions_dict.keys()) == 0: log.info( "No revisions found for the inference service's components: %s", - svc["metadata"]["name"], + inference_service["metadata"]["name"], ) return revisions_dict -def is_raw_deployment(svc): +def is_raw_deployment(inference_service): """ Check if an InferenceService is using RawDeployment mode. Returns True if the service uses RawDeployment, False for Serverless mode. """ - annotations = svc.get("metadata", {}).get("annotations", {}) + annotations = inference_service.get("metadata", {}).get("annotations", {}) # Check for the new KServe annotation deployment_mode = annotations.get("serving.kserve.io/deploymentMode", "") @@ -190,43 +197,44 @@ def is_raw_deployment(svc): return False -def is_modelmesh_deployment(svc): +def is_modelmesh_deployment(inference_service): """ Check if an InferenceService is using ModelMesh mode. Returns True if the service uses ModelMesh deployment mode. """ - annotations = svc.get("metadata", {}).get("annotations", {}) + annotations = inference_service.get("metadata", {}).get("annotations", {}) deployment_mode = annotations.get("serving.kserve.io/deploymentMode", "") return deployment_mode.lower() == "modelmesh" -def get_deployment_mode(svc): +def get_deployment_mode(inference_service): """ Get the deployment mode of an InferenceService. Returns one of: "ModelMesh", "RawDeployment", "Serverless" """ - if is_modelmesh_deployment(svc): + if is_modelmesh_deployment(inference_service): return "ModelMesh" - elif is_raw_deployment(svc): + elif is_raw_deployment(inference_service): return "RawDeployment" else: return "Serverless" -def get_raw_deployment_objects(svc, component): +def get_raw_deployment_objects(inference_service, component): """ Get Kubernetes native resources for a RawDeployment InferenceService component. - Returns a dictionary with deployment, service, and hpa objects. + Returns a dictionary with deployment, service, and HorizontalPodAutoscaler + (HPA) objects. """ - namespace = svc["metadata"]["namespace"] - svc_name = svc["metadata"]["name"] + namespace = inference_service["metadata"]["namespace"] + service_name = inference_service["metadata"]["name"] - # RawDeployment resources follow naming convention: {isvc-name}-{component} - resource_name = f"{svc_name}-{component}" + # RawDeployment resources follow naming convention: {inference-service-name}-{component} + resource_name = f"{service_name}-{component}" objects = { "deployment": None, @@ -237,7 +245,9 @@ def get_raw_deployment_objects(svc, component): try: # Get Deployment deployment = api.get_custom_rsrc( - **versions.K8S_DEPLOYMENT, namespace=namespace, name=resource_name + **versions.KUBERNETES_DEPLOYMENT_RESOURCE, + namespace=namespace, + name=resource_name, ) objects["deployment"] = deployment log.info(f"Found deployment {resource_name} for component {component}") @@ -247,7 +257,9 @@ def get_raw_deployment_objects(svc, component): try: # Get Service service = api.get_custom_rsrc( - **versions.K8S_SERVICE, namespace=namespace, name=resource_name + **versions.KUBERNETES_SERVICE_RESOURCE, + namespace=namespace, + name=resource_name, ) objects["service"] = service log.info(f"Found service {resource_name} for component {component}") @@ -255,23 +267,27 @@ def get_raw_deployment_objects(svc, component): log.warning(f"Could not find service {resource_name}: {e}") try: - # Get HPA (optional) - hpa = api.get_custom_rsrc( - **versions.K8S_HPA, namespace=namespace, name=resource_name + # Get HorizontalPodAutoscaler (optional) + horizontal_pod_autoscaler = api.get_custom_rsrc( + **versions.KUBERNETES_HPA_RESOURCE, + namespace=namespace, + name=resource_name, + ) + objects["hpa"] = horizontal_pod_autoscaler + log.info( + f"Found HorizontalPodAutoscaler {resource_name} for component {component}" ) - objects["hpa"] = hpa - log.info(f"Found HPA {resource_name} for component {component}") except Exception as e: - log.debug(f"No HPA found for {resource_name}: {e}") + log.debug(f"No HorizontalPodAutoscaler found for {resource_name}: {e}") return objects -def get_modelmesh_objects(svc, component): +def get_modelmesh_objects(inference_service, component): """ Get ModelMesh-specific resources for an InferenceService component. """ - namespace = svc["metadata"]["namespace"] + namespace = inference_service["metadata"]["namespace"] objects = { "predictor": None, "servingRuntime": None, @@ -280,17 +296,19 @@ def get_modelmesh_objects(svc, component): } # 1. Get predictor status - if "status" in svc and "components" in svc.get("status", {}): - objects["predictor"] = svc["status"]["components"].get(component) + if "status" in inference_service and "components" in inference_service.get( + "status", {} + ): + objects["predictor"] = inference_service["status"]["components"].get(component) # 2. Determine the ServingRuntime name (early exit if not found) - runtime_name = _extract_serving_runtime_name(svc, component) + runtime_name = _extract_serving_runtime_name(inference_service, component) if not runtime_name: log.warning(f"Could not determine ServingRuntime for component {component}") return objects # 3. Get the ServingRuntime object - objects["servingRuntime"] = _get_k8s_object( + objects["servingRuntime"] = _get_kubernetes_object( namespace=namespace, name=runtime_name, group="serving.kserve.io", @@ -305,19 +323,23 @@ def get_modelmesh_objects(svc, component): log.info(f"Constructed ModelMesh resource name: {resource_name}") # 5. Get the Deployment and Service by their specific names - objects["deployment"] = _get_k8s_object( - namespace=namespace, name=resource_name, **versions.K8S_DEPLOYMENT + objects["deployment"] = _get_kubernetes_object( + namespace=namespace, + name=resource_name, + **versions.KUBERNETES_DEPLOYMENT_RESOURCE, ) - objects["service"] = _get_k8s_object( - namespace=namespace, name=resource_name, **versions.K8S_SERVICE + objects["service"] = _get_kubernetes_object( + namespace=namespace, + name=resource_name, + **versions.KUBERNETES_SERVICE_RESOURCE, ) return objects -def _extract_serving_runtime_name(svc, component): +def _extract_serving_runtime_name(inference_service, component): """Extract the ServingRuntime name from an InferenceService spec.""" - component_spec = svc.get("spec", {}).get(component, {}) + component_spec = inference_service.get("spec", {}).get(component, {}) if not component_spec: return None @@ -334,7 +356,7 @@ def _get_modelmesh_service_name(): return default_name -def _get_k8s_object(namespace, name, group, version, kind): +def _get_kubernetes_object(namespace, name, group, version, kind): """A generic helper to get any single Kubernetes resource by its name.""" try: resource = api.get_custom_rsrc( diff --git a/backend/apps/common/versions.py b/backend/apps/common/versions.py index 90071f1b..91d4fd50 100644 --- a/backend/apps/common/versions.py +++ b/backend/apps/common/versions.py @@ -1,4 +1,4 @@ -"""Helpers with GVK needed, stored in one place.""" +"""Helpers with Kubernetes group/version/kind mappings stored in one place.""" from flask import current_app @@ -8,7 +8,7 @@ "version": "v1", "kind": "revisions", } -KNATIVE_CONF = { +KNATIVE_CONFIGURATION = { "group": "serving.knative.dev", "version": "v1", "kind": "configurations", @@ -16,14 +16,22 @@ KNATIVE_SERVICE = {"group": "serving.knative.dev", "version": "v1", "kind": "services"} # Kubernetes native resources for RawDeployment mode -K8S_DEPLOYMENT = {"group": "apps", "version": "v1", "kind": "deployments"} -K8S_SERVICE = {"group": "", "version": "v1", "kind": "services"} -K8S_HPA = {"group": "autoscaling", "version": "v2", "kind": "horizontalpodautoscalers"} +KUBERNETES_DEPLOYMENT_RESOURCE = { + "group": "apps", + "version": "v1", + "kind": "deployments", +} +KUBERNETES_SERVICE_RESOURCE = {"group": "", "version": "v1", "kind": "services"} +KUBERNETES_HPA_RESOURCE = { + "group": "autoscaling", + "version": "v2", + "kind": "horizontalpodautoscalers", +} -def inference_service_gvk(): +def inference_service_group_version_kind(): """ - Return the GVK needed for an InferenceService. + Return the Kubernetes group/version/kind mapping for an InferenceService. This also checks the APP_VERSION env var to detect the version. """ diff --git a/backend/apps/v1beta1/__init__.py b/backend/apps/v1beta1/__init__.py index ec40c2c7..cbc04991 100644 --- a/backend/apps/v1beta1/__init__.py +++ b/backend/apps/v1beta1/__init__.py @@ -10,14 +10,14 @@ log = logging.getLogger(__name__) -def create_app(name=__name__, cfg: config.Config = None): +def create_app(name=__name__, configuration: config.Config = None): """Create a WSGI app.""" - cfg = config.Config() if cfg is None else cfg + configuration = config.Config() if configuration is None else configuration # Properly set the static serving directory static_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "static") - app = create_default_app(name, static_dir, cfg) + app = create_default_app(name, static_dir, configuration) log.info("Setting STATIC_DIR to: " + static_dir) app.config["STATIC_DIR"] = static_dir diff --git a/backend/apps/v1beta1/routes/get.py b/backend/apps/v1beta1/routes/get.py index ed294bf1..202e2f53 100644 --- a/backend/apps/v1beta1/routes/get.py +++ b/backend/apps/v1beta1/routes/get.py @@ -14,7 +14,7 @@ def get_config(): """Handle retrieval of application configuration.""" try: - config = { + configuration_payload = { "grafanaPrefix": os.environ.get("GRAFANA_PREFIX", "/grafana"), "grafanaCpuMemoryDb": os.environ.get( "GRAFANA_CPU_MEMORY_DB", @@ -25,8 +25,8 @@ def get_config(): ), } - log.info("Configuration requested: %s", config) - return jsonify(config) + log.info("Configuration requested: %s", configuration_payload) + return jsonify(configuration_payload) except Exception as e: log.error("Error retrieving configuration: %s", str(e)) return api.error_response("message", "Failed to retrieve configuration"), 500 diff --git a/backend/apps/v1beta1/routes/post.py b/backend/apps/v1beta1/routes/post.py index 034eda69..2fa415df 100644 --- a/backend/apps/v1beta1/routes/post.py +++ b/backend/apps/v1beta1/routes/post.py @@ -15,9 +15,11 @@ @decorators.required_body_params("apiVersion", "kind", "metadata", "spec") def post_inference_service(namespace): """Handle creation of an InferenceService.""" - cr = request.get_json() + custom_resource = request.get_json() - gvk = versions.inference_service_gvk() - api.create_custom_rsrc(**gvk, data=cr, namespace=namespace) + group_version_kind = versions.inference_service_group_version_kind() + api.create_custom_rsrc( + **group_version_kind, data=custom_resource, namespace=namespace + ) return api.success_response("message", "InferenceService successfully created.") diff --git a/backend/apps/v1beta1/routes/put.py b/backend/apps/v1beta1/routes/put.py index 6025d2fe..34f35dec 100644 --- a/backend/apps/v1beta1/routes/put.py +++ b/backend/apps/v1beta1/routes/put.py @@ -8,28 +8,31 @@ log = logging.getLogger(__name__) -@bp.route("/api/namespaces//inferenceservices/", methods=["PUT"]) +@bp.route( + "/api/namespaces//inferenceservices/", + methods=["PUT"], +) @decorators.request_is_json_type @decorators.required_body_params("apiVersion", "kind", "metadata", "spec") -def replace_inference_service(namespace: str, isvc: str): - gvk = versions.inference_service_gvk() +def replace_inference_service(namespace: str, inference_service_name: str): + group_version_kind = versions.inference_service_group_version_kind() api.authz.ensure_authorized( "update", - group=gvk["group"], - version=gvk["version"], - resource=gvk["kind"], + group=group_version_kind["group"], + version=group_version_kind["version"], + resource=group_version_kind["kind"], namespace=namespace, ) - cr = request.get_json() + custom_resource = request.get_json() api.custom_api.replace_namespaced_custom_object( - group=gvk["group"], - version=gvk["version"], - plural=gvk["kind"], + group=group_version_kind["group"], + version=group_version_kind["version"], + plural=group_version_kind["kind"], namespace=namespace, - name=isvc, - body=cr, + name=inference_service_name, + body=custom_resource, ) return api.success_response("message", "InferenceService successfully updated") diff --git a/backend/entrypoint.py b/backend/entrypoint.py index d4f44e7c..c538036c 100755 --- a/backend/entrypoint.py +++ b/backend/entrypoint.py @@ -24,13 +24,13 @@ "GRAFANA_HTTP_REQUESTS_DB", "db/knative-serving-revision-http-requests" ) -cfg = config.get_config(BACKEND_MODE) -cfg.PREFIX = PREFIX -cfg.APP_VERSION = APP_VERSION +backend_configuration = config.get_config(BACKEND_MODE) +backend_configuration.PREFIX = PREFIX +backend_configuration.APP_VERSION = APP_VERSION # Load the app based on APP_VERSION env var if APP_VERSION == "v1beta1": - app = v1beta1.create_app(APP_NAME, cfg) + app = v1beta1.create_app(APP_NAME, backend_configuration) else: log.error("No app for: %s", APP_VERSION) sys.exit(1)