-
Notifications
You must be signed in to change notification settings - Fork 0
Validate Kubernetes objects using kubeval
#25
Conversation
In https://syn.tools/syn/SDDs/0026-commodore-component-testing.html we have documented why we didn't use Kubeval back then. Is that document obsolete? For what reasons? |
I was not aware of this document. I saw we're using |
I would argue the SDD and
IMO We have many (too many?) components and not enough manpower to thoroughly unit test them all. Even for the tests we have, they are more or less "structure" tests where using |
The problem I have with Kubeval is that it gives easily a false sense of security. For example, it doesn't tell whether you should write In the end, a green check in GH says little to nothing whether my artifacts are valid as expected. And for linting purposes we have Yamllint already? So I'd rather have no test than a bad one, at least I'd know it's not tested. If a component absolutely needs Kubeval they are free to do so, as you've read in the SDD. But I have my doubts rolling that out for every component. |
I did enable
ACK. This PR won't solve CRDs.
A green checkmark never says a software is ok as in valid or bug free. This PR does not aim at formal verification of a component. It does however improve testing slightly where a component is only compiled as a test.
Yamllint does not lint the compiled output. Commodore does have different ideas how compiled yaml should look than our yamllint config.
I still prefer to allow people to enable it with one line in |
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.
A green checkmark never says a software is ok as in valid or bug free. This PR does not aim at formal verification of a component.
Agreed, but then I woudn't call it validate
either. It'll be just linting in that case. For me, "validation" verifies semantic, whereas linting only verifies syntax. A generic Kubeval check would then only be linting as it has no idea if the spec is semantically correct.
copying many lines of Go code.
This is only the current case where we don't have a helper library/repository yet. It was an experiment started in one component, but not rolled out to every component. So maybe we should actually do it now?
I'm still not a fan of rolling out Kubeval as I see no value, but if the majority of contributors think it's useful, I won't stand in the way.
Please also update the SDD page if this gets merged.
<%- if @configs['feature_kubevalValidate'] -%> | ||
|
||
.PHONY: validate | ||
validate: commodore_args = -f tests/$(instance).yml --search-paths ./dependencies | ||
validate: .compile ## Validate the resulting Kubernetes objects using kubeval. | ||
@echo | ||
@echo | ||
$(KUBEVAL_DOCKER) $(KUBEVAL_ARGS) -d compiled/ | ||
<%- end -%> |
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.
resulting from the discussion, I would not call it validate
since that's not a formal validation but rather just K8s-specific linting, thus name it lint_kubeval
or so.
<%- if @configs['feature_kubevalValidate'] -%> | |
.PHONY: validate | |
validate: commodore_args = -f tests/$(instance).yml --search-paths ./dependencies | |
validate: .compile ## Validate the resulting Kubernetes objects using kubeval. | |
@echo | |
@echo | |
$(KUBEVAL_DOCKER) $(KUBEVAL_ARGS) -d compiled/ | |
<%- end -%> | |
<%- if @configs['feature_kubevalLint'] -%> | |
.PHONY: lint_kubeval | |
lint_kubeval: commodore_args = -f tests/$(instance).yml --search-paths ./dependencies | |
lint_kubeval: .compile ## Lint the resulting Kubernetes objects using kubeval (ignores CRDs!) | |
@echo | |
@echo | |
$(KUBEVAL_DOCKER) $(KUBEVAL_ARGS) -d compiled/ | |
<%- end -%> |
@@ -2,6 +2,7 @@ | |||
feature_componentCompile: true | |||
feature_goUnitTests: false | |||
feature_goldenTests: false | |||
feature_kubevalValidate: false |
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.
feature_kubevalValidate: false | |
feature_kubevalLint: false |
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.
Settle on wheter to use "validate" or "lint" (I am fine with both. Then ensure you use the chosen term consistently.
Closing this since we're migrating away from modulesync, I created an issue to track this suggestion on the component template repo: projectsyn/commodore-component-template#11 |
This PR adds a
validate
target for both theMakefile
and the Github test action. The action is used to validate the compiled Kubernetes config.We already use
kubeval
in some components, this PR aims at creating a standardised way to use it:https://github.com/projectsyn/component-lieutenant/blob/efa4020cf71a761de81a601da781ae0af459c396/tests/unit/defaults_test.go#L72
See projectsyn/component-kyverno#16 for a sample of the changes.
Checklist
bug
,enhancement
,documentation
,change
,breaking
,dependency
as they show up in the changelog