-
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
Make TestKanikoTaskRun more portable #1516
Make TestKanikoTaskRun more portable #1516
Conversation
7494f85
to
3138ad3
Compare
test/kaniko_task_test.go
Outdated
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'"}, |
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'm gonna push some images to plumbing
to use it instead of this hack 👼
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.
gcr.io/tekton-releases/dogfooding/skopeo is now available
test/kaniko_task_test.go
Outdated
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) | ||
} | ||
} |
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 part could be done as an option to setup(t)
👼
189e76e
to
c5559f4
Compare
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]>
ca91307
to
74bff77
Compare
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.
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.
test/kaniko_task_test.go
Outdated
RestartPolicy: corev1.RestartPolicyNever, | ||
}, | ||
}); err != nil { | ||
t.Fatalf("Failed to create the local registry service: %v", 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.
The log message doesn't look right here?
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.
oh yeah, my bad =)
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
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]>
74bff77
to
5dfe457
Compare
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
/approve
went back and forth with vincent offline on this and explained how it works, nicely done 👍
/approve |
[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 |
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 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) |
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 we use wait for to poll the pod instead?
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.
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 😉
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.
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
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 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) { |
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.
so cool!!!
}, | ||
}, | ||
} | ||
} |
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 feel like these functions are super cool and reusable - what do you think about putting them in their own package and having docstrings?
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.
@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'"}, |
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 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)
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.
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 😹)
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
andjq
to get theremote 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:
cmd
dir, please updatethe release Task to build and release this image.