Skip to content

Conversation

@runcom
Copy link
Member

@runcom runcom commented Jun 30, 2016

@mtrmac pls see individual commits - the second commit just adds 1 test but if design is ok I'll continue adding them here

@runcom runcom changed the title Docker tests WIP: Docker tests Jun 30, 2016
@runcom runcom changed the title WIP: Docker tests WIP: Docker tests and clean Jun 30, 2016
@runcom runcom force-pushed the docker-tests branch 2 times, most recently from 5a8e692 to 7399b12 Compare June 30, 2016 10:10
func newDockerClient(refHostname, certPath string, tlsVerify bool) (*dockerClient, error) {
// NewClient returns a new Client instance for refHostname (a host a specified in the Docker image reference, not canonicalized to dockerRegistry)
func NewClient(img, certPath string, tlsVerify bool) (Client, error) {
ref, _, err := parseDockerImageName(img)
Copy link
Member Author

@runcom runcom Jun 30, 2016

Choose a reason for hiding this comment

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

This is not so clean here, I would move the parseDockerImageName call up in the call stack but that could affect NewImageSource and NewImageSource as well, not sure. I believe we can live with this duplication but since NewClient is exported I'd rather have a better API here.

The duplication I'm talking about can be clearly seen above in doc.go where we pass img to both the client and the image creations.

After all, I personally don't think this duplication is that bad because Client is now an interface and how we build our own is our implementation detail in this library no? That said, I think NewClient should receive an hostname instead but with this we get back to my original statement to move parseDockerImageName up in the call stack.

@mtrmac WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m thinking the client should be hidden from users of the library, and then AFAICS this problem disappears because the parsing would still happen in the Image{,Source,Destination}.

Separately, for policy namespacing I will probably need a transport-independent “parsed reference” (types.ImageReference interface), with external users first converting a string into an implementation of that interface (or perhaps constructing an implementation directly), and then calling NewImage$something; so the parsing would happen separately and externally.

Copy link
Member Author

Choose a reason for hiding this comment

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

I’m thinking the client should be hidden from users of the library

that's how it is now, but letting ppl specify a custom client if they wish is nice leveraging golang interfaces

@runcom runcom force-pushed the docker-tests branch 3 times, most recently from 34c0b81 to 986bba4 Compare June 30, 2016 10:33
runcom added 3 commits June 30, 2016 12:35
and for pluggability as well

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Docker is already specified in the pkg name

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
@runcom
Copy link
Member Author

runcom commented Jun 30, 2016

The last commit is the most important to me, before going to start vendoring containers/image in other tools (such as rkt) i'd really want to polish the API

type Client interface {
MakeRequest(string, string, map[string][]string, io.Reader, bool) (*http.Response, error)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why export this at all? Do you expect any external users? If this is only for testing, we can make that interface private, and hide its uses from clients (see below).

Copy link
Member Author

@runcom runcom Jul 1, 2016

Choose a reason for hiding this comment

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

I think letting users specify a custom client at will is valuable

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 1, 2016

Full ACK on dropping the Docker word from method names.

@runcom
Copy link
Member Author

runcom commented Jul 1, 2016

so the general stuff going on here is to have an extension point for people who want to provide their own client implementation - not just for our internal testing (it's clear we will gain something from this in tests but it's just a consequence)

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 1, 2016

so the general stuff going on here is to have an extension point for people who want to provide their own client implementation - not just for our internal testing

Like what? I genuinely don’t know why one would want to replace HTTP by something else, or to completely redo the ping and authorization lookup mechanism.

Also, note that this would not help with testing dockerClient.

I can, sort of, imagine a caller wanting to add the same HTTP timeouts as any other HTTP code in their application uses, or perhaps the same HTTP request/response logging that is used in the rest of the application. But why would a bona-fide user want to replace HTTP by something else, completely reimplement the authentication code, and so on?

There may be something possibly useful to expose to the clients but the current dockerClient doesn’t seem to be the right abstraction level.

@runcom
Copy link
Member Author

runcom commented Jul 1, 2016

so probably I'm over engineering but in Docker itself is a separate package with a given interface - probably we don't need this then as it is now

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 1, 2016

What do you mean in particular? Looking at https://github.com/docker/distribution/blob/master/registry/client/repository.go#L65 , it is parametrized with a http.RoundTripper only.

(Arguably http.RoundTripper is not all that more precise, it can be used to do any modification at all and it is not immediately clear who is responsible for the Authorization header for example, but at least it clearly leaves the ping etc. stuff as an internal implementation detail.)

@runcom
Copy link
Member Author

runcom commented Jul 1, 2016

What do you mean in particular? Looking at https://github.com/docker/distribution/blob/master/registry/client/repository.go#L65 , it is parametrized with a http.RoundTripper only.

I was referring to docker/docker and docker/engine-api but that's clearly another type of client

@runcom runcom mentioned this pull request Jul 4, 2016
@runcom
Copy link
Member Author

runcom commented Jul 18, 2016

superseded by #44

@runcom runcom closed this Jul 18, 2016
@runcom runcom deleted the docker-tests branch July 18, 2016 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants