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

Refactor Sidecar Containers Construction If Script Exists #6619

Merged
merged 1 commit into from
May 5, 2023

Conversation

XinruZhang
Copy link
Member

@XinruZhang XinruZhang commented May 3, 2023

Changes

Prior to this PR, in order to reuse the code, we convert v1beta1 Sidecar object to v1beta1.Step and then construct containers out of those steps when the script field is specified.

pipeline/pkg/pod/script.go

Lines 116 to 119 in 09d422c

convertedStepContainers := convertListOfSteps(steps, &placeScriptsInit, &placeScripts, breakpoints, "script")
// Pass empty breakpoint list in "sidecar step to container" converter to not rewrite the scripts and add breakpoints to sidecar
sidecarContainers := convertListOfSteps(sideCarSteps, &placeScriptsInit, &placeScripts, []string{}, "sidecar-script")

As we are switching the storage version to v1, some fields are deprecated in v1.Step (but not Sidecar), thus it does not make sense to convert sidercar to step.

While reusing as much code as possible, this PR refactors the code to seperate the container construction process for steps and sidecars.

Partially fix #6575

/kind bug

Submitter Checklist

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

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. kind/bug Categorizes issue or PR as related to a bug. labels May 3, 2023
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 3, 2023
@XinruZhang
Copy link
Member Author

cc @dibyom @lbernick

@lbernick lbernick self-assigned this May 3, 2023
@XinruZhang XinruZhang force-pushed the 6575-01 branch 2 times, most recently from 5216a55 to 8256fcd Compare May 4, 2023 00:13
Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

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

thanks Xinru! Do we have test coverage for when both the step and sidecar have scripts, when both have debug breakpoints set, and sidecars with readiness probes/liveness probes or other fields that steps don't have?

pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Show resolved Hide resolved
@XinruZhang
Copy link
Member Author

Thank you for the review @lbernick, one thing I'd love to confirm is, do breakpoints apply to sidecars? Asking because I noticed perviously when building containers for sidecars, the breakpoint parameter is an empty string array 🤔

sidecarContainers := convertListOfSteps(sideCarSteps, &placeScriptsInit, &placeScripts, []string{}, "sidecar-script")

@lbernick
Copy link
Member

lbernick commented May 4, 2023

Thank you for the review @lbernick, one thing I'd love to confirm is, do breakpoints apply to sidecars? Asking because I noticed perviously when building containers for sidecars, the breakpoint parameter is an empty string array 🤔

sidecarContainers := convertListOfSteps(sideCarSteps, &placeScriptsInit, &placeScripts, []string{}, "sidecar-script")

good point, probably not! I don't see any mention of sidecars in https://github.com/tektoncd/community/blob/main/teps/0097-breakpoints-for-taskruns-and-pipelineruns.md or https://github.com/tektoncd/community/blob/main/teps/0042-taskrun-breakpoint-on-failure.md and it's probably not something that would be useful anyway.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 98.9% -1.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 98.9% -1.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 98.9% -1.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 98.9% -1.1

pkg/pod/script_test.go Outdated Show resolved Hide resolved
pkg/pod/script_test.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Outdated Show resolved Hide resolved
pkg/pod/script.go Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lbernick

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 4, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

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

I wonder if we could rearrange the functions in the order when they are called?
e.g. maybe we could move convertListOfSteps, convertListOfSidecars and hasScripts in order after the function convertScripts. This might improve the readability?

Prior to this commit, in order to reuse the code, we convert v1beta1
Sidecar object to v1beta1.Step and then construct containers out of
those steps when the script field is specified.

As we are switching the storage version to v1, some fields are
deprecated in v1.Step (but not Sidecar), thus it does not make sense
to convert sidercar to step.

While reusing as much code as possible, this commit refactor the code
to seperate the container construction process for steps and sidecars.
@XinruZhang
Copy link
Member Author

I wonder if we could rearrange the functions in the order when they are called? e.g. maybe we could move convertListOfSteps, convertListOfSidecars and hasScripts in order after the function convertScripts. This might improve the readability?

Thank you @Yongxuanzhang. Good idea! Updated.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/pod/script.go 100.0% 99.0% -1.0

@XinruZhang
Copy link
Member Author

Not sure why "Setup metallb" failed.

Copied from build-log.txt:

metallb-system               pod/controller-7696f658c8-cjgsp                          0/1     ImagePullBackOff   0             33m
metallb-system               pod/speaker-85tzb                                        0/1     ImagePullBackOff   0             33m
metallb-system               pod/speaker-9s9r5                                        0/1     ImagePullBackOff   0             33m
metallb-system               pod/speaker-ptbr4                                        0/1     ImagePullBackOff   0             33m

Since this seems unrelated to this change itself, retesting to see if it will pass.

/retest

@lbernick
Copy link
Member

lbernick commented May 5, 2023

@XinruZhang it looks like it's an issue with TestPipelineRunTasksTimeout; I created #6624

Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 5, 2023
Copy link
Member

@Yongxuanzhang Yongxuanzhang left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot merged commit 77c1698 into tektoncd:main May 5, 2023
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. release-note-none Denotes a PR that doesnt merit a release note. 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.

Handle Loss of Deprecated Container Fields in v1 for Step LivenessProbes and etc.
4 participants