-
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
Check labels in e2e PipelineRun tests and document label propagation #500
Conversation
The e2e tests in test/pipelinerun.go now assert that custom labels set on the PipelineRun are propagated through to the TaskRun and Pod, and that the static labels that are added to all TaskRuns and Pods are propagated correctly as well. In addition, documentation has been added to explain that labels are propagated and to mention the specific labels that are added automatically to generated TaskRuns and Pods. Follow-up to tektoncd#488.
@@ -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 |
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
or faq.md
or tips.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?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This just adds a custom label to the service account propagation
test. @shashwathi is that what you had in mind, or do you think I should create a separate test for labels specifically? (I wasn't sure how conservative we wanted to be about adding new e2e 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.
This looks good. Thank you @dwnusbaum
/ok-to-test (Still waiting to hear back on adding you to the org @dwnusbaum , sorry for the delay!!) |
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.
A bit of misc. feedback from me! I won't /lgtm
without a review from @shashwathi as well but for now anyway:
/approve
@@ -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 |
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
or faq.md
or tips.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!
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 comment
The reason will be displayed to describe this comment to others. Learn more.
niiiice
test/pipelinerun_test.go
Outdated
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 comment
The 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 comment
The 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 comment
The 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 assertLabels
function with all the label-related stuff to simplify further.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
why +3 here? (maybe explain with a comment or a const
?)
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.
len(pr.ObjectMeta.Labels)
for custom labels, +2
for the static pipeline/pipelineRun label from the PipelineRun controller, and +1
for the taskRun label from the TaskRun
controller. I'll add a comment 😄
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 a comment in 37ed488
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 comment
The reason will be displayed to describe this comment to others. Learn more.
what is the significance of pipeline.GroupName+pipeline.PipelineRunLabelKey
and pipeline.GroupName+pipeline.PipelineLabelKey
? (i assume these correspond to some label generation logic in the controller - maybe a comment here would help?)
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment two lines up in 37ed488
/retest since CI failure appears to be infra related:
|
/retest |
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
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Thank you @dwnusbaum
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bobcatfish, dwnusbaum, shashwathi 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 |
The e2e tests in test/pipelinerun.go now assert that custom labels set on the PipelineRun are propagated through to the TaskRun and Pod, and that the static labels that are added to all TaskRuns and Pods are propagated correctly as well.
In addition, documentation has been added to explain that labels are propagated and to mention the specific labels that are added automatically to generated TaskRuns and Pods.
This is a follow-up to #488.
CC @shashwathi @bobcatfish