Skip to content

feat: add tkn validate to check resources without a cluster - #3431

Open
cvas22 wants to merge 5 commits into
tektoncd:mainfrom
cvas22:feat/2588-validate-command
Open

cvas22 wants to merge 5 commits into
tektoncd:mainfrom
cvas22:feat/2588-validate-command

Conversation

@cvas22

@cvas22 cvas22 commented Nov 16, 2026

Copy link
Copy Markdown

Changes

Adds tkn validate, which checks Tekton resources in files without needing a cluster or credentials (#2588).

tkn validate -f task.yaml -f pipeline.yaml
cat pipeline.yaml | tkn validate -f -

Each object gets its defaults applied and goes through the same validation the Tekton webhook runs on create. All files are checked and every problem is reported, prefixed with the file name, e.g. invalid.yaml: Task nosteps is invalid: expected exactly one, got neither: spec.steps. It exits non-zero when anything is invalid, so it drops straight into CI.

Fixes #2588

/kind feature

Notes

This builds on #3430 (tkn bundle push --dry-run) and reuses its bundle.ValidateTektonObjects, so the first commit here is that PR. Only the last commit is new, and I'll rebase once #3430 lands. Resolving remote refs (bundles, git, hub) isn't covered yet. That needs network access and felt like a follow-up, happy to add it if you'd like it here.

Docs and man pages are written to match the generator output, tests are in pkg/cmd/validate. I haven't run them locally, CI will be the first run.

I used some help from AI, please don't yell at me. Thx.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

Release Notes

New tkn validate command checks Tekton resources in YAML or JSON files locally, without a cluster.

@tekton-robot tekton-robot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Nov 16, 2026
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign divyansh42 after the PR has been reviewed.
You can assign the PR to them by writing /assign @divyansh42 in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details 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 size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 16, 2026
@divyansh42
divyansh42 requested a balanced review from Copilot November 22, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Offline validation still rejects generated-name manifests, silently accepts unknown fields, stops at the first decoding error, and returns the wrong exit code for invalid input.

4 open issues
What changed in this PR

Adds tkn validate for checking resource manifests without a cluster or credentials, addressing #2588. It reuses the shared validation introduced by the bundled tkn bundle push --dry-run work from #3430.

Changes:

  • Adds file and stdin validation using Tekton defaulting and create-time validators.
  • Adds bundle dry-run validation and clearer, document-numbered parsing errors.
  • Adds tests, command documentation, man pages, and help-output updates.
File Description
README.md Lists the new validation command.
pkg/​cmd/​validate/​validate.go Implements file and stdin validation.
pkg/​cmd/​validate/​validate_test.go Tests command inputs, results, and error reporting.
pkg/​cmd/​testdata/​TestPluginList.golden Adds validation to expected command help.
pkg/​cmd/​root.go Registers the validation command.
pkg/​cmd/​bundle/​push.go Adds validation without registry publication.
pkg/​cmd/​bundle/​push_test.go Tests dry-run validation and digest output.
pkg/​bundle/​validate.go Adds shared object defaulting and validation.
pkg/​bundle/​validate_test.go Tests validation and parsing diagnostics.
pkg/​bundle/​parser.go Numbers failing documents and limits error snippets.
docs/​man/​man1/​tkn.1 Links the validation man page.
docs/​man/​man1/​tkn-validate.1 Documents validation usage and options.
docs/​man/​man1/​tkn-bundle-push.1 Documents the dry-run flag.
docs/​cmd/​tkn.md Links the validation command reference.
docs/​cmd/​tkn_validate.md Adds validation examples and options.
docs/​cmd/​tkn_bundle_push.md Adds the dry-run flag reference.

Review effort: Balanced

Comment thread pkg/bundle/parser.go Outdated
obj, gvr, err := tektonDecoder.Decode(spec.Raw, nil, nil)
if err != nil {
return fmt.Errorf("failed to parse string as a Tekton object: %q", specInJSON)
return fmt.Errorf("failed to parse string as a Tekton object (document %d): %w: %q", doc, err, truncate(specInJSON))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, validation now has its own decode loop that records a bad document and moves on, so an unsupported kind no longer hides a later broken Task. Bundle building is still fail-fast. Fixed in b4f85d3, and f683343 also trims the missing kind/apiVersion errors.

Comment thread pkg/bundle/validate.go Outdated
ctx = apis.WithinCreate(ctx)
var errs []error
for _, content := range contents {
if err := decodeObjects(content, func(gvk *schema.GroupVersionKind, obj runtime.Object, _ []byte) error {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yep, validation now decodes strictly from the raw YAML/JSON, so workngDir and duplicate keys get reported. Push parsing is unchanged. Fixed in b4f85d3.

Comment thread pkg/bundle/validate.go Outdated
Comment on lines +35 to +38
name, err := getObjectName(obj)
if err != nil {
errs = append(errs, fmt.Errorf("%s: %w", gvk.Kind, err))
return nil

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, validation now gives a generateName-only manifest a placeholder name before checking the spec. Bundle building still needs an explicit name. Fixed in b4f85d3, I did not run it against the real release-pipeline-run.yml, only a similar generateName PipelineRun in a test.

continue
}
if err := bundle.ValidateTektonObjects(ctx, []string{contents}); err != nil {
errs = append(errs, fmt.Errorf("%s: %w", displayName(path), err))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 1aadadb. Invalid manifests now exit with InvalidInput, and a file that can't be read keeps the general code. The test checks the code for each case.

There was no way to check a bundle without pushing it, so CI for catalogs
had to push to a registry, or point at a bad one and tell the errors apart.

--dry-run builds the bundle as usual, then applies defaults and runs the
Tekton validation on every object, reports all problems at once, and prints
the digest without pushing.

Parse errors also got clearer: they name the failing document and include
the decoder error, and only quote the first 200 characters of the object
instead of the whole input.

Fixes tektoncd#1666

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
tkn had no way to check Tekton YAML without a cluster or credentials.
Add 'tkn validate -f FILE', which decodes every Tekton object in the
files (or stdin with -f -), applies defaults and runs the same validation
the Tekton webhook runs on create. Every file is checked and all problems
are reported together, prefixed with the file name.

It reuses bundle.ValidateTektonObjects from the bundle push --dry-run change.

Fixes tektoncd#2588

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
@cvas22
cvas22 force-pushed the feat/2588-validate-command branch from 1dc373f to 4d96590 Compare November 22, 2026 17:58
…build on dry-run

Missing kind/apiVersion errors embedded the whole manifest, and a build
failure in one file hid validation problems in the others.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
…cept generateName

Validation now reports unknown fields and duplicate keys, continues past
a document that cannot be decoded, and treats a manifest with only
metadata.generateName as named. Bundle building is unchanged.

Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
Signed-off-by: Srinivas Chippagiri <cvas22@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tkn verify/validate subcommand

3 participants