Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🟡 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
| 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)) |
There was a problem hiding this comment.
| ctx = apis.WithinCreate(ctx) | ||
| var errs []error | ||
| for _, content := range contents { | ||
| if err := decodeObjects(content, func(gvk *schema.GroupVersionKind, obj runtime.Object, _ []byte) error { |
There was a problem hiding this comment.
Yep, validation now decodes strictly from the raw YAML/JSON, so workngDir and duplicate keys get reported. Push parsing is unchanged. Fixed in b4f85d3.
| name, err := getObjectName(obj) | ||
| if err != nil { | ||
| errs = append(errs, fmt.Errorf("%s: %w", gvk.Kind, err)) | ||
| return nil |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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>
1dc373f to
4d96590
Compare
…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>

Changes
Adds
tkn validate, which checks Tekton resources in files without needing a cluster or credentials (#2588).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 itsbundle.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:
make checkmake generatedSee the contribution guide
for more details.
Release Notes