-
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
Add Script Support to Sidecars #1987
Add Script Support to Sidecars #1987
Conversation
This makes a sidecar behave like a Step, and allows the ability to pass a script argument. This enables tektoncd#1856. Signed-off-by: Tom George <tg82490@gmail.com>
Hi @tomgeorge. Thanks for your PR. I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
Nice! thank you! I think one thing missing would be a yaml in the examples directory which are used in CI for validation too.. |
I'll add an example this evening |
Signed-off-by: Tom George <tg82490@gmail.com>
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.
/meow
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vdemeester 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 |
- name: check-ready | ||
image: ubuntu | ||
# The step will only succeed if the sidecar has written this file, which | ||
# it does 5s after it starts, before it reports Ready. |
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 think I'm missing something here - where is the 5s delay happening? And what is meant here by the sidecar reporting Ready?
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.
That was me copy/pasting another example without deleting the comments. It isn't really waiting for anything to be ready.
pkg/pod/pod_test.go
Outdated
}}}, | ||
Sidecars: []v1alpha1.Sidecar{ | ||
{ | ||
Container: corev1.Container{ |
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.
Suggest collapsing these brackets to match format with the Step on line 404. Similarly for the init container on line 422.
pkg/pod/script.go
Outdated
// | ||
// It iterates through the list of steps (or sidecars), generates the script file name and heredoc termination string, | ||
// adds an entry to the init container args, sets up the step container to run the script, and sets the volume mounts. | ||
func convertListOfSteps(steps []v1alpha1.Step, initContainer *corev1.Container, placeScripts *bool, format string) []corev1.Container { |
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.
suggest "namePrefix" instead of "format" here, since the value isn't expected to be a format string.
// | ||
// It does this by prepending a container that writes specified Script bodies | ||
// to executable files in a shared volumeMount, then produces Containers that | ||
// simply run those executable files. | ||
func convertScripts(shellImage string, steps []v1alpha1.Step) (*corev1.Container, []corev1.Container) { | ||
func convertScripts(shellImage string, steps []v1alpha1.Step, sidecars []v1alpha1.Sidecar) (*corev1.Container, []corev1.Container, []corev1.Container) { |
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.
Rather than amending the signature and adding the extra func to account for Sidecars, couldn't the caller (MakePod) simply execute this function twice? Once for Steps and once for Sidecars?
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.
Yes you can definitely do the same thing that way. I think in order to do that you need to change the signature of convertScripts
anyways to include context about the namePrefix. Would you prefer I changed it to that?
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.
That would be excellent, thank you @tomgeorge !
Signed-off-by: Tom George <tg82490@gmail.com>
@sbwsg I made the formatting/comment changes you requested. I need to think a little bit more about the best way to make the |
Signed-off-by: Tom George <tg82490@gmail.com>
/test pull-tekton-pipeline-integration-tests |
@tomgeorge building up the script in the init container definitely complicates things. Looking at it again I think your original solution is good. I was initially wary of the passing a pointer to the placeScripts bool and init container but given the way the code worked before this change I think yours is a sound approach. So I'm happy to leave things as-is with the two formatting changes. /lgtm |
Changes
This makes a sidecar behave like a Step, and allows the ability to pass a script argument.
This enables #1856.
To implement this, I created a
Sidecar
type that was the same asStep
.I then changed
convertScripts
to accept an image, a slice of steps, and a slice of sidecars, and return the init container, and two lists of containers: one for steps, and one for sidecars.I also refactored
convertScripts
to call a helper function,convertListOfSteps
, that takes a list of steps to convert, a pointer to the init container to add to, a pointer toplaceScripts
, and a format string for writing out the heredoc and temp file names. It returns the converted list of containers.convertListOfSteps
does most of the work thatconvertScripts
does. It might be a little ugly but it seemed better than putting everything inconvertScripts
. Unfortunately this doesn't translate very well to the Github PR viewer, but git diff works fineSubmitter 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.
Reviewer Notes
If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.
Release Notes