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

Enable sidecars to partake in substitution #1770

Merged
merged 1 commit into from
Jan 10, 2020

Conversation

MLBMatt
Copy link
Contributor

@MLBMatt MLBMatt commented Dec 19, 2019

This change enables sidecars to use variable subtitution and leverage
pipeline-specific params to execute whatever actions during a
pipelinerun.

Fixes #1761

Changes

This change enables sidecars to use variable subtitution and leverage
pipeline-specific params to execute whatever actions during a
pipelinerun.

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:

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

Task sidecars now partake in variable substitution.

@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 Dec 19, 2019
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 19, 2019
@tekton-robot
Copy link
Collaborator

Hi @MLBMatt. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 19, 2019

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit and removed cla: no labels Dec 19, 2019
@imjasonh
Copy link
Member

/ok-to-test

Thanks for this! Can you add a YAML example that demonstrates this works? This serves as a runnable sample, and as a test that this continues to work as expected.

Also, please provide release notes for this user visible change.

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 19, 2019
@MLBMatt MLBMatt marked this pull request as ready for review December 19, 2019 18:03
@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 Dec 19, 2019
@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 19, 2019

@imjasonh Added a yaml example to the docs, added a bit more implementation, updated more to the tests and added release notes.

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 19, 2019

/retest

@imjasonh
Copy link
Member

@imjasonh Added a yaml example to the docs, added a bit more implementation, updated more to the tests and added release notes.

Thanks for adding the example to the docs. If you add a working example to examples/taskrun/ we'll make sure the run succeeds during presubmit tests.

Something like sidecar-ready.yaml:

spec:
  taskSpec:
    inputs:
      params:
      - name: value
        default: default-value
    sidecars:
    - name: slow-sidecar
      image: ubuntu
      command:
      - sh
      - -c
      - echo $(inputs.params.value) > /shared/value && sleep infinity
      volumeMounts:
      - name: shared
        mountPath: /shared

    steps:
    - image: ubuntu
      # The step will only succeed if the sidecar resolved the param value.
      script: |
        #!/usr/bin/env bash
        VALUE=$(cat /shared/value)
        [[ $VALUE == $(inputs.params.value) ]]
      volumeMounts:
      - name: shared
        mountPath: /shared

(I haven't tested this, but something like it should work, and prove that params are resolved in the sidecar)

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 20, 2019

@imjasonh I added an example, however I couldn't get it working locally because of, what looks like, the noop bug associated with sidecars. I couldn't get your sidecar-ready.yaml example working either, so I'm not sure if it's me or tekton.

@ghost
Copy link

ghost commented Dec 20, 2019

@MLBMatt Can you describe a bit the problems you encountered? I was able to get your example working with the code on your branch but I'd like to understand the issue you're seeing before giving this a 👍

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 20, 2019

@sbwsg I was defining a command for my sidecar however it looked like the sleep was never running correctly, was being replaced by the tianon/true image and complaining about not finding shell to execute.

I've seen that, in order for the sidecar to be killed correctly, the sidecar is modified to exit cleanly but for me, this looked to still be broken on my end? Maybe I don't have the latest controller version?

@ghost
Copy link

ghost commented Dec 20, 2019

Ah ok great that's actually expected behaviour! In order to stop sidecars when the task steps finish we have to replace the image of the sidecar's container. Bit wonky but it (mostly) works until k8s supports sidecar lifecycle containers natively.

@ghost
Copy link

ghost commented Dec 20, 2019

(Just to confirm - did the TaskRun end with a successful status?)

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 20, 2019

@sbwsg Ah ok, yes the task container ended in a Completed state and looks all good. I think things were just getting muddled a bit.

edit: Well the pod itself ends in a ContainerCannotRun state, caused by trying to run /bin/sh on the tianon/true image. I'm not sure if Tekton evaluates this still to a successful run or not.

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 20, 2019

I get a status Failed on the actual taskrun pod because:

Error: failed to start container "sidecar-value-sidecar": Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown

This from the replaced tianon/true image trying to run the previous value-sidecar's command/args.

@ghost
Copy link

ghost commented Dec 20, 2019

Tekton ignores the failure of the sidecar container. The TaskRun ends with a condition of Succeeded / True and the step-check-value Step has an exit code of 0 with reason Completed (at least on my machine). I think we're all good here in terms of this example.

Edit: sidecar pod -> sidecar container

@MLBMatt
Copy link
Contributor Author

MLBMatt commented Dec 20, 2019

@sbwsg awesome! 🎉

@ghost
Copy link

ghost commented Dec 20, 2019

/lgtm

@tekton-robot tekton-robot assigned ghost Dec 20, 2019
@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 20, 2019
corev1 "k8s.io/api/core/v1"
)

func ApplyContainerReplacements(step *corev1.Container, stringReplacements map[string]string, arrayReplacements map[string][]string) {
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this doesn't need to be exported, except to be tested in container_replacements_test.go.

Can we either test this as an unexported method, or only test the exported surface in apply_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@imjasonh it's also used in https://github.com/tektoncd/pipeline/pull/1770/files#diff-768a3668fda546db3140aa35963e1247R25, not sure if that still warrants not exporting (I'm super new to Go, so the import/export semantics elude me a bit right now)

Copy link

Choose a reason for hiding this comment

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

Indeed, looks like this is used by the resources package as well and so needs to live on as exported for the time being 👍

examples/taskruns/sidecar-interp.yaml Outdated Show resolved Hide resolved
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jan 6, 2020
@MLBMatt MLBMatt requested a review from imjasonh January 7, 2020 21:10
@ghost
Copy link

ghost commented Jan 10, 2020

@MLBMatt thanks for the PR, could you squash the commits, rebase on top of latest master, and ensure that the commit message continues to match the PR description you've included here (after all the squashing is done)?

I think otherwise this is looking ready to merge. Many thanks! 🙏

This change enables sidecars to use variable subtitution and leverage
pipeline-specific params to execute whatever actions during a
pipelinerun.

Fixes tektoncd#1761
@MLBMatt
Copy link
Contributor Author

MLBMatt commented Jan 10, 2020

@sbwsg squashed and rebased 👍

@ghost
Copy link

ghost commented Jan 10, 2020

/approve

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

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 Jan 10, 2020
@ghost
Copy link

ghost commented Jan 10, 2020

/retest

1 similar comment
@ghost
Copy link

ghost commented Jan 10, 2020

/retest

@ghost
Copy link

ghost commented Jan 10, 2020

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2020
@tekton-robot tekton-robot merged commit f157f33 into tektoncd:master Jan 10, 2020
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

Allow sidecars to use input params/tekton pod labels
4 participants