-
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
Check labels in e2e PipelineRun tests and document label propagation #500
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,26 @@ of the `TaskRun` resource object. | |
For examples and more information about specifying service accounts, see the | ||
[`ServiceAccount`](./auth.md) reference topic. | ||
|
||
## Labels | ||
|
||
Any labels specified in the metadata field of a `PipelineRun` will be | ||
propagated to the `TaskRuns` created automatically for each `Task` in the | ||
`Pipeline` and then to the `Pods` created for those `TaskRuns`. In addition, | ||
the following labels will be added automatically: | ||
|
||
* `pipeline.knative.dev/pipeline` will contain the name of the `Pipeline` | ||
* `pipeline.knative.dev/pipelineRun` will contain the name of the `PipelineRun` | ||
|
||
These labels make it easier to find the resources that are associated with a | ||
given pipeline. | ||
|
||
For example, to find all `Pods` created by a `Pipeline` named test-pipeline, | ||
you could use the following command: | ||
|
||
```shell | ||
kubectl get pods --all-namespaces -l pipeline.knative.dev/pipeline=test-pipeline | ||
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. niiiice |
||
``` | ||
|
||
## Cancelling a PipelineRun | ||
|
||
In order to cancel a running pipeline (`PipelineRun`), you need to update its | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,8 @@ func TestPipelineRun(t *testing.T) { | |
td.testSetup(t, c, namespace, i) | ||
|
||
prName := fmt.Sprintf("%s%d", pipelineRunName, i) | ||
if _, err := c.PipelineRunClient.Create(td.pipelineRunFunc(i, namespace)); err != nil { | ||
pr, err := c.PipelineRunClient.Create(td.pipelineRunFunc(i, namespace)) | ||
if err != nil { | ||
t.Fatalf("Failed to create PipelineRun `%s`: %s", prName, err) | ||
} | ||
|
||
|
@@ -160,14 +161,36 @@ func TestPipelineRun(t *testing.T) { | |
if !r.Status.GetCondition(duckv1alpha1.ConditionSucceeded).IsTrue() { | ||
t.Fatalf("Expected TaskRun %s to have succeeded but Status is %v", taskRunName, r.Status) | ||
} | ||
for name, key := range map[string]string{ | ||
pipelineRunName: pipeline.PipelineRunLabelKey, | ||
pipelineName: pipeline.PipelineLabelKey, | ||
} { | ||
expectedName := getName(name, i) | ||
lbl := pipeline.GroupName + key | ||
if val := r.Labels[lbl]; val != expectedName { | ||
t.Errorf("Expected label %s=%s but got %s", lbl, expectedName, val) | ||
|
||
// Check label propagation to Tasks | ||
labels := make(map[string]string, len(pr.ObjectMeta.Labels)+3) | ||
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. why +3 here? (maybe explain with a comment or a 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.
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. Added a comment in 37ed488 |
||
for key, val := range pr.ObjectMeta.Labels { | ||
labels[key] = val | ||
} | ||
labels[pipeline.GroupName+pipeline.PipelineLabelKey] = getName(pipelineName, i) | ||
labels[pipeline.GroupName+pipeline.PipelineRunLabelKey] = getName(pipelineRunName, i) | ||
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. what is the significance of 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. Yeah those are static labels added by the controller, but definitely could use a comment. 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. Added a comment two lines up in 37ed488 |
||
for key, pipelineRunVal := range labels { | ||
if taskRunVal := r.ObjectMeta.Labels[key]; taskRunVal != pipelineRunVal { | ||
t.Errorf("Expected label %s=%s but got %s", key, pipelineRunVal, taskRunVal) | ||
} | ||
} | ||
|
||
// Check label propagation to Pods | ||
taskRunLabelKey := pipeline.GroupName + pipeline.TaskRunLabelKey | ||
labels[taskRunLabelKey] = taskRunName | ||
pods, err := c.KubeClient.Kube.CoreV1().Pods(namespace).List(metav1.ListOptions{ | ||
LabelSelector: taskRunLabelKey + " = " + taskRunName, | ||
}) | ||
if err != nil { | ||
t.Fatalf("Couldn't get expected Pod for %s: %s", taskRunName, err) | ||
} | ||
if numPods := len(pods.Items); numPods != 1 { | ||
t.Fatalf("Expected 1 Pod for %s, but got %d Pods", taskRunName, numPods) | ||
} | ||
pod := pods.Items[0] | ||
for key, taskRunVal := range labels { | ||
if podVal := pod.ObjectMeta.Labels[key]; podVal != taskRunVal { | ||
t.Errorf("Expected label %s=%s but got %s", key, taskRunVal, podVal) | ||
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. total nitpick: could these be in a separate function called by the test? for the same of readability (test is getting long!) 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. Yeah good point, I'll separate it out! 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. Did some refactoring in 37ed488, let me know if that seems good or if you'd like to see a totally separate |
||
} | ||
} | ||
} | ||
|
@@ -322,10 +345,12 @@ func getPipelineRunSecret(suffix int, namespace string) *corev1.Secret { | |
} | ||
|
||
func getHelloWorldPipelineRun(suffix int, namespace string) *v1alpha1.PipelineRun { | ||
return tb.PipelineRun(getName(pipelineRunName, suffix), namespace, tb.PipelineRunSpec( | ||
getName(pipelineName, suffix), | ||
tb.PipelineRunServiceAccount(fmt.Sprintf("%s%d", saName, suffix)), | ||
)) | ||
return tb.PipelineRun(getName(pipelineRunName, suffix), namespace, | ||
tb.PipelineRunLabel("hello-world-key", "hello-world-value"), | ||
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 just adds a custom label to the 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 looks good. Thank you @dwnusbaum |
||
tb.PipelineRunSpec(getName(pipelineName, suffix), | ||
tb.PipelineRunServiceAccount(fmt.Sprintf("%s%d", saName, suffix)), | ||
), | ||
) | ||
} | ||
|
||
func getName(namespace string, suffix int) 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.
This seemed like the least bad place for the docs, but I don't know if it really fits. Any suggestions are welcome!
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 had trouble thinking of a good place myself! the only other alternative i can think of is to create a new doc like
troubleshooting.md
orfaq.md
ortips.md
or something but none of those options seem great either 🤔 this seems fine for now tho if you don't like any of those ideas!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.
Yeah, it seems kind of weird to create a new file just for this information. My preference would be to leave it for now, and then if we end up with other troubleshooting-esque docs we can refactor them into a single place later. Does that seem ok?