Repository navigation
ParseDockerImageReference use docker/distribution reference parser - #11245
Conversation
|
[test] |
|
This parser have a few issues:
|
| ref.Registry, ref.Name = reference.SplitHostname(named) | ||
| } else if named, ok := dockerRef.(reference.Tagged); ok { | ||
| ref.Tag = named.Tag() | ||
| } else if named, ok := dockerRef.(reference.Digested); ok { |
There was a problem hiding this comment.
I believe Tagged and Digested can be considered invalid.
There was a problem hiding this comment.
OK, but in this case type switch no longer needed.
There was a problem hiding this comment.
Ignore my previous comment. They are valid references.
|
|
||
| repoParts := strings.Split(ref.Name, "/") | ||
|
|
||
| if !isRegistryName(ref.Registry) && len(repoParts) == 1 { |
There was a problem hiding this comment.
A note for isRegistryName(): use strings.ContainsAny. Also document that it needs to be called with just one path component (no slash allowed).
There was a problem hiding this comment.
You forget about localhost. So I think this function useful here.
There was a problem hiding this comment.
It is. This is a suggestion to modify the isRegistryName() function itself and annotate it with a godoc.
| ref.Registry = "" | ||
| } | ||
|
|
||
| if ref.Namespace == "" && len(repoParts) >= 2 { |
There was a problem hiding this comment.
Make sure repoParts[0] doesn't look like a registry?
| ref.Namespace, ref.Name = repoParts[0], strings.Join(repoParts[1:], "/") | ||
| } | ||
|
|
||
| if ref.Namespace == "" && IsRegistryDockerHub(ref.Registry) { |
| Tag: "tag", | ||
| }, | ||
| { | ||
| // docker.io/namespace/name == 255 chars without implicit namespace |
| switch tagRef.From.Kind { | ||
| case "DockerImage": | ||
| if ref, err := api.ParseDockerImageReference(tagRef.From.Name); err == nil && tagRef.ImportPolicy.Scheduled && len(ref.ID) > 0 { | ||
| if ref, err := api.ParseDockerImageReference(tagRef.From.Name); err != nil { |
There was a problem hiding this comment.
... && len(tagRef.From.Name) > 0, which is already covered above.
|
I'd rather do it right than stick with the old behavior. Another example is parsing of |
| From: "http://bar:5000/foo/baz@sha256:3c87c572822935df60f0f5d3665bd376841a7fcfeb806b5f212de6a00e9a7b25", | ||
| Err: true, | ||
| }, | ||
| { |
There was a problem hiding this comment.
Could you add From: "@sha256:3c87c572822935df60f0f5d3665bd376841a7fcfeb806b5f212de6a00e9a7b25", From: "sha256:3c87c572822935df60f0f5d3665bd376841a7fcfeb806b5f212de6a00e9a7b25" and From: ":tag"?
@miminar This behavior right according |
package main
import ("fmt"; "github.com/docker/docker/reference")
func main() {
ref, err := reference.ParseNamed("bar/foo/baz")
if err != nil {
fmt.Println("failed to parse reference: %v", err)
}
fmt.Printf("hostname=%q, remotename=%q\n", ref.Hostname(), ref.RemoteName())
}Which makes more sense to me. Although if you replace |
@miminar Using I'm not sure we want it. |
|
@miminar i don't like vendoring 15 more deps just to get this helper, not saying that we can't even use the helper as it is as we need to get the namespace still.. |
a1b8c4b to
e3afe0b
Compare
|
I took the function to separate the host name and repository from the docker. |
|
@miminar I think this is unacceptable as well. we will break everyone. |
By everyone you mean us? 😄 This PR attempts to get the parsing right. Different output for the same input is expected if the previous parsing was wrong. We just need to make sure that everything works as expected. I wouldn't default to |
OK :)
If we do not want to use |
e3afe0b to
2ea0593
Compare
| repoParts := strings.Split(ref.Name, "/") | ||
|
|
||
| if len(repoParts) >= 2 { | ||
| if isRegistryName(repoParts[0]) { |
There was a problem hiding this comment.
Is this even possible to satisfy? It is with localhost in name (e.g. registry.com/app/localhost/image). But it looks to me like a valid reference.
0613aae to
d9b7feb
Compare
| break | ||
| } | ||
| return ref, fmt.Errorf("the docker pull spec %q must be two or three segments separated by slashes", spec) | ||
| // It's not enough just to use the reference.ParseNamed(). We have the fill |
There was a problem hiding this comment.
Yes, typo. I'll fix it.
| @@ -0,0 +1,53 @@ | |||
| package utils | |||
There was a problem hiding this comment.
In kube we try to avoid generic "utils" packages. Not a deal breaker, but I'd recommend a more specific package name.
There was a problem hiding this comment.
github.com/openshift/origin/pkg/image/reference ?
| }, | ||
| }, | ||
| expected: field.ErrorList{ | ||
| field.Invalid(field.NewPath("spec", "tags").Key("badid").Child("from", "name"), "abc@badid", "only tags can be scheduled for import"), |
There was a problem hiding this comment.
It looks like we lost a test case where we validate that you can't specify a digest for import where the error returned is "only tags can be scheduled for import"
There was a problem hiding this comment.
"abc@badid" was always wrong, but previously the error was ignored.
what do you mean "we lost" ?
There was a problem hiding this comment.
There is no test case that validates it receives "only tags can be scheduled for import" as an error any more. Could you please add a test case that tries to schedule a valid pull-by-digest spec?
| return ref, err | ||
| } | ||
|
|
||
| if named, ok := dockerRef.(reference.Named); ok { |
There was a problem hiding this comment.
Doesn't reference.ParseNamed return a reference.Named?
There was a problem hiding this comment.
Good catch! thanks!
| Tag: "tag", | ||
| }, | ||
| { | ||
| // docker.io/namespace/name == 255 chars without explicit namespace |
78c9a44 to
148e83a
Compare
bf5259e to
8b073e8
Compare
|
@ncdc please review again. |
8b073e8 to
a9c2463
Compare
|
It sure if I'll have time to review today. Feel free to find another On Tuesday, October 11, 2016, Alexey Gladkov [email protected]
|
@ncdc Then please take off lock on this PR. |
|
@liggitt @smarterclayton please review |
a9c2463 to
e9843b1
Compare
| } | ||
| return false, dockerImageReference.ID | ||
| } else { | ||
| fmt.Fprintf(os.Stderr, "ERR(%s): %#+v\n", imageNode.Name, err) |
There was a problem hiding this comment.
Is this for debugging purposes? If not, maybe something a bit gentler than "ERR" would be better?
There was a problem hiding this comment.
@ncdc I forgot to remove debugging. Fixed.
| ) | ||
|
|
||
| // NamedDockerImageReference points to a Docker image. | ||
| type NamedDockerImageReference struct { |
There was a problem hiding this comment.
This type is identical in everything except name to DockerImageReference in pkg/image/api/types.go. And ParseNamedDockerImageReference below is effectively wrapped by pkg/image/api/helpers.go#ParseDockerImageReference. Can we collapse the two types and functions into just 1 type and 1 function?
There was a problem hiding this comment.
I split it to able use this parser in S2I as mentioned in #11245 (comment). S2I can't use ParseDockerImageReference directly because origin imports it. To avoid differences in the parser behavior we need to use one parser everywhere. So I move it into separate module with minimal dependencies.
e9843b1 to
0cf14aa
Compare
|
flake: #8571 |
0cf14aa to
2c9ba48
Compare
We can't remove ParseDockerImageReference and just use docker/distribution/reference to parse DockerImageReference because we have to support few special cases related to docker.io. Keeping it in mind, we can reimplement ParseDockerImageReference to use new parser. In addition we got new limits on the length of the DockerImageReference. So, after refactoring our restrictions are pretty the same as in docker/distribution. Signed-off-by: Gladkov Alexey <[email protected]>
2c9ba48 to
caa9083
Compare
|
Evaluated for origin test up to caa9083 |
|
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10015/) (Base Commit: 6b0457c) |
|
@mfojtik merge ? |
|
[merge] Michal Fojtik On 13 October 2016 at 19:13:19, Alexey Gladkov ([email protected])
|
|
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10015/) (Image: devenv-rhel7_5179) |
|
Evaluated for origin merge up to caa9083 |
We can't remove ParseDockerImageReference and just use docker/distribution/reference
to parse DockerImageReference because we have to support few special cases related
to docker.io. Keeping it in mind, we can reimplement ParseDockerImageReference
to use new parser.
In addition we got new limits on the length of the DockerImageReference.
So, after refactoring our restrictions are pretty the same as in docker/distribution.
Fix #11211
@ncdc @miminar please review.