From a5f345828d59062e4e3d54ed80a3b36efde4f7e7 Mon Sep 17 00:00:00 2001 From: Andrew Ballantyne Date: Wed, 18 Oct 2023 15:13:17 -0400 Subject: [PATCH] Expose the DSC status for the client --- backend/src/routes/api/dsc/index.ts | 12 ++++++++++ backend/src/types.ts | 36 ++++++++++++++++++++++++----- backend/src/utils/dsc.ts | 26 +++++++++++++++++++++ frontend/src/k8sTypes.ts | 17 ++++++++++++++ manifests/base/cluster-role.yaml | 8 +++++++ 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 backend/src/routes/api/dsc/index.ts create mode 100644 backend/src/utils/dsc.ts diff --git a/backend/src/routes/api/dsc/index.ts b/backend/src/routes/api/dsc/index.ts new file mode 100644 index 0000000000..bae485b6db --- /dev/null +++ b/backend/src/routes/api/dsc/index.ts @@ -0,0 +1,12 @@ +import { KubeFastifyInstance } from '../../../types'; +import { secureRoute } from '../../../utils/route-security'; +import { getClusterStatus } from '../../../utils/dsc'; + +module.exports = async (fastify: KubeFastifyInstance) => { + fastify.get( + '/status', + secureRoute(fastify)(async () => { + return getClusterStatus(fastify); + }), + ); +}; diff --git a/backend/src/types.ts b/backend/src/types.ts index 1b8e0e6e1e..6c0a4de077 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -254,7 +254,6 @@ export type KubeDecorator = KubeStatus & { customObjectsApi: k8s.CustomObjectsApi; rbac: k8s.RbacAuthorizationV1Api; currentToken: string; - }; export type KubeFastifyInstance = FastifyInstance & { @@ -759,10 +758,10 @@ export type GPUInfo = { export type AcceleratorInfo = { configured: boolean; - available: {[key: string]: number}; - total: {[key: string]: number}; - allocated: {[key: string]: number}; -} + available: { [key: string]: number }; + total: { [key: string]: number }; + allocated: { [key: string]: number }; +}; export type EnvironmentVariable = EitherNotBoth< { value: string | number }, @@ -882,7 +881,6 @@ export type SupportedModelFormats = { autoSelect?: boolean; }; - export enum ContainerResourceAttributes { CPU = 'cpu', MEMORY = 'memory', @@ -947,3 +945,29 @@ export enum KnownLabels { MODEL_SERVING_PROJECT = 'modelmesh-enabled', DATA_CONNECTION_AWS = 'opendatahub.io/managed', } + +type ComponentNames = + | 'codeflare' + | 'data-science-pipelines-operator' + | 'kserve' + | 'model-mesh' + // Bug: https://github.com/opendatahub-io/opendatahub-operator/issues/641 + | 'odh-dashboard' + | 'ray' + | 'workbenches'; + +export type DataScienceClusterKindStatus = { + conditions: []; + installedComponents: { [key in ComponentNames]: boolean }; + phase?: string; +}; + +export type DataScienceClusterKind = K8sResourceCommon & { + spec: unknown; // we should never need to look into this + status: DataScienceClusterKindStatus; +}; + +export type DataScienceClusterList = { + kind: 'DataScienceClusterList'; + items: DataScienceClusterKind[]; +}; diff --git a/backend/src/utils/dsc.ts b/backend/src/utils/dsc.ts new file mode 100644 index 0000000000..eae01bc1e1 --- /dev/null +++ b/backend/src/utils/dsc.ts @@ -0,0 +1,26 @@ +import { + DataScienceClusterKind, + DataScienceClusterKindStatus, + DataScienceClusterList, + KubeFastifyInstance, +} from '../types'; +import { createCustomError } from './requestUtils'; + +export const getClusterStatus = async ( + fastify: KubeFastifyInstance, +): Promise => { + const result: DataScienceClusterKind | null = await fastify.kube.customObjectsApi + .listClusterCustomObject('datasciencecluster.opendatahub.io', 'v1', 'datascienceclusters') + .then((res) => (res.body as DataScienceClusterList).items[0]) + .catch((e) => { + fastify.log.error(`Failure to fetch dsc: ${e.response.body}`); + return null; + }); + + if (!result) { + // May not be using v2 Operator + throw createCustomError('DSC Unavailable', 'Unable to get status', 404); + } + + return result.status; +}; diff --git a/frontend/src/k8sTypes.ts b/frontend/src/k8sTypes.ts index 329d5008be..bf50b108f1 100644 --- a/frontend/src/k8sTypes.ts +++ b/frontend/src/k8sTypes.ts @@ -769,3 +769,20 @@ export type K8sResourceListResult> continue: string; }; }; + +type ComponentNames = + | 'codeflare' + | 'data-science-pipelines-operator' + | 'kserve' + | 'model-mesh' + // Bug: https://github.com/opendatahub-io/opendatahub-operator/issues/641 + | 'odh-dashboard' + | 'ray' + | 'workbenches'; + +/** We don't need or should ever get the full kind, this is the status section */ +export type DataScienceClusterKindStatus = { + conditions: K8sCondition[]; + installedComponents: { [key in ComponentNames]: boolean }; + phase?: string; +}; diff --git a/manifests/base/cluster-role.yaml b/manifests/base/cluster-role.yaml index d21d47cd04..228eaeed7c 100644 --- a/manifests/base/cluster-role.yaml +++ b/manifests/base/cluster-role.yaml @@ -164,3 +164,11 @@ rules: - delete resources: - notebooks + - apiGroups: + - datasciencecluster.opendatahub.io + verbs: + - list + - watch + - get + resources: + - datascienceclusters