@@ -146,6 +146,14 @@ func Test_CreateEvents(t *testing.T) {
146
146
ObjectMeta : v1.ObjectMeta {
147
147
Name : "test" ,
148
148
Namespace : "argocd" ,
149
+ OwnerReferences : []v1.OwnerReference {
150
+ {
151
+ APIVersion : "argoproj.io/v1alpha1" ,
152
+ Kind : "ApplicationSet" ,
153
+ Name : "test" ,
154
+ UID : "test" ,
155
+ },
156
+ },
149
157
},
150
158
Spec : v1alpha1.ApplicationSpec {
151
159
Project : "test" ,
@@ -183,6 +191,8 @@ func Test_CreateEvents(t *testing.T) {
183
191
assert .NoError (t , err )
184
192
require .NotNil (t , napp )
185
193
assert .Equal (t , "HEAD" , napp .Spec .Source .TargetRevision )
194
+ // OwnerReferences should be dropped on the control-plane application
195
+ assert .Empty (t , napp .OwnerReferences )
186
196
// Check that the destination is set to the cluster mapping
187
197
assert .Equal (t , "foo" , napp .Spec .Destination .Name )
188
198
assert .Equal (t , "" , napp .Spec .Destination .Server )
@@ -200,6 +210,14 @@ func Test_CreateEvents(t *testing.T) {
200
210
ObjectMeta : v1.ObjectMeta {
201
211
Name : "test" ,
202
212
Namespace : "argocd" ,
213
+ OwnerReferences : []v1.OwnerReference {
214
+ {
215
+ APIVersion : "argoproj.io/v1alpha1" ,
216
+ Kind : "ApplicationSet" ,
217
+ Name : "test" ,
218
+ UID : "test" ,
219
+ },
220
+ },
203
221
},
204
222
Spec : v1alpha1.ApplicationSpec {
205
223
Source : & v1alpha1.ApplicationSource {
@@ -219,6 +237,7 @@ func Test_CreateEvents(t *testing.T) {
219
237
}
220
238
exapp := app .DeepCopy ()
221
239
exapp .Namespace = "foo"
240
+ exapp .OwnerReferences = nil
222
241
fac := kube .NewKubernetesFakeClientWithApps (exapp )
223
242
ev := cloudevents .NewEvent ()
224
243
ev .SetDataSchema ("application" )
@@ -237,6 +256,7 @@ func Test_CreateEvents(t *testing.T) {
237
256
napp , err := fac .ApplicationsClientset .ArgoprojV1alpha1 ().Applications ("foo" ).Get (context .TODO (), "test" , v1.GetOptions {})
238
257
assert .NoError (t , err )
239
258
require .NotNil (t , napp )
259
+ assert .Empty (t , napp .OwnerReferences )
240
260
// Check that the destination is set to the cluster mapping
241
261
assert .Equal (t , "foo" , napp .Spec .Destination .Name )
242
262
assert .Equal (t , "" , napp .Spec .Destination .Server )
@@ -250,6 +270,14 @@ func Test_UpdateEvents(t *testing.T) {
250
270
ObjectMeta : v1.ObjectMeta {
251
271
Name : "test" ,
252
272
Namespace : "argocd" ,
273
+ OwnerReferences : []v1.OwnerReference {
274
+ {
275
+ APIVersion : "argoproj.io/v1alpha1" ,
276
+ Kind : "ApplicationSet" ,
277
+ Name : "test" ,
278
+ UID : "test" ,
279
+ },
280
+ },
253
281
},
254
282
Spec : v1alpha1.ApplicationSpec {
255
283
Project : "default" ,
@@ -308,6 +336,8 @@ func Test_UpdateEvents(t *testing.T) {
308
336
assert .NoError (t , err )
309
337
require .NotNil (t , napp )
310
338
assert .Equal (t , "HEAD" , napp .Spec .Source .TargetRevision )
339
+ // OwnerReferences should be dropped on spec update in autonomous mode
340
+ assert .Empty (t , napp .OwnerReferences )
311
341
// Check that the destination is set to the cluster mapping
312
342
assert .Equal (t , "foo" , napp .Spec .Destination .Name )
313
343
assert .Equal (t , "" , napp .Spec .Destination .Server )
@@ -504,6 +534,14 @@ func Test_processAppProjectEvent(t *testing.T) {
504
534
ObjectMeta : v1.ObjectMeta {
505
535
Name : "test" ,
506
536
Namespace : "argocd" ,
537
+ OwnerReferences : []v1.OwnerReference {
538
+ {
539
+ APIVersion : "argoproj.io/v1alpha1" ,
540
+ Kind : "ApplicationSet" ,
541
+ Name : "owner" ,
542
+ UID : "uid-1" ,
543
+ },
544
+ },
507
545
},
508
546
Spec : v1alpha1.AppProjectSpec {
509
547
SourceRepos : []string {"foo" },
@@ -544,6 +582,8 @@ func Test_processAppProjectEvent(t *testing.T) {
544
582
createdProject , err := fac .ApplicationsClientset .ArgoprojV1alpha1 ().AppProjects ("argocd" ).Get (context .TODO (), projName , v1.GetOptions {})
545
583
assert .NoError (t , err )
546
584
assert .Equal (t , projName , createdProject .Name )
585
+ // OwnerReferences should be dropped on the control-plane appProject
586
+ assert .Empty (t , createdProject .OwnerReferences )
547
587
548
588
// Check that SourceNamespaces is set to the agent name
549
589
assert .Equal (t , []string {"foo" }, createdProject .Spec .SourceNamespaces )
@@ -579,6 +619,8 @@ func Test_processAppProjectEvent(t *testing.T) {
579
619
ev .SetType (event .SpecUpdate .String ())
580
620
581
621
updatedProject := project .DeepCopy ()
622
+ // include owner refs in update payload and ensure they are dropped
623
+ updatedProject .OwnerReferences = []v1.OwnerReference {{APIVersion : "argoproj.io/v1alpha1" , Kind : "ApplicationSet" , Name : "owner2" , UID : "uid-2" }}
582
624
updatedProject .Spec .Description = "updated"
583
625
updatedProject .Name = "test" // Use original name (will be prefixed)
584
626
ev .SetData (cloudevents .ApplicationJSON , updatedProject )
@@ -601,6 +643,8 @@ func Test_processAppProjectEvent(t *testing.T) {
601
643
got , err := fac .ApplicationsClientset .ArgoprojV1alpha1 ().AppProjects ("argocd" ).Get (context .TODO (), projName , v1.GetOptions {})
602
644
assert .NoError (t , err )
603
645
assert .Equal (t , updatedProject .Spec .Description , got .Spec .Description )
646
+ // OwnerReferences should be dropped on update as well
647
+ assert .Empty (t , got .OwnerReferences )
604
648
605
649
// Check that SourceNamespaces is set to the agent name
606
650
assert .Equal (t , []string {"foo" }, got .Spec .SourceNamespaces )
0 commit comments