Skip to content

Commit 7178634

Browse files
committed
We must create ns and operatorgroup only when the the gitopssubnamespace is not openshift-operators
1 parent 9235058 commit 7178634

2 files changed

Lines changed: 45 additions & 26 deletions

File tree

templates/policies/ocp-gitops-policy.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ spec:
2626
include:
2727
- default
2828
object-templates:
29-
{{- if $.Values.global.gitOpsSubNamespace }}
30-
- complianceType: mustonlyhave
31-
objectDefinition:
32-
apiVersion: v1
33-
kind: Namespace
34-
metadata:
35-
name: {{ $.Values.global.gitOpsSubNamespace }}
36-
- complianceType: mustonlyhave
37-
objectDefinition:
38-
apiVersion: operators.coreos.com/v1
39-
kind: OperatorGroup
40-
metadata:
41-
name: {{ $.Values.global.gitOpsSubNamespace }}-operator-group
42-
namespace: {{ $.Values.global.gitOpsSubNamespace }}
43-
spec:
44-
{{- end }}
4529
- complianceType: mustonlyhave
4630
objectDefinition:
4731
# This is an auto-generated file. DO NOT EDIT
@@ -69,6 +53,22 @@ spec:
6953
namespace: openshift-gitops
7054
labels:
7155
config.openshift.io/inject-trusted-cabundle: 'true'
56+
{{- if ne $.Values.global.gitOpsSubNamespace "openshift-operators" }}
57+
- complianceType: mustonlyhave
58+
objectDefinition:
59+
apiVersion: v1
60+
kind: Namespace
61+
metadata:
62+
name: {{ $.Values.global.gitOpsSubNamespace }}
63+
- complianceType: mustonlyhave
64+
objectDefinition:
65+
apiVersion: operators.coreos.com/v1
66+
kind: OperatorGroup
67+
metadata:
68+
name: {{ $.Values.global.gitOpsSubNamespace }}-operator-group
69+
namespace: {{ $.Values.global.gitOpsSubNamespace }}
70+
spec:
71+
{{- end }}
7272
---
7373
apiVersion: policy.open-cluster-management.io/v1
7474
kind: PlacementBinding

tests/gitops_sub_namespace_test.yaml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ tests:
6262
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.namespace
6363
pattern: ^openshift-operators$
6464

65-
- it: should create namespace object-template when gitOpsSubNamespace is set
65+
- it: should create namespace object-template when gitOpsSubNamespace is set to something other than openshift-operators
6666
set:
6767
global:
68-
gitOpsSubNamespace: my-gitops-ns
68+
gitOpsSubNamespace: yolo
6969
clusterGroup:
7070
managedClusterGroups:
7171
region-one:
@@ -78,16 +78,16 @@ tests:
7878
path: metadata.name
7979
value: region-one-gitops-policy
8080
equal:
81-
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.kind
81+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[2].objectDefinition.kind
8282
value: Namespace
8383
- documentSelector:
8484
path: metadata.name
8585
value: region-one-gitops-policy
8686
equal:
87-
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.name
88-
value: my-gitops-ns
87+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[2].objectDefinition.metadata.name
88+
value: yolo
8989

90-
- it: should create operatorgroup object-template when gitOpsSubNamespace is set
90+
- it: should create operatorgroup object-template when gitOpsSubNamespace is set to something other than openshift-operators
9191
set:
9292
global:
9393
gitOpsSubNamespace: my-gitops-ns
@@ -103,21 +103,40 @@ tests:
103103
path: metadata.name
104104
value: region-one-gitops-policy
105105
equal:
106-
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.kind
106+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[3].objectDefinition.kind
107107
value: OperatorGroup
108108
- documentSelector:
109109
path: metadata.name
110110
value: region-one-gitops-policy
111111
equal:
112-
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.metadata.name
112+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[3].objectDefinition.metadata.name
113113
value: my-gitops-ns-operator-group
114114
- documentSelector:
115115
path: metadata.name
116116
value: region-one-gitops-policy
117117
equal:
118-
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.metadata.namespace
118+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[3].objectDefinition.metadata.namespace
119119
value: my-gitops-ns
120120

121+
- it: should not create operatorgroup nor namespace object-template when gitOpsSubNamespace is set to openshift-operators
122+
set:
123+
global:
124+
gitOpsSubNamespace: openshift-operators
125+
clusterGroup:
126+
managedClusterGroups:
127+
region-one:
128+
name: region-one
129+
acmlabels:
130+
- name: clusterGroup
131+
value: region-one
132+
asserts:
133+
- documentSelector:
134+
path: metadata.name
135+
value: region-one-gitops-policy
136+
lengthEqual:
137+
path: spec.policy-templates[0].objectDefinition.spec.object-templates
138+
count: 2 # Just subscription and configmap
139+
121140
- it: should use gitOpsSubNamespace as subscription namespace when set
122141
set:
123142
global:
@@ -134,5 +153,5 @@ tests:
134153
path: metadata.name
135154
value: region-one-gitops-policy
136155
matchRegex:
137-
path: spec.policy-templates[0].objectDefinition.spec.object-templates[2].objectDefinition.metadata.namespace
156+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[3].objectDefinition.metadata.namespace
138157
pattern: ^my-gitops-ns$

0 commit comments

Comments
 (0)