-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Allow multiple segments in DockerImageReference #11173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,34 @@ func ParseDockerImageReference(spec string) (DockerImageReference, error) { | |
ref.ID = id | ||
break | ||
default: | ||
// TODO: this is no longer true with V2 | ||
// Handle multiple segments in form: registry/namespace/namesegment1/namesegment2/.../name | ||
// but not this form: http://registry/namespace/name. We don't support using the schema in | ||
// the DockerImageReference. | ||
if len(repoParts) > 3 && !strings.HasSuffix(repoParts[0], ":") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this going to miss validating myregistry.com:5000/a/b/c? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see it now, thanks. Nevermind :-) But when would it have a suffix of :? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you split it by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not valid. We've never supported a scheme. Is that all you're testing the suffix for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also hostname can't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right... I guess this is ok if we actually have users putting in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if len(repoParts[0]) == 0 { | ||
return ref, fmt.Errorf("the docker pull spec %q cannot have empty segments", spec) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this error text consistent with the 2 below please |
||
} | ||
ref.Registry = repoParts[0] | ||
|
||
if len(repoParts[1]) == 0 { | ||
return ref, fmt.Errorf("the docker pull spec %q cannot have empty segments", spec) | ||
} | ||
ref.Namespace = repoParts[1] | ||
|
||
for i, part := range repoParts[2:] { | ||
if len(part) == 0 { | ||
return ref, fmt.Errorf("the docker pull spec %q cannot have empty segments", spec) | ||
} | ||
if i > 0 { | ||
ref.Name += "/" | ||
} | ||
ref.Name += part | ||
} | ||
|
||
ref.Tag = tag | ||
ref.ID = id | ||
break | ||
} | ||
return ref, fmt.Errorf("the docker pull spec %q must be two or three segments separated by slashes", spec) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message looks outdated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. This is the error message that was returned by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message contradicts a comment two lines above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will be OK if I put comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite understand, why a function that is supposed to parse a reference with way more than 3 segments would ever return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @miminar because this case for But I just realized that I can't act like that and in case of specifying of schema I need to parse the rest path. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @miminar I was wrong again. We don't support schema in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To get to this line of code, it means either:
Either way, I don't think we should keep the error message as is, saying that it has to be two or three segments. I'm not sure what the best error message is, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ncdc This error message describes the common requirements for the DockerImageReference. It seems to me that it is better to leave it as is. Otherwise we need to add much more checks to make it better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can leave it for now, to get this PR in, but I would like it fixed when we refactor parsing. |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,6 +243,12 @@ func TestParseDockerImageReference(t *testing.T) { | |
Namespace: "user", | ||
Name: "myapp", | ||
}, | ||
{ | ||
From: "docker.io/user/project/myapp", | ||
Registry: "docker.io", | ||
Namespace: "user", | ||
Name: "project/myapp", | ||
}, | ||
{ | ||
From: "index.docker.io/bar", | ||
Registry: "index.docker.io", | ||
|
@@ -291,7 +297,17 @@ func TestParseDockerImageReference(t *testing.T) { | |
Err: true, | ||
}, | ||
{ | ||
From: "bar/foo/baz/biz", | ||
From: "bar/foo/baz/biz", | ||
Registry: "bar", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, I think if the docker hub ever starts supporting multiple components, this would resolve to registry=docker.io, namespace=bar, name=foo/baz/biz. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. See my above comment https://github.com/openshift/origin/pull/11173/files#r81712056 |
||
Namespace: "foo", | ||
Name: "baz/biz", | ||
}, | ||
{ | ||
From: "bar/foo/baz////biz", | ||
Err: true, | ||
}, | ||
{ | ||
From: "//foo/baz/biz", | ||
Err: true, | ||
}, | ||
{ | ||
|
@@ -313,6 +329,8 @@ func TestParseDockerImageReference(t *testing.T) { | |
case err == nil && testCase.Err: | ||
t.Errorf("%s: unexpected non-error", testCase.From) | ||
continue | ||
case err != nil && testCase.Err: | ||
continue | ||
} | ||
if e, a := testCase.Registry, ref.Registry; e != a { | ||
t.Errorf("%s: registry: expected %q, got %q", testCase.From, e, a) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding
case 3
: I feel like it's about time to recognizeregistry
part based on special characters it contains. The same way upstream does it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miminar parser refactoring out of scope of PR. I can open following issue about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I hate devcuts.