Skip to content

Refactor Step validation to implement apis.Validatable. #8717

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

Conversation

twoGiants
Copy link
Member

@twoGiants twoGiants commented Apr 18, 2025

Changes

As a follow up to #8685 in this small PR the Step validation is refactored to align with the pattern used in pipeline_validation.go, task_validation.go, result_validation.go, etc. meaning implementing the apis.Validatable interface and using a custom type for a list of Step namely StepList.

Now that the Step validation has a public Validate API, the tests can be moved from task_validation_test.go to container_validation_test.go.

Issue #8700.

/kind cleanup

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
  • pre-commit Passed
  • 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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 18, 2025
@tekton-robot tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 18, 2025
@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/apis/pipeline/v1/task_validation.go 98.6% 97.8% -0.8

@tekton-robot tekton-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2025
@waveywaves
Copy link
Member

@twoGiants: PR needs rebase :p

@twoGiants
Copy link
Member Author

@twoGiants: PR needs rebase :p

Yes sir! Is in the works and will open a couple more soon 😸

Add `StepList` with a `Validate` method and implement a `Validate`
method on `Step`.

Move up check for duplicated Step names into `StepList.Validate` to be
consistent with the check for duplicated Task names in
`pipeline_validation.go`.

Issue tektoncd#8700.

Signed-off-by: Stanislav Jakuschevskij <[email protected]>
@twoGiants twoGiants force-pushed the issue-8700-refactor-step-validation-to-implement-validatable branch from 70c4547 to b88b80f Compare May 14, 2025 12:45
@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 14, 2025
@twoGiants twoGiants changed the title 🚧 Refactor Step validation to implement apis.Validatable. 🚧 Refactor Step validation to implement apis.Validatable. May 14, 2025
@twoGiants twoGiants marked this pull request as ready for review May 14, 2025 12:46
@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 May 14, 2025
@tekton-robot tekton-robot requested a review from jerop May 14, 2025 12:46
@twoGiants
Copy link
Member Author

/kind cleanup

You can take a look, it's ready @waveywaves. Thank you 😸

Next will be PRs with batches of moved and renamed tests.

@tekton-robot tekton-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label May 14, 2025
errs = errs.Also(errorIfStepResultReferencedInField(s.Name, "name"))
errs = errs.Also(errorIfStepResultReferencedInField(s.Image, "image"))
errs = errs.Also(errorIfStepResultReferencedInField(s.Script, "script"))
errs = errs.Also(errorIfStepResultReferencedInField(string(s.ImagePullPolicy), "imagePullPoliicy"))
errs = errs.Also(errorIfStepResultReferencedInField(string(s.ImagePullPolicy), "imagePullPolicy"))
Copy link
Member

Choose a reason for hiding this comment

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

you're finding a lot of typos hahaha

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a code spell checker installed 😁 😎

@@ -87,7 +87,7 @@ func (ts *TaskSpec) Validate(ctx context.Context) (errs *apis.FieldError) {
})
}

errs = errs.Also(validateSteps(ctx, mergedSteps).ViaField("steps"))
errs = errs.Also(StepList(mergedSteps).Validate(ctx).ViaField("steps"))
Copy link
Member

Choose a reason for hiding this comment

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

why does it feel like I have already reviewed this 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably because its similar to the sidecar Validatable refactoring in #8710. It's basically the same but for the Step :).

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is a better link to the same line.

Copy link
Member

Choose a reason for hiding this comment

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

ah yess, thank you for sharing

@@ -104,7 +103,8 @@ func RefNameLikeUrl(name string) error {
return nil
}

func validateStep(ctx context.Context, s Step, names sets.String) (errs *apis.FieldError) {
// Validate implements apis.Validatable
func (s *Step) Validate(ctx context.Context) (errs *apis.FieldError) {
Copy link
Member

Choose a reason for hiding this comment

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 14, 2025
@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/apis/pipeline/v1/task_validation.go 99.1% 99.1% 0.0

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.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label May 20, 2025
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester, waveywaves

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 merged commit 1027f72 into tektoncd:main May 20, 2025
20 checks passed
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
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants