Skip to content

Commit

Permalink
Add tests for non-Policy resolution
Browse files Browse the repository at this point in the history
New tests for ConfigurationPolicy (including using the hub namespace
argument) and object-templates-raw.

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
  • Loading branch information
JustinKuli authored and openshift-merge-bot[bot] committed Sep 11, 2024
1 parent 382967b commit d5600b8
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: Namespace
metadata:
name: policies
spec: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: coolest-car
namespace: policies
data:
model: Subaru Baja
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: label-configmaps
spec:
remediationAction: enforce
severity: low
object-templates:
- complianceType: musthave
objectDefinition:
kind: ConfigMap
apiVersion: v1
metadata:
name: '{{ (lookup "v1" "ConfigMap" "default" "cool-car").metadata.name }}'
namespace: '{{ (lookup "v1" "ConfigMap" "default" "cool-car").metadata.namespace }}'
labels:
ford.com/model: '{{ fromConfigMap "default" "cool-car" "model" }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: label-configmaps
spec:
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
labels:
ford.com/model: Shelby Mustang
name: cool-car
namespace: default
remediationAction: enforce
severity: low
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: label-configmaps
namespace: my-cluster
spec:
remediationAction: enforce
severity: low
object-templates:
- complianceType: musthave
objectDefinition:
kind: ConfigMap
apiVersion: v1
metadata:
name: coolest-car
namespace: default
labels:
cars.com/model: '{{hub fromConfigMap "policies" "coolest-car" "model" hub}}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: label-configmaps
namespace: my-cluster
spec:
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
labels:
cars.com/model: Subaru Baja
name: coolest-car
namespace: default
remediationAction: enforce
severity: low
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object-templates-raw: |
{{- range (lookup "v1" "ConfigMap" "default" "").items }}
{{- if and .data.model (contains "Mustang" .data.model) }}
- complianceType: musthave
objectDefinition:
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ .metadata.name }}
namespace: {{ .metadata.namespace }}
labels:
ford.com/model: Mustang
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: v1
kind: ConfigMap
metadata:
labels:
ford.com/model: Mustang
name: cool-car
namespace: default

0 comments on commit d5600b8

Please sign in to comment.