-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Added digest cache, store digest instead of tags, added test #396
Added digest cache, store digest instead of tags, added test #396
Conversation
/ok-to-test |
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.
Looking great to me! Just a few minor items to address - also a question for my own understanding about httptest
:D
/approve
@@ -115,27 +115,45 @@ func getEnvVar(cmd, args []string) (string, error) { | |||
// GetRemoteEntrypoint accepts a cache of image lookups, as well as the image | |||
// to look for. If the cache does not contain the image, it will lookup the | |||
// metadata from the images registry, and then commit that to the cache |
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.
could you update this comment to say digest
instead of image
? (the word image above i think mostly is referring literally to the image
variable`)
// GetImageDigest tries to find and return image digest in cache, if | ||
// cache doesn't exists it will lookup the digest in remote image manifest | ||
// and then cache it | ||
func GetImageDigest(cache *Cache, image string) (string, error) { |
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 like how you broke this into a separate function!
// and then cache it | ||
func GetImageDigest(cache *Cache, image string) (string, error) { | ||
if ep, ok := cache.get(image); ok { | ||
return ep[0], nil |
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.
what is ep[0]
? what does ep
have in it? could it be an empty list?
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.
Yep, sorry, my bad, fixed.
if err != nil { | ||
return "", fmt.Errorf("failed to fetch remote image %s: %v", image, err) | ||
} | ||
// Get Digest Hash struct |
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 think this comment kinda just repeats the line below it so im not sure we need it
// Get Digest Hash struct | ||
digestHash, err := img.Digest() | ||
if err != nil { | ||
return "", fmt.Errorf("couldn't get config for image %s: %v", image, err) |
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.
should this be "couldn't get digest hash for image"?
bSpec := bs.DeepCopy() | ||
for i := range bSpec.Steps { | ||
step := &bSpec.Steps[i] | ||
if len(step.Command) == 0 { | ||
ep, err := entrypoint.GetRemoteEntrypoint(cache, step.Image) | ||
digest, err := entrypoint.GetImageDigest(digestCache, step.Image) | ||
ep, err := entrypoint.GetRemoteEntrypoint(entrypointCache, digest) |
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.
nice, im glad we do this in two steps 👍
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.
@Zyqsempai Actually shouldn't entrypoint.GetRemoteEntrypoint
take step.Image
and digest
?
The digested
image should be in the form of step.Image@digest
otherwise the ref is wrong 😅
digestHash, _ := img.Digest() | ||
expectedDigetsSha := digestHash.String() | ||
expectedRepo := "image" | ||
manifestPath := fmt.Sprintf("/v2/%s/manifests/latest", expectedRepo) |
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.
might be nice to have a function (or functions!) to return digestHash
and expectedRepo
especially since this seems to be repeated b/w the two tests
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.
Added only function to get digest like Str, since expetedRepo doesn't necessarily should be same for tests, and add function just to return on string seems like small overhead to me;)
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.
kk makes sense! :D
expectedRepo := "image" | ||
manifestPath := fmt.Sprintf("/v2/%s/manifests/latest", expectedRepo) | ||
|
||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
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.
this is for my own understanding: how does httptest
intercept requests?? i dont see anywhere where it is configured to listen on a particular port, or anywhere that we tell remote.Image
to make requests to this server 🤔 (obviously it works but I don't understand how!)
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.
httptest.NewServer
creates a thing (listening to a port or a socket I don't remember) and to target it, server.URL
will point to it. (See https://golang.org/src/net/http/httptest/server.go?s=2302:2346#L70, it runs an http.Server
behind the scene 👼 )
func newLocalListener() net.Listener {
if *serve != "" {
l, err := net.Listen("tcp", *serve)
if err != nil {
panic(fmt.Sprintf("httptest: failed to listen on %v: %v", *serve, err))
}
return l
}
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
if l, err = net.Listen("tcp6", "[::1]:0"); err != nil {
panic(fmt.Sprintf("httptest: failed to listen on a port: %v", err))
}
}
return l
}
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.
Oooooooooh and then we use server.URL
in image := path.Join(strings.TrimPrefix(server.URL, "http://"), "image:latest")
! Got it, thanks for explaining @vdemeester :D
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.
sgtm 👍
expectedRepo := "image" | ||
manifestPath := fmt.Sprintf("/v2/%s/manifests/latest", expectedRepo) | ||
|
||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
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.
httptest.NewServer
creates a thing (listening to a port or a socket I don't remember) and to target it, server.URL
will point to it. (See https://golang.org/src/net/http/httptest/server.go?s=2302:2346#L70, it runs an http.Server
behind the scene 👼 )
func newLocalListener() net.Listener {
if *serve != "" {
l, err := net.Listen("tcp", *serve)
if err != nil {
panic(fmt.Sprintf("httptest: failed to listen on %v: %v", *serve, err))
}
return l
}
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
if l, err = net.Listen("tcp6", "[::1]:0"); err != nil {
panic(fmt.Sprintf("httptest: failed to listen on a port: %v", err))
}
}
return l
}
a6b62f8
to
dd56fc3
Compare
Fixed comments. But I can't reach the test server, to check why the tests are failing. |
bSpec := bs.DeepCopy() | ||
for i := range bSpec.Steps { | ||
step := &bSpec.Steps[i] | ||
if len(step.Command) == 0 { | ||
ep, err := entrypoint.GetRemoteEntrypoint(cache, step.Image) | ||
digest, err := entrypoint.GetImageDigest(digestCache, step.Image) | ||
ep, err := entrypoint.GetRemoteEntrypoint(entrypointCache, digest) |
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.
@Zyqsempai Actually shouldn't entrypoint.GetRemoteEntrypoint
take step.Image
and digest
?
The digested
image should be in the form of step.Image@digest
otherwise the ref is wrong 😅
@vdemeester Could you please post the failed test stucktrace, or another info, coz seems like i just doesn't have access to |
bSpec := bs.DeepCopy() | ||
for i := range bSpec.Steps { | ||
step := &bSpec.Steps[i] | ||
if len(step.Command) == 0 { | ||
ep, err := entrypoint.GetRemoteEntrypoint(cache, step.Image) | ||
digest, err := entrypoint.GetImageDigest(digestCache, step.Image) |
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.
this err
need to be checked too before getting to the next line
@Zyqsempai the errors indicates the
See my comment above ^^ |
@vdemeester Seems like it's related to the problem with Digest you mentioned above. |
Fix PR comments Fix PR comments 2
dd56fc3
to
c2fd4e5
Compare
The following is the coverage report on pkg/.
|
Is this to be expected @adrcunha ? Docs don't seem to indicate any requirements to see these logs: https://github.com/knative/docs/blob/9f8fe54d315f6a2ba32d3dadfc39312b44922f53/community/CONTRIBUTING.md#pull-requests (maybe you need to be a member of |
Seems, like tests pathed can we merge now? |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bobcatfish, vdemeester, Zyqsempai The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fix image replacement
Fixed: #333
Open questions:
sha256:bla-bla-bla
, but we have NewDigest function inside this step https://github.com/knative/build-pipeline/blob/master/pkg/reconciler/v1alpha1/taskrun/entrypoint/entrypoint.go#L123 which one wait for next pattern:image@sha256:bla-bla-bla
, so who is right here?