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

fix(distribution): digest cache should not be moved if it was an auth #36509

Merged
merged 1 commit into from Mar 23, 2018

Conversation

xujihui1985
Copy link
Contributor

@xujihui1985 xujihui1985 commented Mar 7, 2018

fixes #36309

- How I did it
when push mount candidate to registry, first check if error is autherror, then check if user has authConfig
if both autherror while user has not login, do not remove the local cache.
- How to verify it
push the image without login, and login again, you still can mount the shared layer
- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@GordonTheTurtle GordonTheTurtle added dco/no Automatically set by a bot when one of the commits lacks proper signature status/0-triage labels Mar 7, 2018
@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Mar 7, 2018
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Mar 7, 2018
@moby moby deleted a comment from GordonTheTurtle Mar 7, 2018
@thaJeztah
Copy link
Member

ping @dmcgowan @tonistiigi PTAL

@xujihui1985
Copy link
Contributor Author

ping @dmcgowan

@@ -580,14 +600,14 @@ func getMaxMountAndExistenceCheckAttempts(layer PushLayer) (maxMountAttempts, ma
// then fallback to upload
return 4, 3, true

// middle sized blobs; if we could not get the size, assume we deal with middle sized blob
// middle sized blobs; if we could not get the size, assume we deal with middle sized blob
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should not have the extra indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for my ide auto format the code

case size > smallLayerMaximumSize, err != nil:
// 1st attempt to mount blobs of average size few times
// 2nd try at most 1 existence check if there's an existing mapping to the target repository
// then fallback to upload
return 3, 1, false

// small blobs, do a minimum number of checks
// small blobs, do a minimum number of checks
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should not have the extra indentation.

"github.com/docker/docker/distribution/metadata"
"github.com/docker/docker/layer"
"github.com/docker/docker/pkg/progress"
"github.com/opencontainers/go-digest"
"github.com/docker/docker/api/types"
"github.com/docker/docker/registry"
"net/url"
Copy link
Contributor

Choose a reason for hiding this comment

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

Put this above with "net/http".

@@ -397,8 +416,9 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress.
return distribution.Descriptor{}, retryOnError(err)
}
}
defer layerUpload.Close()

if layerUpload != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem right to allow layerUpload to be nil and then immediately afterwards call pd.uploadUsingSession with layerUpload. Why would layerUpload be nil when bs.Create returned no error a few lines above?

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, this is paranoid, when I test the code with mock method I thought that may be the case when error is empty while layerUpload is nil too, and that should not happened

switch e := e.(type) {
case errcode.Error:
if e.Code == errcode.ErrorCodeUnauthorized {
logrus.Debugf("error code is unauthoriedError")
Copy link
Contributor

Choose a reason for hiding this comment

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

unauthoriedError is misspelled.

if isUnauthorizedError && !pd.pushState.hasAuthInfo {
// break the attempt loop as user has not login
logrus.Infoln("failed to push image to registry because unauthorized error and user not login")
break
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should continue instead of break. There might be other repos which do not require credentials to mount the blob. The continue can go inside the error checking code, instead of setting an isUnauthorizedError variable (it would mean having a label on the candidate loop and using continue candidateLoop).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is modified as you suggested

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Mar 13, 2018
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Mar 13, 2018
@codecov
Copy link

codecov bot commented Mar 13, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@72ba7f5). Click here to learn what that means.
The diff coverage is 90%.

@@            Coverage Diff            @@
##             master   #36509   +/-   ##
=========================================
  Coverage          ?   34.82%           
=========================================
  Files             ?      612           
  Lines             ?    45412           
  Branches          ?        0           
=========================================
  Hits              ?    15814           
  Misses            ?    27524           
  Partials          ?     2074

@thaJeztah
Copy link
Member

PowerPC failing is due to a flaky test;

https://jenkins.dockerproject.org/job/Docker-PRs-powerpc/8973/console

12:00:49 --- FAIL: TestLinksEtcHostsContentMatch (0.53s)
12:00:49 	assertions.go:226: 
                          
	Error Trace:	links_linux_test.go:46
12:00:49 		
	Error:      	Not equal: 
12:00:49 		
	            	expected: "127.0.0.1\tlocalhost\n::1\tlocalhost ip6-localhost ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\n172.17.0.2\t6fe75c06bdcd\n"
12:00:49 		
	            	received: ""

I see that one is being fixed through #36569

if e.Code == errcode.ErrorCodeUnauthorized && !pd.pushState.hasAuthInfo {
// continue to try other candidate as other repos may not require credentials to mount the blob
logrus.Debugf("failed to push layer to registry because unauthorized error and user not login")
continue candidateLoop
Copy link
Member

Choose a reason for hiding this comment

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

Does the layer upload need to be cancelled here? Maybe instead of a continue statement just ensure that the remove doesn't happen so there are fewer early exit/continue conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

this is my first attempt, what do you think of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as @aaronlehmann mentioned

I think this should continue instead of break. There might be other repos which do not require credentials to mount the blob. The continue can go inside the error checking code, instead of setting an isUnauthorizedError variable (it would mean having a label on the candidate loop and using continue candidateLoop).

is that the reason when authorizedError happened, it should continue to check other candidates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the main difference is do we break here when first authorizedError met or continue to try other candidates

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we have some conclusion on this so that I can have another commit before this weekend? @dmcgowan @aaronlehmann : )

Copy link
Contributor

Choose a reason for hiding this comment

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

@dmcgowan is right that this needs to cancel the layer upload.

How about adding && !isUnauthorizedError to if len(mountCandidate.SourceRepository) > 0... below, instead of the continue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about adding && !isUnauthorizedError to if len(mountCandidate.SourceRepository) > 0... below, instead of the continue?

it looks like it will still continue to try next candidate which is not necessary?

@aaronlehmann
Copy link
Contributor

aaronlehmann commented Mar 16, 2018 via email

error

local digest cache will be removed when error occured on push image
but it should not be removed if it is an auth error while on auth was
provided

moby#36309
Signed-off-by: 慕陶 <jihui.xjh@alibaba-inc.com>
if len(mountCandidate.SourceRepository) > 0 &&
!(isUnauthorizedError && !pd.pushState.hasAuthInfo) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmcgowan @aaronlehmann please have a look at this commit, hope that makes you happy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmcgowan let me know if you have any concern with this commit.

@xujihui1985
Copy link
Contributor Author

can we proceed this PR...? 🤓

@moby moby deleted a comment from GordonTheTurtle Mar 21, 2018
@dmcgowan
Copy link
Member

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM (thanks for reviewing @aaronlehmann @dmcgowan)

@xujihui1985
Copy link
Contributor Author

janky status seems not updated, actually it has finished

@vdemeester
Copy link
Member

janky is green 👼 not sure why the check status is not up-to-date

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.

docker pull full layer of image even base image already on the host
6 participants