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

TEP-0090 Matrix: Refactor Matrix FanOut() to use the Matrix Struct #6246

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

EmmaMunley
Copy link
Contributor

[TEP-0090: Matrix] introduced Matrix to the PipelineTask specification such that the PipelineTask executes a list of TaskRuns or Runs in parallel with the specified list of inputs for a Parameter or with different combinations of the inputs for a set of Parameters.

This PR refactors the FanOut() function to use the Matrix struct instead of the old []Params.

/kind cleanup

Submitter Checklist

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

  • Has Docs included if any changes are user facing
  • 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)
  • 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 kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 28, 2023
pkg/matrix/matrix_test.go Outdated Show resolved Hide resolved
@jerop jerop added this to the Pipelines v0.46 milestone Feb 28, 2023
@EmmaMunley EmmaMunley requested review from lbernick and removed request for abayer February 28, 2023 21:41
@@ -18,9 +18,9 @@ import (
)

// FanOut produces combinations of Parameters of type String from a slice of Parameters of type Array.
func FanOut(params []v1beta1.Param) Combinations {
func FanOut(matrix v1beta1.Matrix) Combinations {
Copy link
Member

Choose a reason for hiding this comment

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

Can we please declare this function as a member function:

func (m Matrix) FanOut() Combinations {
	var combinations Combinations
	for _, parameter := range m.Params {
		combinations = combinations.fanOut(parameter)
	}
	return combinations
}

just like:

func (combinations Combinations) fanOut(param v1beta1.Param) Combinations {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/hold for now until we clarify how this works since the existing logic has matrix.FanOut()

matrixCombinations := matrix.FanOut(rpt.PipelineTask.Matrix.Params).ToMap()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chatted with Priti and decided for now we will leave as is. The way that Matrix pkg is right now does not make it is easy to simply refactor FanOut() as a member function.
/hold cancel
/assign @pritidesai

Copy link
Member

Choose a reason for hiding this comment

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

@EmmaMunley is it because of import cycle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. We would have to move FanOut() to where the type Matrix is defined in Pipeline_types.go, however Combinations is defined within Matrix and it doesn't make sense to have Combinations defined in the API.

Copy link
Member

Choose a reason for hiding this comment

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

thanks @EmmaMunley!

Yup, it results in cyclic imports 🙃 and bringing combinations in pkg/apis/ might not be desirable based on recent discussions of avoiding copy/paste in multiple APIs.

@jerop I am happy to merge this for now but wanted to understand this package github.com/tektoncd/pipeline/pkg/matrix. Also, the package name matrix being same as the type Matrix caused confusion in https://github.com/tektoncd/pipeline/blob/main/pkg/reconciler/pipelinerun/pipelinerun.go#L837

matrix.FanOut(rpt.PipelineTask.Matrix.Params).ToMap()

Copy link
Member

Choose a reason for hiding this comment

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

Matrix type is defined in pkg/apis/pipeline/v1beta1/ with a couple of member functions. Matrix type has two fields: Params []Param and Include []MatrixInclude

https://github.com/tektoncd/pipeline/blob/main/pkg/apis/pipeline/v1beta1/pipeline_types.go#L165

func (matrix *Matrix) MatrixHasInclude() bool {

func (matrix *Matrix) MatrixHasParams() bool {

There is a matrix package with matrix.go and matrix_types.go with a combinations defined. Combination type has two fields: MatrixID string and Params []v1beta1.Param.

Can we replace combination type with matrix struct and add MatrixID to matrix struct? This way we do not have maintain a separate struct and a package.

Copy link
Member

Choose a reason for hiding this comment

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

@pritidesai thanks for the suggestions, refactored the implementation - #6282

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 1, 2023
[TEP-0090: Matrix] introduced `Matrix` to the `PipelineTask` specification such that the `PipelineTask` executes a list of `TaskRuns` or `Runs` in parallel with the specified list of inputs for a `Parameter` or with different combinations of the inputs for a set of `Parameters`.

This PR refactors the FanOut() function to use the Matrix struct instead of the old []Params.
@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 1, 2023
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pritidesai

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 Mar 2, 2023
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.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 2, 2023
@tekton-robot tekton-robot merged commit 01462c8 into tektoncd:main Mar 2, 2023
@pritidesai
Copy link
Member

thank you @lbernick for merging this PR, was hoping to hear back from @jerop on the comments ⬆️ so that they are not lost (spent quite a bit of typing last night 🤣). Have opened an issue for it to facilitate further discussion. Thanks!

@lbernick
Copy link
Member

lbernick commented Mar 2, 2023

Sorry Priti, I didn't realize you had unresolved comments! Thanks for opening an issue to track.

@EmmaMunley EmmaMunley deleted the update-fan-out-prelim branch March 3, 2023 15:25
@QuanZhang-William
Copy link
Member

I'm curious about what is the motivation for this change? 🤔

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/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants