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

fix: debug scripts are not mounted to steps with no scripts #4776

Merged

Conversation

yuzp1996
Copy link
Contributor

@yuzp1996 yuzp1996 commented Apr 19, 2022

Changes

Update debug script mount logic

When the step script is empty then the logic which mounts the debug
script will skip for the container and the signal of placeScripts
will be the default value false which causes no debug script volume
will be mounted.

Now it will check the breakpoint first, if the breakpoint is not null
then will add volume Mount for container no matter the script
is empty or not.

And if the breakpoint is not null then will set the signal placeScripts
to be true while it used to be true only when the script is not empty.

related issue: #4613

/kind bug

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Docs included if any changes are user facing
  • Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Release notes block below has been filled in
    (if there are no user facing changes, use release note "NONE")

Release Notes

NONE

@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 19, 2022
@tekton-robot
Copy link
Collaborator

Hi @yuzp1996. 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.

@tekton-robot tekton-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 19, 2022
@yuzp1996 yuzp1996 changed the title fix: debug scripts are not mounted to steps with no scripts [WIP]fix: debug scripts are not mounted to steps with no scripts Apr 19, 2022
@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 Apr 19, 2022
@vdemeester
Copy link
Member

/ok-to-test

@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 Apr 20, 2022
@yuzp1996 yuzp1996 force-pushed the fix/arg-taskrun-no-debug-script branch from b97c1cd to 41f2844 Compare April 20, 2022 22:44
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 20, 2022
@yuzp1996 yuzp1996 force-pushed the fix/arg-taskrun-no-debug-script branch from 41f2844 to adb43ec Compare April 20, 2022 22:47
@yuzp1996
Copy link
Contributor Author

/retest

@yuzp1996 yuzp1996 closed this Apr 20, 2022
@yuzp1996 yuzp1996 reopened this Apr 20, 2022
@yuzp1996 yuzp1996 changed the title [WIP]fix: debug scripts are not mounted to steps with no scripts fix: debug scripts are not mounted to steps with no scripts Apr 20, 2022
@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 Apr 20, 2022
@yuzp1996 yuzp1996 force-pushed the fix/arg-taskrun-no-debug-script branch from adb43ec to e7d18df Compare April 21, 2022 03:02
@yuzp1996
Copy link
Contributor Author

/retest

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

@yuzp1996
Copy link
Contributor Author

@vdemeester @bobcatfish @jerop @waveywaves I am sorry to bother you guys. If you have time to help review this PR I will be very appreciative! Thank you!

If there is anything I need to do please tell me. Thank you again!

@waveywaves
Copy link
Member

Hey, thanks for the PR ! I'll take a look at it today.

@waveywaves
Copy link
Member

Again, thanks for the PR.

I can see that debug is mounted if scripts are not present as well. I have tested this with the kn task.

kubectl exec -it kn-pod -- /bin/sh
Defaulted container "step-kn" out of: step-kn, place-tools (init), step-init (init), place-scripts (init)
/ # ls /tekton
bin          debug        home         run          termination
creds        downward     results      steps

Comment on lines +203 to +205
// If breakpoint is not nil then should add the init container
// to write debug script files
Copy link
Member

Choose a reason for hiding this comment

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

InitContainers: []corev1.Container{placeToolsInit, tektonDirInit(images.EntrypointImage, []v1beta1.Step{{Container: corev1.Container{Name: "name"}}})},
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{placeToolsInit, tektonDirInit(images.EntrypointImage, []v1beta1.Step{{Container: corev1.Container{Name: "name"}}}),
{
Copy link
Member

Choose a reason for hiding this comment

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

Can you extract this Container as it's own variable called placeScriptsInit as you have done for containerVolumeMounts ? It would look much cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 4, 2022
@yuzp1996
Copy link
Contributor Author

yuzp1996 commented May 8, 2022

Again, thanks for the PR.

I can see that debug is mounted if scripts are not present as well. I have tested this with the kn task.

kubectl exec -it kn-pod -- /bin/sh
Defaulted container "step-kn" out of: step-kn, place-tools (init), step-init (init), place-scripts (init)
/ # ls /tekton
bin          debug        home         run          termination
creds        downward     results      steps

Hi, this is the task and taskrun I use to reproduce the error in a local deployment environment that is deployed with the latest commit from the master branch

Task with script 

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: hello
spec:
  steps:
    - name: hello
      image: ubuntu
      env:
      - name: WORKSPACE_SOURCE_PATH
        value: $(workspaces.source.path)
      - name: WORKSPACE_ARTIFACTS_PATH
        value: $(workspaces.artifacts.path)
      script: |
        #!/usr/bin/env bash
        echodd "Hello from Bash!"

Task with args and command

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: hello
spec:
  steps:
    - name: hello
      image: ubuntu
      env:
      - name: WORKSPACE_SOURCE_PATH
        value: $(workspaces.source.path)
      - name: WORKSPACE_ARTIFACTS_PATH
        value: $(workspaces.artifacts.path)
      command:
        - echodd
      args:
        - "Hello from Bash!"

Above tasks can be referred to by the same taskrun 

apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  generateName: hello-run-arg-
spec:
  debug:
    breakpoint: [ "onFailure" ]
  taskRef:
    name: hello

this is the result that I get. @waveywaves

F6BF32C6-8367-4E05-ADDF-D09579FAA05B

When the step script is empty then the logic which mounts the debug
script will skip for the container and the signal of placeScripts
will be the default value false which causes no debug script volume
will be mounted.

Now it will check the breakpoint first, if the breakpoint is not null
then will add volume Mount for container no matter weather the script
is empty or not.

And if the breakpoint is not null then will set the signal placeScripts
to be true while it used to be true only when the script is not empty.

related issue:  tektoncd#4613

Signed-off-by: yuzhipeng <[email protected]>
@yuzp1996 yuzp1996 force-pushed the fix/arg-taskrun-no-debug-script branch from e7d18df to 87a4d99 Compare May 8, 2022 13:25
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 8, 2022
@yuzp1996
Copy link
Contributor Author

yuzp1996 commented May 8, 2022

Because there were some conflict changes I spend some time fixing that. Now I have modified the code and the PR is ready to be merged. I will be very appreciative if you can review this PR.

I am not good at English now If there is any offence please forgive me and tell me.

Thanks again! @waveywaves

@yuzp1996
Copy link
Contributor Author

yuzp1996 commented May 8, 2022

/retest

@@ -371,7 +371,7 @@ func makeLabels(s *v1beta1.TaskRun) map[string]string {
return labels
}

// shouldAddReadyAnnotationonPodCreate returns a bool indicating whether the
// shouldAddReadyAnnotationOnPodCreate returns a bool indicating whether the
Copy link
Contributor Author

@yuzp1996 yuzp1996 May 11, 2022

Choose a reason for hiding this comment

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

I find that the comment does not start with the function name, so I change it.

@@ -130,9 +130,18 @@ func convertScripts(shellImageLinux string, shellImageWin string, steps []v1beta
func convertListOfSteps(steps []v1beta1.Step, initContainer *corev1.Container, placeScripts *bool, breakpoints []string, namePrefix string) []corev1.Container {
containers := []corev1.Container{}
for i, s := range steps {
// Add debug mounts if breakpoints are present
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I move the logic of adding debug script before judging the script make sure it can work well no matter s.Script is empty or not.

@yuzp1996
Copy link
Contributor Author

Hi @waveywaves, I am sorry to bother you again. I fixed the code conflict and add some comments to help understand the change I made. I would be very grateful if you could take the time to help me review this PR and give me your valuable suggestions. Thanks!

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label May 12, 2022
@yuzp1996 yuzp1996 requested review from vdemeester and waveywaves and removed request for waveywaves May 12, 2022 23:01
@waveywaves
Copy link
Member

Hey @yuzp1996
This looks good to me ! I ran it once again and can confirm that it works. Thanks for fixing this one 💯

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 15, 2022
@yuzp1996
Copy link
Contributor Author

Hey @yuzp1996 This looks good to me ! I ran it once again and can confirm that it works. Thanks for fixing this one 💯

/lgtm

Thanks for your lgtm! It is important to me! @waveywaves

Is there anything else I need to do to merge this PR? Maybe an approval? @waveywaves @vdemeester

Sorry, I don't know if I should be in such a hurry. If there is anything I did that made you feel not good please tell me and I will be happy to accept your suggestions. Thanks again!

@abayer
Copy link
Contributor

abayer commented May 17, 2022

/assign
/assign @vdemeester

@tekton-robot
Copy link
Collaborator

[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 /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 May 20, 2022
@tekton-robot tekton-robot merged commit e6c7eb0 into tektoncd:main May 20, 2022
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. kind/bug Categorizes issue or PR as related to a bug. 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

5 participants