@@ -104,61 +104,153 @@ func TestReconcileArgoCD_Reconcile(t *testing.T) {
104
104
105
105
func TestReconcileArgoCD_LabelSelector (t * testing.T ) {
106
106
logf .SetLogger (ZapLogger (true ))
107
+ //ctx := context.Background()
107
108
a := makeTestArgoCD ()
108
- r := makeTestReconciler (t , a )
109
- assert .NoError (t , createNamespace (r , a .Namespace , "" ))
110
-
111
- // ArgoCD instance should be reconciled if no label-selctor is applied to the operator
112
- req := reconcile.Request {
109
+ a .Name = "argo-test-1"
110
+ b := makeTestArgoCD ()
111
+ b .Name = "argo-test-2"
112
+ c := makeTestArgoCD ()
113
+ c .Name = "argo-test-3"
114
+ rt1 := makeTestReconciler (t , a )
115
+ rt2 := makeTestReconciler (t , b )
116
+ rt3 := makeTestReconciler (t , c )
117
+ assert .NoError (t , createNamespace (rt1 , a .Namespace , "" ))
118
+ assert .NoError (t , createNamespace (rt2 , b .Namespace , "" ))
119
+ assert .NoError (t , createNamespace (rt3 , c .Namespace , "" ))
120
+
121
+ // All ArgoCD instance should be reconciled if no label-selctor is applied to the operator.
122
+ // No label selector provided and all argocd instances are reconciled
123
+
124
+ // Instance 'a'
125
+ req1 := reconcile.Request {
113
126
NamespacedName : types.NamespacedName {
114
127
Name : a .Name ,
115
128
Namespace : a .Namespace ,
116
129
},
117
130
}
118
- res , err := r .Reconcile (context .TODO (), req )
131
+ res1 , err := rt1 .Reconcile (context .TODO (), req1 )
119
132
assert .NoError (t , err )
120
- if res .Requeue {
133
+ if res1 .Requeue {
134
+ t .Fatal ("reconcile requeued request" )
135
+ }
136
+
137
+ //Instance 'b'
138
+ req2 := reconcile.Request {
139
+ NamespacedName : types.NamespacedName {
140
+ Name : b .Name ,
141
+ Namespace : b .Namespace ,
142
+ },
143
+ }
144
+ res2 , err := rt2 .Reconcile (context .TODO (), req2 )
145
+ assert .NoError (t , err )
146
+ if res2 .Requeue {
121
147
t .Fatal ("reconcile requeued request" )
122
148
}
123
149
124
- // Apply label-selector foo=bar to the operator but not to the argocd instance. No reconciliation will happen and an Error is expected.
125
- r .LabelSelector = "foo=bar"
126
- reqTest1 := reconcile.Request {
150
+ //Instance 'c'
151
+ req3 := reconcile.Request {
152
+ NamespacedName : types.NamespacedName {
153
+ Name : c .Name ,
154
+ Namespace : c .Namespace ,
155
+ },
156
+ }
157
+ res3 , err := rt3 .Reconcile (context .TODO (), req3 )
158
+ assert .NoError (t , err )
159
+ if res3 .Requeue {
160
+ t .Fatal ("reconcile requeued request" )
161
+ }
162
+
163
+ // Apply label-selector foo=bar to the operator but not to the argocd instances. No reconciliation will happen and an error is expected.
164
+ rt1 .LabelSelector = "foo=bar"
165
+ reqTest := reconcile.Request {
127
166
NamespacedName : types.NamespacedName {
128
167
Name : a .Name ,
129
168
Namespace : a .Namespace ,
130
169
},
131
170
}
132
- resTest1 , err := r .Reconcile (context .TODO (), reqTest1 )
171
+ resTest , err := rt1 .Reconcile (context .TODO (), reqTest )
133
172
assert .Error (t , err )
134
- if resTest1 .Requeue {
173
+ if resTest .Requeue {
174
+ t .Fatal ("reconcile requeued request" )
175
+ }
176
+
177
+ //not reconciled should return error
178
+ rt2 .LabelSelector = "foo=bar"
179
+ reqTest2 := reconcile.Request {
180
+ NamespacedName : types.NamespacedName {
181
+ Name : b .Name ,
182
+ Namespace : b .Namespace ,
183
+ },
184
+ }
185
+ resTest2 , err := rt2 .Reconcile (context .TODO (), reqTest2 )
186
+ assert .Error (t , err )
187
+ if resTest2 .Requeue {
188
+ t .Fatal ("reconcile requeued request" )
189
+ }
190
+
191
+ //not reconciled should return error
192
+ rt3 .LabelSelector = "foo=bar"
193
+ reqTest3 := reconcile.Request {
194
+ NamespacedName : types.NamespacedName {
195
+ Name : c .Name ,
196
+ Namespace : c .Namespace ,
197
+ },
198
+ }
199
+ resTest3 , err := rt3 .Reconcile (context .TODO (), reqTest3 )
200
+ assert .Error (t , err )
201
+ if resTest3 .Requeue {
135
202
t .Fatal ("reconcile requeued request" )
136
203
}
137
204
}
138
205
func TestReconcileArgoCD_ReconcileLabel (t * testing.T ) {
206
+
207
+ // Multiple ArgoCD instances present with matching label present on some and absent on some.
208
+ // Only instances matching the label are reconciled.
209
+
139
210
logf .SetLogger (ZapLogger (true ))
140
211
ctx := context .Background ()
141
212
a := makeTestArgoCD ()
142
- r := makeTestReconciler (t , a )
143
- assert .NoError (t , createNamespace (r , a .Namespace , "" ))
213
+ r1 := makeTestReconciler (t , a )
214
+ assert .NoError (t , createNamespace (r1 , a .Namespace , "" ))
215
+ b := makeTestArgoCD ()
216
+ r2 := makeTestReconciler (t , b )
217
+ assert .NoError (t , createNamespace (r2 , b .Namespace , "" ))
144
218
145
219
// Apply label foo=bar to the argocd instance and to the operator for reconciliation without any error.
146
- r .LabelSelector = "foo=bar"
220
+ r1 .LabelSelector = "foo=bar"
221
+ r2 .LabelSelector = "foo=bar"
222
+
223
+ //Apply label to Instance 'a' but not to Instance 'b'
147
224
a .SetLabels (map [string ]string {"foo" : "bar" })
148
- err := r .Client .Update (ctx , a )
225
+ err := r1 .Client .Update (ctx , a )
149
226
fatalIfError (t , err , "failed to update the ArgoCD: %s" , err )
150
227
reqTest2 := reconcile.Request {
151
228
NamespacedName : types.NamespacedName {
152
229
Name : a .Name ,
153
230
Namespace : a .Namespace ,
154
231
},
155
232
}
156
- resTest2 , err := r .Reconcile (context .TODO (), reqTest2 )
233
+ resTest2 , err := r1 .Reconcile (context .TODO (), reqTest2 )
234
+
235
+ //Instance 'a' reconciled without error
157
236
assert .NoError (t , err )
158
237
if resTest2 .Requeue {
159
238
t .Fatal ("reconcile requeued request" )
160
239
}
161
240
241
+ reqTest3 := reconcile.Request {
242
+ NamespacedName : types.NamespacedName {
243
+ Name : b .Name ,
244
+ Namespace : b .Namespace ,
245
+ },
246
+ }
247
+ resTest3 , err := r2 .Reconcile (context .TODO (), reqTest3 )
248
+ //Instance 'b' is not reconciled and an error is expeced
249
+ assert .Error (t , err )
250
+ if resTest3 .Requeue {
251
+ t .Fatal ("reconcile requeued request" )
252
+ }
253
+
162
254
}
163
255
164
256
func TestReconcileArgoCD_Reconcile_RemoveManagedByLabelOnArgocdDeletion (t * testing.T ) {
0 commit comments