Skip to content

Commit

Permalink
Fix for untrue flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-o0o committed Jul 31, 2024
1 parent be47fe4 commit 3596a57
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,21 @@ describe('getNotebookImageData', () => {
const result = getNotebookImageData(notebook, images);
expect(result?.imageAvailability).toBe(NotebookImageAvailability.DELETED);
});

it('should fail without fix', () => {
const imageName = 'jupyter-datascience-notebook';
const tagName = '2024.1';
const notebook = mockNotebookK8sResource({
lastImageSelection: `${imageName}:${tagName}`,
image: `image-registry.openshift-image-registry.svc:5000/opendatahub/${imageName}:${tagName}`,
});
const images = [
mockImageStreamK8sResource({
tagName,
name: imageName,
}),
];
const result = getNotebookImageData(notebook, images);
expect(result?.imageAvailability).toBe(NotebookImageAvailability.ENABLED);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,22 @@ export const getNotebookImageData = (
}

const [imageName, versionName] = imageTag;
const [lastImageSelectionName] =
const [lastImageSelectionName, lastImageSelectionTag] =
notebook.metadata.annotations?.['notebooks.opendatahub.io/last-image-selection']?.split(':') ??
[];

// Fallback for non internal registry clusters
const imageStream =
images.find((image) => image.metadata.name === imageName) ||
images.find((image) =>
image.spec.tags
? image.spec.tags.find(
images.find(
(image) =>
image.metadata.name === lastImageSelectionName &&
(image.spec.tags?.find((version) => version.from?.name === container.image) ||
image.status?.tags?.find(
(version) =>
version.from?.name === container.image &&
image.metadata.name === lastImageSelectionName,
)
: false,
version.tag === lastImageSelectionTag &&
version.items?.find((item) => item.dockerImageReference === container.image),
)),
);

// if the image stream is not found, consider it deleted
Expand All @@ -54,7 +55,10 @@ export const getNotebookImageData = (

const versions = imageStream.spec.tags || [];
const imageVersion = versions.find(
(version) => version.name === versionName || version.from?.name === container.image,
(version) =>
version.name === versionName ||
version.from?.name === container.image ||
version.name === lastImageSelectionTag,
);

// because the image stream was found, get its display name
Expand Down

0 comments on commit 3596a57

Please sign in to comment.