-
Couldn't load subscription status.
- Fork 258
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
base: main
Are you sure you want to change the base?
Conversation
This commit introduces a new kubeconform template that validates Kubernetes resources against their schemas using the kubeconform library. Features: - Validates Kubernetes resources against official schemas - Supports custom schema locations and Kubernetes versions - Configurable strict mode for catching extra properties - Can ignore missing schemas for CRDs - Skip/reject specific resource kinds - Schema caching support Changes: - Added kubeconform template with comprehensive parameter support - Fixed godoc comments following Go conventions - Added unit tests for template functionality - Added e2e tests with sample valid and invalid resources - Integrated template into kube-linter's template registry - Updated documentation with template parameters 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
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. |
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
Signed-off-by: Tomasz Janiszewski <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a new file ? I find the name misleading (hints at pod where a different kind is specified).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a new file ?
| func validate(p params.Params) (check.Func, error) { | ||
| // Create cache directory if it doesn't exist | ||
| if p.Cache != "" { | ||
| if err := os.MkdirAll(p.Cache, 0755); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the gosec error (drop directory permissions for other)
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-resourceas it could be replaced by a newschema-validationcheck orkubeconformThis could be considered as breaking change as it changes the semantic of
--fail-on-invalid-resourceto 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]