-
Notifications
You must be signed in to change notification settings - Fork 77
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
Perform an O(1) check to find layers in an image #101
Merged
openshift-merge-robot
merged 5 commits into
openshift:master
from
smarterclayton:fetch_layers
Jul 13, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8fd43e4
Add a test script to assist in running a local registry
smarterclayton 1fd7f26
Reorganize blobdescriptorservice Stat to exit early
smarterclayton b665e71
Use imagestream/layers call to make verify O(1)
smarterclayton 359fc89
Add support for layers in fake client testing and unit tests
smarterclayton 82a0a6d
Update to Go 1.10 for travis and build to get t.Helper
smarterclayton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: go | ||
|
||
go: | ||
- 1.8 | ||
- "1.10" | ||
|
||
before_install: | ||
- go get github.com/alecthomas/gometalinter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# This script launches the image registry pointing to the OpenShift master defined in | ||
# the KUBECONFIG environment variable (and uses the current credentials as the client | ||
# credentials). You may need to start your master with the internalRegistryHostname | ||
# configuration variable set for some image stream calls to function properly. | ||
# | ||
|
||
source "$(dirname "${BASH_SOURCE}")/lib/init.sh" | ||
|
||
os::build::setup_env | ||
|
||
os::util::ensure::built_binary_exists 'dockerregistry' | ||
|
||
url="${REGISTRY_OPENSHIFT_SERVER_ADDR:-localhost:5000}" | ||
# find the first builder service account token | ||
token="$(oc get $(oc get secrets -o name | grep builder-token | head -n 1) --template '{{ .data.token }}' | os::util::base64decode)" | ||
echo | ||
echo "Login with:" | ||
echo " docker login -p \"${token}\" -u user ${url}" | ||
echo | ||
|
||
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY="${REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY:-/tmp/registry}" \ | ||
REGISTRY_OPENSHIFT_SERVER_ADDR="${url}" \ | ||
dockerregistry images/dockerregistry/config.yml | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,28 +40,40 @@ func (bs *blobDescriptorService) Stat(ctx context.Context, dgst digest.Digest) ( | |
if err == nil { | ||
return desc, nil | ||
} | ||
|
||
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: could not stat layer link %s in repository %s: %v", dgst.String(), bs.repo.Named().Name(), err) | ||
|
||
// we couldn't find the layer link | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment should elucidate the implications of not finding the layer link There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just a refactor of the method, i'm happy to make better comments |
||
desc, err = bs.repo.app.BlobStatter().Stat(ctx, dgst) | ||
if err == nil { | ||
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: blob %s exists in the global blob store", dgst.String()) | ||
// only non-empty layers is wise to check for existence in the image stream. | ||
// schema v2 has no empty layers. | ||
if !isEmptyDigest(dgst) { | ||
// ensure it's referenced inside of corresponding image stream | ||
if bs.repo.cache.ContainsRepository(dgst, bs.repo.imageStream.Reference()) { | ||
context.GetLogger(ctx).Debugf("found cached blob %q in repository %s", dgst.String(), bs.repo.imageStream.Reference()) | ||
} else if image := bs.repo.imageStream.HasBlob(ctx, dgst); image != nil { | ||
// remember all the layers of matching image | ||
RememberLayersOfImage(ctx, bs.repo.cache, image, bs.repo.imageStream.Reference()) | ||
} else { | ||
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: blob %s is neither empty nor referenced in image stream %s", dgst.String(), bs.repo.Named().Name()) | ||
return distribution.Descriptor{}, distribution.ErrBlobUnknown | ||
} | ||
} | ||
if err != nil { | ||
return desc, err | ||
} | ||
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: blob %s exists in the global blob store", dgst.String()) | ||
|
||
// Empty layers are considered to be "public" and we don't need to check whether they are referenced - schema v2 | ||
// has no empty layers. | ||
if isEmptyDigest(dgst) { | ||
return desc, nil | ||
} | ||
|
||
return desc, err | ||
// ensure it's referenced inside of corresponding image stream | ||
if bs.repo.cache.ContainsRepository(dgst, bs.repo.imageStream.Reference()) { | ||
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: found cached blob %q in repository %s", dgst.String(), bs.repo.imageStream.Reference()) | ||
return desc, nil | ||
} | ||
|
||
found, layers, image := bs.repo.imageStream.HasBlob(ctx, dgst) | ||
if !found { | ||
context.GetLogger(ctx).Debugf("(*blobDescriptorService).Stat: blob %s is neither empty nor referenced in image stream %s", dgst.String(), bs.repo.Named().Name()) | ||
return distribution.Descriptor{}, distribution.ErrBlobUnknown | ||
} | ||
|
||
if layers != nil { | ||
// remember all the layers of matching image | ||
RememberLayersOfImageStream(ctx, bs.repo.cache, layers, bs.repo.imageStream.Reference()) | ||
} | ||
if image != nil { | ||
// remember all the layers of matching image | ||
RememberLayersOfImage(ctx, bs.repo.cache, image, bs.repo.imageStream.Reference()) | ||
} | ||
return desc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume this expects a cluster to be running somewhere, how are the coordinates of the cluster being supplied to the registry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KUBECONFIG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a usage comment at the top of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done