Skip to content

Commit

Permalink
Add tests for data validation
Browse files Browse the repository at this point in the history
Add policices written in [rego](https://www.openpolicyagent.org/docs/latest/policy-language/)
that validate kubernetes resources configuration of the community
infrastructure. Only the ingresses resources are covered.
THis is heavily inspired from https://github.com/deliveryhero/helm-charts/tree/master/ci/helm-conftest-policies.
[conftest](https://github.com/open-policy-agent/conftest) will be
against those policies.

Ref: kubernetes#1734

Signed-off-by: Arnaud Meukam <[email protected]>
  • Loading branch information
ameukam committed Mar 4, 2021
1 parent 71591c3 commit fb8becc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions policies/base.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import data.kubernetes

apiversion = input.apiversion

warn[msg] {
kubernetes.is_ingress
msg = sprintf("Found ingress %s", [apiversion])
}
21 changes: 21 additions & 0 deletions policies/deprecations.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

warn[msg] {
input.apiVersion == "v1"
input.kind == "List"
obj := input.items[_]
msg := _warn with input as obj
}

warn[msg] {
input.apiVersion != "v1"
input.kind != "List"
msg := _warn
}

# Ingress resources extensions/v1beta1 will no longer be served from in v1.20. Migrate use to the networking.k8s.io/v1beta1 API, available since v1.14.
_warn = msg {
input.apiVersion == "extensions/v1beta1"
input.kind == "Ingress"
msg := sprintf("%s/%s: API extensions/v1beta1 for Ingress is deprecated from Kubernetes 1.14, use networking.k8s.io/v1beta1 instead.", [input.kind, input.metadata.name])
}
14 changes: 14 additions & 0 deletions policies/kubernetes.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

package kubernetes

is_service {
input.kind = "Service"
}

is_deployment {
input.kind = "Deployment"
}

is_ingress {
input.kind = "Ingress"
}

0 comments on commit fb8becc

Please sign in to comment.