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

Added digest cache, store digest instead of tags, added test #396

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

Zyqsempai
Copy link
Contributor

@Zyqsempai Zyqsempai commented Jan 16, 2019

  1. Added new cache instans for image -> digest step caching.
  2. Moved common functionality for fetching remote image to dedicated function
  3. Added test for tag -> digest functionality

Fixed: #333

Open questions:

  1. The Digest pattern are the next 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?
  2. In the case of cold cache we will be forced to warmup two caches instead of one, this can affect on perfomance.

@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 16, 2019
@Zyqsempai
Copy link
Contributor Author

cc @imjasonh @bobcatfish

@bobcatfish
Copy link
Collaborator

/ok-to-test

@knative-prow-robot knative-prow-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 16, 2019
Copy link
Collaborator

@bobcatfish bobcatfish left a 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
Copy link
Collaborator

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) {
Copy link
Collaborator

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
Copy link
Collaborator

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?

Copy link
Contributor Author

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
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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 👍

Copy link
Member

@vdemeester vdemeester Jan 16, 2019

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)
Copy link
Collaborator

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

Copy link
Contributor Author

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;)

Copy link
Collaborator

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) {
Copy link
Collaborator

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!)

Copy link
Member

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
}

Copy link
Collaborator

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 16, 2019
Copy link
Member

@vdemeester vdemeester left a 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) {
Copy link
Member

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
}

@Zyqsempai
Copy link
Contributor Author

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)
Copy link
Member

@vdemeester vdemeester Jan 16, 2019

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 😅

@Zyqsempai
Copy link
Contributor Author

@vdemeester Could you please post the failed test stucktrace, or another info, coz seems like i just doesn't have access to gubernator.knative.dev

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)
Copy link
Member

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

@vdemeester
Copy link
Member

vdemeester commented Jan 16, 2019

@Zyqsempai the errors indicates the image reference seems to be wrong

status:
  conditions:
  - lastTransitionTime: "2019-01-16T15:42:04Z"
    message: 'References a Task arendelle-uvyhvmae/helm-reset-task that doesn''t exist:  could
      not get entrypoint from registry for alpine/helm: couldn''t get config for image
      sha256:1cc169daeea16a0011753c5727001f35142327c8f4dcb181558fc2ed04ad17f6: UNAUTHORIZED:
      "authentication required"'
    reason: CouldntGetTask
    status: "False"
    type: Succeeded
  podName: ""

See my comment above ^^

@Zyqsempai
Copy link
Contributor Author

@vdemeester Seems like it's related to the problem with Digest you mentioned above.

@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-build-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/taskrun/entrypoint/entrypoint.go 83.8% 80.8% -3.0
pkg/reconciler/v1alpha1/taskrun/taskrun.go 72.7% 71.3% -1.3

@bobcatfish
Copy link
Collaborator

bobcatfish commented Jan 16, 2019

@vdemeester Could you please post the failed test stucktrace, or another info, coz seems like i just doesn't have access to gubernator.knative.dev

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 knative-dev@ the knative org?)

@Zyqsempai
Copy link
Contributor Author

Seems, like tests pathed can we merge now?

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 17, 2019
@knative-prow-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit f2c5037 into tektoncd:master Jan 17, 2019
piyush-garg pushed a commit to piyush-garg/pipeline that referenced this pull request May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants