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

Remove global DefaultRegistryClient #13356

Merged
merged 1 commit into from
Mar 15, 2017
Merged

Conversation

dmage
Copy link
Contributor

@dmage dmage commented Mar 11, 2017

Global variables really complicate tests and make them impossible to run concurrently. So I've tried to remove one of a such variable.

accessController, err := newAccessController(options)
if err != nil {
t.Fatal(err)
}
ctx := context.WithValue(context.Background(), "http.request", req)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, use github.com/docker/distribution/context.WithRequest


type contextKey string

var registryClientKey contextKey = "registryClient"
Copy link
Contributor

Choose a reason for hiding this comment

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

Historically, these things are stored in the util.go. Please either move context variables from util.go there or move this variables there.

@@ -201,6 +196,11 @@ func TokenRealm(options map[string]interface{}) (*url.URL, error) {
func newAccessController(options map[string]interface{}) (registryauth.AccessController, error) {
log.Info("Using Origin Auth handler")

ctx, ok := options["_context"].(context.Context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you write a comment why we can't use parent context ? It will help us not to forget that it cannot be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no parent context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooops. Sorry. I looked at WithUserClient, but was thinking about this change :)

@@ -201,6 +196,11 @@ func TokenRealm(options map[string]interface{}) (*url.URL, error) {
func newAccessController(options map[string]interface{}) (registryauth.AccessController, error) {
log.Info("Using Origin Auth handler")

ctx, ok := options["_context"].(context.Context)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add constant for _context.

@legionus
Copy link
Contributor

[test]

@dmage
Copy link
Contributor Author

dmage commented Mar 13, 2017

@legionus all comments addressed.

@@ -45,6 +45,8 @@ const (

RealmKey = "realm"
TokenRealmKey = "tokenrealm"

accessControllerOptionContext = "_context"
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it public and use it in pkg/cmd/dockerregistry/dockerregistry.go
Godoc please :)

@legionus
Copy link
Contributor

Flake #12784

@@ -201,6 +196,11 @@ func TokenRealm(options map[string]interface{}) (*url.URL, error) {
func newAccessController(options map[string]interface{}) (registryauth.AccessController, error) {
log.Info("Using Origin Auth handler")

ctx, ok := options["_context"].(context.Context)
Copy link

Choose a reason for hiding this comment

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

Why hiding the client into a context. Can the registry client be passed directly in an option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should've replace log.Info with context.GetLogger(ctx), but I forged to do that. And I think it's convenient to have the application context in all hooks, not only in the middlewares.

Copy link

Choose a reason for hiding this comment

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

I don't think the context makes sense in functions where you don't deal with a request that can be canceled or measured.

The newAccessController is invoked just once for the lifetime of the registry. I don't see a value in passing a context to the access controller upon init. Especially when all the other requests it will deal with will have context of their own - and completely different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced Context by AccessControllerParams.

@miminar
Copy link

miminar commented Mar 13, 2017

makeFakeRegistryClient seem no longer to be necessary. Please disregard. It still is.

@dmage
Copy link
Contributor Author

dmage commented Mar 14, 2017

Flake #13385

// WithRemoteBlobAccessCheckEnabled returns a new Context that allows
// blobDescriptorService to stat remote blobs. It is useful only in case
// of manifest verification.
func WithRemoteBlobAccessCheckEnabled(parent context.Context, enable bool) context.Context {
Copy link

Choose a reason for hiding this comment

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

Does it make sense to export these if others are private?

return context.WithValue(ctx, registryClientKey, client)
}

// RegistryClientFrom returns the registry client stored in ctx, if present.
Copy link

Choose a reason for hiding this comment

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

nit: drop the comma

spec := search[repo]
spec, ok := search[repo]
if !ok {
continue
Copy link

Choose a reason for hiding this comment

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

Did this crash for you? It would indicate an error in identifyCandidateRepositories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it crashed. It was removed by delete call few lines before because there was too many open files in proxyStat handler.

Copy link

Choose a reason for hiding this comment

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

I see, ok, good catch.

Copy link

@miminar miminar left a comment

Choose a reason for hiding this comment

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

This looks good to me. Squash the commits please.

Copy link
Contributor

@legionus legionus left a comment

Choose a reason for hiding this comment

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

LGTM

@legionus
Copy link
Contributor

Flake #12784

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to a7ca6e1

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/225/) (Base Commit: 0009bfa)

@legionus
Copy link
Contributor

[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Mar 15, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/225/) (Base Commit: 0009bfa) (Image: devenv-rhel7_6070)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to a7ca6e1

@openshift-bot openshift-bot merged commit 1eb44c7 into openshift:master Mar 15, 2017
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.

4 participants