Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Validate Kubernetes objects using kubeval #25

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config_defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
feature_componentCompile: true
feature_goUnitTests: false
feature_goldenTests: false
feature_kubevalValidate: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
feature_kubevalValidate: false
feature_kubevalLint: false

componentName: ""

.github/ISSUE_TEMPLATE/config.yml:
Expand Down
21 changes: 21 additions & 0 deletions moduleroot/.github/workflows/test.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,24 @@ jobs:
- name: Golden diff
run: make golden-diff
<%- end -%>
<%- if @configs['feature_kubevalValidate'] -%>
validate:
runs-on: ubuntu-latest
<%- if !@configs['matrix'].empty? -%>
strategy:
matrix:
<%= @configs['matrix']['key'] -%>:
<% @configs['matrix']['entries'].each do |entry| -%>
- <%= entry %>
<% end -%>
<%- end -%>
defaults:
run:
working-directory: ${{ env.COMPONENT_NAME }}
steps:
- uses: actions/checkout@v2
with:
path: ${{ env.COMPONENT_NAME }}
- name: Validate Kubernetes objects
run: make validate
<%- end -%>
9 changes: 9 additions & 0 deletions moduleroot/Makefile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ golden-diff: commodore_args = -f tests/$(instance).yml --search-paths ./dependen
golden-diff: .compile ## Diff compile output against the reference version. Review output and run `make gen-golden golden-diff` if this target fails.
@git diff --exit-code --minimal --no-index -- tests/golden/$(instance) compiled/
<%- end -%>
<%- 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 -%>
Comment on lines +79 to +87
Copy link
Contributor

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.

Suggested change
<%- 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 -%>


.PHONY: clean
clean: ## Clean the project
Expand Down
6 changes: 6 additions & 0 deletions moduleroot/Makefile.vars.mk.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ YAMLLINT_ARGS ?= --no-warnings
YAMLLINT_CONFIG ?= .yamllint.yml
YAMLLINT_IMAGE ?= docker.io/cytopia/yamllint:latest
YAMLLINT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) $(YAMLLINT_IMAGE)
<%- if @configs['feature_kubevalValidate'] -%>

KUBEVAL_ARGS ?= --ignore-missing-schemas
KUBEVAL_IMAGE ?= docker.io/cytopia/kubeval:latest
KUBEVAL_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) $(KUBEVAL_IMAGE)
<%- end -%>

VALE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --volume "$${PWD}"/docs/modules:/pages vshn/vale:2.1.1
VALE_ARGS ?= --minAlertLevel=error --config=/pages/ROOT/pages/.vale.ini /pages
Expand Down