Skip to content

Commit

Permalink
Don't crash if modelregistries namespace is not present in the DSC (#…
Browse files Browse the repository at this point in the history
…3248)

* Don't crash if modelregistries namespace is not present in the DSC

Signed-off-by: Mike Turley <mike.turley@alum.cs.umass.edu>

* Defensively get registriesNamespace in the frontend

Signed-off-by: Mike Turley <mike.turley@alum.cs.umass.edu>

---------

Signed-off-by: Mike Turley <mike.turley@alum.cs.umass.edu>
  • Loading branch information
mturley committed Sep 24, 2024
1 parent b83d991 commit d5938bf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
17 changes: 14 additions & 3 deletions backend/src/routes/api/modelRegistries/modelRegistryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ const MODEL_REGISTRY_API_GROUP = 'modelregistry.opendatahub.io';
const MODEL_REGISTRY_API_VERSION = 'v1alpha1';
const MODEL_REGISTRY_PLURAL = 'modelregistries';

export const getModelRegistryNamespace = async (fastify: KubeFastifyInstance): Promise<string> => {
const modelRegistryNamespace = await getClusterStatus(fastify);
return modelRegistryNamespace.components.modelregistry.registriesNamespace;
export const getModelRegistryNamespace = async (
fastify: KubeFastifyInstance,
): Promise<string | undefined> => {
let registriesNamespace: string | undefined;
try {
const clusterStatus = await getClusterStatus(fastify);
registriesNamespace = clusterStatus.components?.modelregistry?.registriesNamespace;
} catch (e) {
fastify.log.error(e, 'Failed to fetch DSC status');
}
if (!registriesNamespace) {
fastify.log.warn('Model registry namespace not found in DSC status');
}
return registriesNamespace;
};

const base64encode = (value?: string): string => {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,11 @@ type ComponentNames =
| 'workbenches';

export type DataScienceClusterKindStatus = {
components: {
modelregistry: {
registriesNamespace: string
}
}
components?: {
modelregistry?: {
registriesNamespace?: string;
};
};
conditions: K8sCondition[];
installedComponents: { [key in ComponentNames]?: boolean };
phase?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const EnabledModelRegistrySelectorContextProvider: React.FC<
isLoaded,
error,
refreshRulesReview,
} = useModelRegistryServices(dscStatus?.components.modelregistry.registriesNamespace || '');
} = useModelRegistryServices(dscStatus?.components?.modelregistry?.registriesNamespace || '');
const [preferredModelRegistry, setPreferredModelRegistry] = React.useState<
ServiceKind | undefined
>(undefined);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/k8sTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,9 +1356,9 @@ export type K8sResourceListResult<TResource extends Partial<K8sResourceCommon>>

/** We don't need or should ever get the full kind, this is the status section */
export type DataScienceClusterKindStatus = {
components: {
modelregistry: {
registriesNamespace: string;
components?: {
modelregistry?: {
registriesNamespace?: string;
};
};
conditions: K8sCondition[];
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/modelRegistrySettings/CreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CreateModal: React.FC<CreateModalProps> = ({ isOpen, onClose, refresh }) =
kind: 'ModelRegistry',
metadata: {
name: nameDesc.k8sName || translateDisplayNameForK8s(nameDesc.name),
namespace: dscStatus?.components.modelregistry.registriesNamespace || '',
namespace: dscStatus?.components?.modelregistry?.registriesNamespace || '',
annotations: {
'openshift.io/description': nameDesc.description,
'openshift.io/display-name': nameDesc.name.trim(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ProjectsSettingsTab from './ProjectsTab/ProjectsSettingsTab';

const ModelRegistriesManagePermissions: React.FC = () => {
const { dscStatus } = React.useContext(AreaContext);
const modelRegistryNamespace = dscStatus?.components.modelregistry.registriesNamespace;
const modelRegistryNamespace = dscStatus?.components?.modelregistry?.registriesNamespace;
const [activeTabKey, setActiveTabKey] = React.useState('users');
const [ownerReference, setOwnerReference] = React.useState<ModelRegistryKind>();
const [groups] = useGroups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const useModelRegistryRoleBindings = (): FetchState<RoleBindingKind[]> => {
const getRoleBindings = React.useCallback(
() =>
listRoleBindings(
dscStatus?.components.modelregistry.registriesNamespace,
dscStatus?.components?.modelregistry?.registriesNamespace,
KnownLabels.LABEL_SELECTOR_MODEL_REGISTRY,
).catch((e) => {
if (e.statusObject?.code === 404) {
throw new Error('No rolebindings found.');
}
throw e;
}),
[dscStatus?.components.modelregistry.registriesNamespace],
[dscStatus?.components?.modelregistry?.registriesNamespace],
);

return useFetchState<RoleBindingKind[]>(getRoleBindings, []);
Expand Down

0 comments on commit d5938bf

Please sign in to comment.