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

Compare mount targets by string #690

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func scopesForUploadingImage(repo name.Repository, layers []v1.Layer) []string {
if ml, ok := l.(*MountableLayer); ok {
// we will add push scope for ref.Context() after the loop.
// for now we ask pull scope for references of the same registry
if ml.Reference.Context() != repo && ml.Reference.Context().Registry == repo.Registry {
if ml.Reference.Context().String() != repo.String() && ml.Reference.Context().Registry.String() == repo.Registry.String() {
scopeSet[ml.Reference.Scope(transport.PullScope)] = struct{}{}
}
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/v1/remote/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,41 @@ func TestWriteWithErrors(t *testing.T) {
}
}

func TestDockerhubScopes(t *testing.T) {
src, err := name.ParseReference("busybox")
if err != nil {
t.Fatal(err)
}
rl, err := random.Layer(1024, types.DockerLayer)
if err != nil {
t.Fatal(err)
}
ml := &MountableLayer{
Layer: rl,
Reference: src,
}
want := src.Scope(transport.PullScope)

for _, s := range []string{
"jonjohnson/busybox",
"docker.io/jonjohnson/busybox",
"index.docker.io/jonjohnson/busybox",
} {
dst, err := name.ParseReference(s)
if err != nil {
t.Fatal(err)
}

scopes := scopesForUploadingImage(dst.Context(), []v1.Layer{ml})

if len(scopes) != 2 {
t.Errorf("Should have two scopes (src and dst), got %d", len(scopes))
} else if diff := cmp.Diff(want, scopes[1]); diff != "" {
t.Errorf("TestDockerhubScopes %q: (-want +got) = %v", s, diff)
}
}
}

func TestScopesForUploadingImage(t *testing.T) {
referenceToUpload, err := name.NewTag("example.com/sample/sample:latest", name.WeakValidation)
if err != nil {
Expand Down