Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse BYON repository URL correctly #1249

Merged

Conversation

DaoDaoNoCode
Copy link
Member

@DaoDaoNoCode DaoDaoNoCode commented May 17, 2023

Closes #1085

Description

The PR did the following things:

  1. Use regex to match the repository URL, which could help correctly parse the hostname and the tag name
  2. If the user doesn't input the tag name, we will set the tag name default to latest, because it will automatically fetch the latest tag if you create an image stream without specifying the tag name
  3. If the user inputs the tag name, we will set the tag name of the BYON image to the same as the tag name user is importing

Because some docker container images might not have the latest tag or might not have the tag user specifies, it could throw an error if the tag cannot be found. In this situation, we show the error in the BYON image table to the admin users and hide the image from the spawner page of both the KFNBC and DS projects.

UX/UI change: Add an error state and tooltip to invalid BYON images

Screenshot 2023-05-17 at 9 50 18 AM

How Has This Been Tested?

  1. Try to create some custom images, you can use the images here https://quay.io/repository/opendatahub/workbench-images?tab=tags with the tag starting with jupyter, also you can go to search the OpenShift internal image streams like image-registry.openshift-image-registry.svc:5000/opendatahub/s2i-minimal-notebook. Try to create some with and without the tags
  2. Go to the spawner page to see if you can create a notebook/workbench with the custom image
  3. Try to find an image without the latest tag and import that image without specifying the tag
  4. Check whether there is an error state in the table for that image
  5. Check whether the error image is not visible in the spawner page image selections

Test Impact

Add some jest tests to make sure the regex could parse the URL correctly.

Request review criteria:

  • The commits have meaningful messages (squashes happen on merge by the bot).
  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work
  • The developer has added tests or explained why testing cannot be added (unit tests & storybook for related changes)

@@ -130,3 +130,6 @@ export const DEFAULT_NOTEBOOK_SIZES: NotebookSize[] = [
},
},
];

export const imageUrlRegex =
/^([\w.\-_]+((?::\d+|)(?=\/[a-z0-9._-]+\/[a-z0-9._-]+))|)(?:\/|)([a-z0-9.\-_]+(?:\/[a-z0-9.\-_]+|))(?::([\w.\-_]{1,127})|)/;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex won't match @sha256... as the tag because if use that, we cannot set it as the tag name. So in the custom image, the tag name will be set to latest but the repo URL will be set to the correct one with @sha256.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my gosh -- we need you to comment this in some fashion haha... wowzers, that's a regex and a half haha.

@DaoDaoNoCode
Copy link
Member Author

@vconzola Please check the UI change for the error state of the custom images as listed in the description.

@vconzola
Copy link

@DaoDaoNoCode As long as invalid images are hidden from non-admin users in the spawner dropdowns, the UX LGTM.

// check if the host is valid
if (!matchArray[1]) {
fastify.log.error('Invalid repository URL unable to add notebook image');
return { success: false, error: 'Invalid repository URL: ' + fullUrl };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's the way we had the endpoint configure, but I'm not a fan of returning a 200 with a failing state, rather than using the proper error code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is a lot of uncomfortable stuff with this area of the code -- I'm viewing the UI and noticing a lot of inconsistencies to the other parts of our app... we will need to rework this.

Copy link
Contributor

@lucferbux lucferbux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

I left a little nit, but at this point I don't think we should do major refactors to the backend so it's ok.

@openshift-ci openshift-ci bot added the lgtm label Jun 1, 2023
test('OpenShift internal registry URL with tag', () => {
const url =
'image-registry.openshift-image-registry.svc:5000/opendatahub/s2i-minimal-notebook:v0.3.0-py36';
const match = url.match(REPOSITORY_URL_REGEX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should have been a function wrapping to give 1/4 a real name instead of magic-ness... these tests showcase that just in reading of the test lines.

}
return (
<Tooltip removeFindDomNode role="none" content={<Text>{image.error}</Text>}>
<Icon role="button" aria-label="error icon" status="danger" isInline tabIndex={0}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is not the best way to make it tab-enabled... because you're explicitly setting the tab index to 0. We did this elsewhere with a button: https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/components/SupportedAppTitle.tsx#L22-L30

Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will log a tech debt to clean up some of these things... this is bad for maintenance, but this works as-is... so we'll want to clean it up next sprint.

EDIT: for posterity, #1326

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 2, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, lucferbux

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Custom notebook image fails to pull with registry port
5 participants