Skip to content

Commit

Permalink
Merge pull request #1981 from andrewballantyne/support-dsc-status
Browse files Browse the repository at this point in the history
Expose the DSC status for the client
  • Loading branch information
openshift-ci[bot] authored Oct 18, 2023
2 parents b4b169b + a5f3458 commit c0dca01
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 6 deletions.
12 changes: 12 additions & 0 deletions backend/src/routes/api/dsc/index.ts
Original file line number Diff line number Diff line change
@@ -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);
}),
);
};
36 changes: 30 additions & 6 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ export type KubeDecorator = KubeStatus & {
customObjectsApi: k8s.CustomObjectsApi;
rbac: k8s.RbacAuthorizationV1Api;
currentToken: string;

};

export type KubeFastifyInstance = FastifyInstance & {
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -882,7 +881,6 @@ export type SupportedModelFormats = {
autoSelect?: boolean;
};


export enum ContainerResourceAttributes {
CPU = 'cpu',
MEMORY = 'memory',
Expand Down Expand Up @@ -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[];
};
26 changes: 26 additions & 0 deletions backend/src/utils/dsc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
DataScienceClusterKind,
DataScienceClusterKindStatus,
DataScienceClusterList,
KubeFastifyInstance,
} from '../types';
import { createCustomError } from './requestUtils';

export const getClusterStatus = async (
fastify: KubeFastifyInstance,
): Promise<DataScienceClusterKindStatus> => {
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;
};
17 changes: 17 additions & 0 deletions frontend/src/k8sTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,20 @@ export type K8sResourceListResult<TResource extends Partial<K8sResourceCommon>>
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;
};
8 changes: 8 additions & 0 deletions manifests/base/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,11 @@ rules:
- delete
resources:
- notebooks
- apiGroups:
- datasciencecluster.opendatahub.io
verbs:
- list
- watch
- get
resources:
- datascienceclusters

0 comments on commit c0dca01

Please sign in to comment.