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

Make TestKanikoTaskRun more portable #1516

Merged
merged 2 commits into from
Nov 8, 2019

Conversation

vdemeester
Copy link
Member

Changes

This test could, previously, only run on specific environment, and
would depend on GCP on the CI. This is not more the case with this
changes as it is now able to run on any kubernetes.

We start a registry in the same namespace the test happens, and we
push build/push the image on this local registry. To validate the
digest, we need to run a new pod using skopeo and jq to get the
remote digest.

Marking it as wip for now as it needs a little bit of refactoring 👼

Signed-off-by: Vincent Demeester [email protected]

/cc @afrittoli @bobcatfish @imjasonh

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 4, 2019
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Nov 4, 2019
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 4, 2019
@vdemeester vdemeester force-pushed the test-e2e-portable-kaniko branch from 7494f85 to 3138ad3 Compare November 4, 2019 12:39
Name: "skopeo",
Image: "quay.io/rhpipeline/skopeo:alpine",
Command: []string{"/bin/sh", "-c"},
Args: []string{"apk add --no-cache jq 1>/dev/null; skopeo inspect --tls-verify=false docker://" + image + ":latest| jq '.Digest'"},
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm gonna push some images to plumbing to use it instead of this hack 👼

Copy link
Member

Choose a reason for hiding this comment

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

gcr.io/tekton-releases/dogfooding/skopeo is now available

Comment on lines 56 to 76
if _, err := c.KubeClient.Kube.AppsV1().Deployments(namespace).Create(getRegistryDeployment(namespace)); err != nil {
t.Fatalf("Failed to create the local registry deployment: %v", err)
}
service := getRegistryService(namespace)
if _, err := c.KubeClient.Kube.CoreV1().Services(namespace).Create(service); err != nil {
t.Fatalf("Failed to create the local registry service: %v", err)
}
set := labels.Set(service.Spec.Selector)
if pods, err := c.KubeClient.Kube.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: set.AsSelector().String()}); err != nil {
t.Fatalf("Failed to list Pods of service[%s] error:%v", service.GetName(), err)
} else {
if len(pods.Items) != 1 {
t.Fatalf("Only 1 pod for service %s should be running: %v", service, pods.Items)
}

if err := WaitForPodState(c, pods.Items[0].Name, namespace, func(pod *corev1.Pod) (bool, error) {
return pod.Status.Phase == "Running", nil
}, "PodContainersRunning"); err != nil {
t.Fatalf("Error waiting for Pod %q to run: %v", pods.Items[0].Name, err)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This part could be done as an option to setup(t) 👼

@vdemeester vdemeester force-pushed the test-e2e-portable-kaniko branch 2 times, most recently from 189e76e to c5559f4 Compare November 4, 2019 13:59
@vdemeester vdemeester changed the title wip: Make TestKanikoTaskRun more portable Make TestKanikoTaskRun more portable Nov 4, 2019
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 4, 2019
This test could, previously, only run on specific environment, and
would depend on GCP on the CI. This is not more the case with this
changes as it is now able to run on any kubernetes.

We start a registry in the same namespace the test happens, and we
push build/push the image on this local registry. To validate the
digest, we need to run a new pod using `skopeo` and `jq` to get the
remote digest.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the test-e2e-portable-kaniko branch from ca91307 to 74bff77 Compare November 5, 2019 10:21
Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Thank you for this, I think it's a great direction for us to go.
I have a couple of comments - mainly I'm concerned with cleanup and isolation across tests.

RestartPolicy: corev1.RestartPolicyNever,
},
}); err != nil {
t.Fatalf("Failed to create the local registry service: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

The log message doesn't look right here?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yeah, my bad =)

test/kaniko_task_test.go Show resolved Hide resolved
test/init_test.go Show resolved Hide resolved
Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 5, 2019
And use this to extract the "local" registry part of TestKanikoTaskRun
into a separate function, reusable in other tests.

Signed-off-by: Vincent Demeester <[email protected]>
@vdemeester vdemeester force-pushed the test-e2e-portable-kaniko branch from 74bff77 to 5dfe457 Compare November 5, 2019 13:58
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 5, 2019
Copy link
Member

@chmouel chmouel left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

went back and forth with vincent offline on this and explained how it works, nicely done 👍

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 8, 2019
@dlorenc
Copy link
Contributor

dlorenc commented Nov 8, 2019

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chmouel, dlorenc

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 8, 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.

This is super cool!!! I think there are a few places where I feel like future explorers might benefit from some additional docstrings + comments but otherwise this is beautiful!!! 😍

set := labels.Set(service.Spec.Selector)

// Give it a little bit of time to at least create the pod
time.Sleep(5 * time.Second)
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we use wait for to poll the pod instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are actually waiting for the pod below, this is to give a little bit of time for the kube api-server to actually create the pod… (didn't find a good way on the service status to get that information for some reason). We may refine that though 😉

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm shouldn't we be able to query the kube api for the status before the pod is actually created?

i just find that generally arbitrarily sleeping in tests tends to cause pain over time (5 seconds can be a really long time sometimes) - even (or maybe especially) when the test is already pretty slow

Copy link
Member Author

Choose a reason for hiding this comment

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

i just find that generally arbitrarily sleeping in tests tends to cause pain over time (5 seconds can be a really long time sometimes) - even (or maybe especially) when the test is already pretty slow

I cannot agree more with " generally arbitrarily sleeping in tests tends to cause pain over time" 😛 The main problem with service is that the status is pretty "bare", there is only loadBalancer in there 🤦‍♂️. That said, I think I should be able to watch the deployment instead 👼 I'll include that in my follow-up 😉

"k8s.io/apimachinery/pkg/labels"
)

func withRegistry(t *testing.T, c *clients, namespace string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

so cool!!!

},
},
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

i feel like these functions are super cool and reusable - what do you think about putting them in their own package and having docstrings?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bobcatfish this is doable indeed 👼 I wanted to port more tests (like the helm one, …) before to see if I need to refine them before extracting them 👼

Name: "skopeo",
Image: "gcr.io/tekton-releases/dogfooding/skopeo:latest",
Command: []string{"/bin/sh", "-c"},
Args: []string{"skopeo inspect --tls-verify=false docker://" + image + ":latest| jq '.Digest'"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

i feel like this and/or the function could use some comments to explain what skopeo is, what the function is all about and how exactly it determines the digest (looks like specifically looking for image with tag latest - which would mean if you don't tag latest, it wont work)

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, I'll follow-up on this to add the comment on the function 👼
Also I feel the function name could be more explicit (like getRemoteDigestFromTheInside or something like that 😹)

@tekton-robot tekton-robot merged commit 50cf4bc into tektoncd:master Nov 8, 2019
@vdemeester vdemeester deleted the test-e2e-portable-kaniko branch November 8, 2019 15:05
@vdemeester vdemeester mentioned this pull request Nov 12, 2019
3 tasks
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit 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.

7 participants