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

mcr.microsoft.com/mssql/rhel/server:2022-CU13-rhel-9.1 should have one or two '/' #572

Closed
mchoma opened this issue Aug 16, 2024 · 6 comments
Labels

Comments

@mchoma
Copy link
Contributor

mchoma commented Aug 16, 2024

XTF does not allow for me to use image like mcr.microsoft.com/mssql/rhel/server:2022-CU13-rhel-9.1

java.lang.IllegalArgumentException: image 'mcr.microsoft.com/mssql/rhel/server:2022-CU13-rhel-9.1' should have one or two '/' characters
	at cz.xtf.core.image.Image.from(Image.java:71)
	at cz.xtf.core.image.Image.get(Image.java:18)
	at cz.xtf.core.image.Image.resolve(Image.java:22)
	at cz.xtf.builder.db.MsSQL.getImageName(MsSQL.java:113)
	at cz.xtf.builder.db.AbstractDatabase.configureDeployment(AbstractDatabase.java:186)
	at cz.xtf.builder.db.AbstractDatabase.configureDeployment(AbstractDatabase.java:181)

We need case 4+: section here?

switch (slashTokens.length) {
case 1:
registry = "";
user = "";
repoTag = slashTokens[0];
break;
case 2:
registry = "";
user = slashTokens[0];
repoTag = slashTokens[1];
break;
case 3:
registry = slashTokens[0];
user = slashTokens[1];
repoTag = slashTokens[2];
break;
default:
throw new IllegalArgumentException("image '" + imageUrl + "' should have one or two '/' characters");

So we will end up with something like this

registry = mcr.microsoft.com
user = mssql/rhel
repoTag = server:2022-CU13-rhel-9.1
@mnovak1 mnovak1 added the major label Aug 16, 2024
@mchoma
Copy link
Contributor Author

mchoma commented Aug 19, 2024

@dosu what do you think?

Copy link

dosubot bot commented Aug 19, 2024

To handle image strings like mcr.microsoft.com/mssql/rhel/server:2022-CU13-rhel-9.1 in Image.java, you can modify the from method to accommodate cases with more than two '/' characters. Here is the updated code:

public static Image from(String imageUrl) {
    final String[] slashTokens = imageUrl.split("/");
    final String repoTag;

    final String registry;
    final String user;
    final String repo;
    final String tag;

    switch (slashTokens.length) {
        case 1:
            registry = "";
            user = "";
            repoTag = slashTokens[0];
            break;
        case 2:
            registry = "";
            user = slashTokens[0];
            repoTag = slashTokens[1];
            break;
        case 3:
            registry = slashTokens[0];
            user = slashTokens[1];
            repoTag = slashTokens[2];
            break;
        default:
            // Handle cases with more than two '/' characters
            registry = slashTokens[0];
            user = String.join("/", Arrays.copyOfRange(slashTokens, 1, slashTokens.length - 1));
            repoTag = slashTokens[slashTokens.length - 1];
            break;
    }

    final String[] tokens = repoTag.split(":");
    switch (tokens.length) {
        case 1:
            repo = tokens[0];
            tag = "";
            break;
        case 2:
            repo = tokens[0];
            tag = tokens[1];
            break;
        default:
            throw new IllegalArgumentException("repoTag '" + repoTag + "' should have zero or one ':' character");
    }
    return new Image(registry, user, repo, tag);
}

This modification ensures that if there are more than two '/' characters, the method correctly assigns the registry and user, and then extracts the repoTag from the last segment. This approach is similar to the logic used in the ImageStreamBuilder class from the xtf project, which also handles image URLs with varying numbers of '/' characters [1][2].

To continue talking to Dosu, mention @dosu.

mnovak1 added a commit to mnovak1/xtf that referenced this issue Aug 27, 2024
mnovak1 added a commit to mnovak1/xtf that referenced this issue Aug 28, 2024
mnovak1 added a commit to mnovak1/xtf that referenced this issue Aug 30, 2024
mnovak1 added a commit to mnovak1/xtf that referenced this issue Sep 2, 2024
@mchoma
Copy link
Contributor Author

mchoma commented Sep 2, 2024

@dosu any objection with linked pull request? Do you think it address original issue? Are linked tests correctly testing change?

Copy link

dosubot bot commented Sep 2, 2024

The linked pull request addresses the original issue by adding a check to ensure that image names do not contain more than two '/' characters. The specific change is:

String[] parts = imageUrl.split("/");
if (parts.length > 3) {
    throw new IllegalArgumentException("image '" + imageUrl + "' should have one or two '/' characters");
}

This code ensures that only valid image URLs are processed by throwing an IllegalArgumentException if the imageUrl contains more than two '/' characters [1].

Regarding the tests, I couldn't find specific information about the unit tests covering the Image.from method in the provided data. It would be prudent to review the tests to ensure they cover various scenarios, including edge cases like image URLs with more than two '/' characters.

To continue talking to Dosu, mention @dosu.

@mchoma
Copy link
Contributor Author

mchoma commented Sep 2, 2024

@dosu No that check is not implemented in #577

Copy link

dosubot bot commented Sep 2, 2024

The pull request #577 does address the original issue by modifying the parsing logic to handle image URLs with more than two slashes. This change allows the image mcr.microsoft.com/mssql/rhel/server:2022-CU13-rhel-9.1 to be parsed correctly.

Regarding the tests, the pull request includes updates to ensure that the new parsing logic is covered. It would be beneficial to review these tests to confirm they adequately cover various scenarios, including edge cases with different numbers of slashes in the image URLs. If the tests are comprehensive and pass successfully, the changes should be good to go.

To continue talking to Dosu, mention @dosu.

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

No branches or pull requests

2 participants