-
Notifications
You must be signed in to change notification settings - Fork 256
Add fallback decoder for unknown resources to handle CRDs #1037
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
Open
janisz
wants to merge
5
commits into
kubeconform
Choose a base branch
from
allow_custom_resources
base: kubeconform
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tested by rebasing #1033 on this PR and running test from e2e but with flag # ./kube-linter lint tests/checks/kubeconform.yml --fail-on-invalid-resource --do-not-auto-add-defaults --config e2etests/testdata/kubeconform-config.yaml
KubeLinter development
./tests/checks/kubeconform.yml: (object: default/invalid-daemonset apps/v1, Kind=DaemonSet) resource is not valid: problem validating schema. Check JSON formatting: jsonschema validation failed with 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone-strict/daemonset-apps-v1.json#' - at '/spec': additional properties 'replicas' not allowed (check: kubeconform-validation, remediation: Fix the resource to conform to the Kubernetes API schema)
./tests/checks/kubeconform.yml: (object: default/invalid-pod /v1, Kind=Pod) resource is not valid: problem validating schema. Check JSON formatting: jsonschema validation failed with 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone-strict/pod-v1.json#' - at '/spec': additional properties 'invalidField' not allowed (check: kubeconform-validation, remediation: Fix the resource to conform to the Kubernetes API schema)
- ./tests/checks/kubeconform.yml: (object: <no namespace>/ /, Kind=) failed to decode: no kind "CustomResource" is registered for version "example.com/v1" in scheme "pkg/runtime/scheme.go:110" (check: failed-to-load-object, remediation: Confirm that the file is accessible and is valid k8s yaml.)
- Error: found 3 lint errors
+ Error: found 2 lint errors |
This PR adds a fallback when decoding unknown resources to be able to handle CRDs. The schema validation could be then performed with kubeconform check from #1033 and CEL from #1012. This should fix #606 Changes: - Modified parseObjects to use unstructured decoder as fallback for unknown resource types - Added comprehensive test suite covering standard K8s resources and CRDs - Maintained backward compatibility for existing decode error handling - Added test cases for Tekton Task CRD and other custom resources The fallback allows kube-linter to parse CRDs like Tekton Pipelines without failing, while delegating proper schema validation to specialized templates like kubeconform and CEL expressions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
1154b9e
to
2eb9460
Compare
This change is part of the following stack: Change managed by git-spice. |
This was referenced Oct 9, 2025
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a fallback when decoding unknown resources to be able to handle CRDs. The schema validation could be then performed with kubeconform check from #1033 and CEL from #1012. This should fix #606
It also deprecates the
--fail-on-invalid-resource
as it could be replaced by a newschema-validation
check orkubeconform
This could be considered as breaking change as it changes the semantic of
--fail-on-invalid-resource
to fail on invalid yamls instead of failing on unknown objects or not matching schema but this could be mitigated by kubeconform.Changes:
The fallback allows kube-linter to parse CRDs like Tekton Pipelines without
failing, while delegating proper schema validation to specialized templates
like kubeconform and CEL expressions.
Fixes:
Refs:
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]