Skip to content

Commit

Permalink
Added utils for labels duplicates (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethahealy authored Jun 25, 2020
1 parent 4272392 commit fd117b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 42 deletions.
21 changes: 21 additions & 0 deletions policy/utils/labels.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package utils.labels

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/name"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/instance"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/component"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/part-of"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/managed-by"]
}
24 changes: 3 additions & 21 deletions policy/warn-k8s_ocp-all-bestpractices.rego
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
package main

import data.utils.labels

warn[msg] {
isCommonK8sLabelNotSet with input as input.metadata
labels.isCommonK8sLabelNotSet with input as input.metadata

msg := sprintf("%s/%s: does not contain all the expected k8s labels in 'metadata.labels'. See: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels", [input.kind, input.metadata.name])
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/name"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/instance"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/component"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/part-of"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/managed-by"]
}
23 changes: 2 additions & 21 deletions policy/warn-k8s_ocp-deployment_deploymentconfig-bestpractices.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package main

import data.utils.labels
import data.utils.openshift

warn[msg] {
Expand Down Expand Up @@ -234,31 +235,11 @@ warn[msg] {
warn[msg] {
openshift.isDeploymentOrDeploymentConfig

isCommonK8sLabelNotSet with input as input.spec.template.metadata
labels.isCommonK8sLabelNotSet with input as input.spec.template.metadata

msg := sprintf("%s/%s: does not contain all the expected k8s labels in 'spec.template.metadata.labels'. See: https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels", [input.kind, input.metadata.name])
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/name"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/instance"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/component"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/part-of"]
}

isCommonK8sLabelNotSet {
not input.labels["app.kubernetes.io/managed-by"]
}

warn[msg] {
openshift.isDeploymentOrDeploymentConfig

Expand Down

0 comments on commit fd117b9

Please sign in to comment.