Skip to content

Commit 89be53d

Browse files
authored
Merge pull request #571 from karlkfi/karl-cross-namespace-deps
chore: add test for cross namespace depends-on
2 parents 42d34da + aeff41d commit 89be53d

File tree

2 files changed

+236
-21
lines changed

2 files changed

+236
-21
lines changed

test/e2e/depends_on_test.go

Lines changed: 228 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,28 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
2626

2727
inv := invConfig.InvWrapperFunc(invConfig.FactoryFunc(inventoryName, namespaceName, "test"))
2828

29-
pod1Obj := e2eutil.WithDependsOn(e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod1), namespaceName), fmt.Sprintf("/namespaces/%s/Pod/pod3", namespaceName))
30-
pod2Obj := e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod2), namespaceName)
31-
pod3Obj := e2eutil.WithDependsOn(e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod3), namespaceName), fmt.Sprintf("/namespaces/%s/Pod/pod2", namespaceName))
29+
namespace1Name := fmt.Sprintf("%s-ns1", namespaceName)
30+
namespace1Obj := e2eutil.UnstructuredNamespace(namespace1Name)
31+
32+
namespace2Name := fmt.Sprintf("%s-ns2", namespaceName)
33+
namespace2Obj := e2eutil.UnstructuredNamespace(namespace2Name)
34+
35+
pod1Obj := e2eutil.ManifestToUnstructured(pod1)
36+
pod1Obj = e2eutil.WithNamespace(pod1Obj, namespace1Name)
37+
pod1Obj = e2eutil.WithDependsOn(pod1Obj, fmt.Sprintf("/namespaces/%s/Pod/pod3", namespace1Name))
38+
39+
pod2Obj := e2eutil.ManifestToUnstructured(pod2)
40+
pod2Obj = e2eutil.WithNamespace(pod2Obj, namespace2Name)
41+
42+
pod3Obj := e2eutil.ManifestToUnstructured(pod3)
43+
pod3Obj = e2eutil.WithNamespace(pod3Obj, namespace1Name)
44+
pod3Obj = e2eutil.WithDependsOn(pod3Obj, fmt.Sprintf("/namespaces/%s/Pod/pod2", namespace2Name))
3245

3346
// Dependency order: pod1 -> pod3 -> pod2
3447
// Apply order: pod2, pod3, pod1
3548
resources := []*unstructured.Unstructured{
49+
namespace1Obj,
50+
namespace2Obj,
3651
pod1Obj,
3752
pod2Obj,
3853
pod3Obj,
@@ -76,13 +91,21 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
7691
},
7792
},
7893
{
79-
// Apply Pod2 first
94+
// Apply Namespace1 first
8095
EventType: event.ApplyType,
8196
ApplyEvent: &testutil.ExpApplyEvent{
8297
GroupName: "apply-0",
8398
Operation: event.Created,
84-
Identifier: object.UnstructuredToObjMetadata(pod2Obj),
85-
Error: nil,
99+
Identifier: object.UnstructuredToObjMetadata(namespace1Obj),
100+
},
101+
},
102+
{
103+
// Apply Namespace2 first
104+
EventType: event.ApplyType,
105+
ApplyEvent: &testutil.ExpApplyEvent{
106+
GroupName: "apply-0",
107+
Operation: event.Created,
108+
Identifier: object.UnstructuredToObjMetadata(namespace2Obj),
86109
},
87110
},
88111
{
@@ -104,21 +127,39 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
104127
},
105128
},
106129
{
107-
// Pod2 reconcile Pending.
130+
// Namespace1 reconcile Pending.
108131
EventType: event.WaitType,
109132
WaitEvent: &testutil.ExpWaitEvent{
110133
GroupName: "wait-0",
111134
Operation: event.ReconcilePending,
112-
Identifier: object.UnstructuredToObjMetadata(pod2Obj),
135+
Identifier: object.UnstructuredToObjMetadata(namespace1Obj),
113136
},
114137
},
115138
{
116-
// Pod2 confirmed Current.
139+
// Namespace2 reconcile Pending.
140+
EventType: event.WaitType,
141+
WaitEvent: &testutil.ExpWaitEvent{
142+
GroupName: "wait-0",
143+
Operation: event.ReconcilePending,
144+
Identifier: object.UnstructuredToObjMetadata(namespace2Obj),
145+
},
146+
},
147+
{
148+
// Namespace1 confirmed Current.
117149
EventType: event.WaitType,
118150
WaitEvent: &testutil.ExpWaitEvent{
119151
GroupName: "wait-0",
120152
Operation: event.Reconciled,
121-
Identifier: object.UnstructuredToObjMetadata(pod2Obj),
153+
Identifier: object.UnstructuredToObjMetadata(namespace1Obj),
154+
},
155+
},
156+
{
157+
// Namespace2 confirmed Current.
158+
EventType: event.WaitType,
159+
WaitEvent: &testutil.ExpWaitEvent{
160+
GroupName: "wait-0",
161+
Operation: event.Reconciled,
162+
Identifier: object.UnstructuredToObjMetadata(namespace2Obj),
122163
},
123164
},
124165
{
@@ -140,12 +181,12 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
140181
},
141182
},
142183
{
143-
// Apply Pod3 second
184+
// Apply Pod2 first
144185
EventType: event.ApplyType,
145186
ApplyEvent: &testutil.ExpApplyEvent{
146187
GroupName: "apply-1",
147188
Operation: event.Created,
148-
Identifier: object.UnstructuredToObjMetadata(pod3Obj),
189+
Identifier: object.UnstructuredToObjMetadata(pod2Obj),
149190
Error: nil,
150191
},
151192
},
@@ -168,21 +209,21 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
168209
},
169210
},
170211
{
171-
// Pod3 reconcile Pending.
212+
// Pod2 reconcile Pending.
172213
EventType: event.WaitType,
173214
WaitEvent: &testutil.ExpWaitEvent{
174215
GroupName: "wait-1",
175216
Operation: event.ReconcilePending,
176-
Identifier: object.UnstructuredToObjMetadata(pod3Obj),
217+
Identifier: object.UnstructuredToObjMetadata(pod2Obj),
177218
},
178219
},
179220
{
180-
// Pod3 confirmed Current.
221+
// Pod2 confirmed Current.
181222
EventType: event.WaitType,
182223
WaitEvent: &testutil.ExpWaitEvent{
183224
GroupName: "wait-1",
184225
Operation: event.Reconciled,
185-
Identifier: object.UnstructuredToObjMetadata(pod3Obj),
226+
Identifier: object.UnstructuredToObjMetadata(pod2Obj),
186227
},
187228
},
188229
{
@@ -204,12 +245,12 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
204245
},
205246
},
206247
{
207-
// Apply Pod1 third
248+
// Apply Pod3 second
208249
EventType: event.ApplyType,
209250
ApplyEvent: &testutil.ExpApplyEvent{
210251
GroupName: "apply-2",
211252
Operation: event.Created,
212-
Identifier: object.UnstructuredToObjMetadata(pod1Obj),
253+
Identifier: object.UnstructuredToObjMetadata(pod3Obj),
213254
Error: nil,
214255
},
215256
},
@@ -232,19 +273,83 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
232273
},
233274
},
234275
{
235-
// Pod1 reconcile Pending.
276+
// Pod3 reconcile Pending.
236277
EventType: event.WaitType,
237278
WaitEvent: &testutil.ExpWaitEvent{
238279
GroupName: "wait-2",
239280
Operation: event.ReconcilePending,
281+
Identifier: object.UnstructuredToObjMetadata(pod3Obj),
282+
},
283+
},
284+
{
285+
// Pod3 confirmed Current.
286+
EventType: event.WaitType,
287+
WaitEvent: &testutil.ExpWaitEvent{
288+
GroupName: "wait-2",
289+
Operation: event.Reconciled,
290+
Identifier: object.UnstructuredToObjMetadata(pod3Obj),
291+
},
292+
},
293+
{
294+
// WaitTask finished
295+
EventType: event.ActionGroupType,
296+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
297+
Action: event.WaitAction,
298+
GroupName: "wait-2",
299+
Type: event.Finished,
300+
},
301+
},
302+
{
303+
// ApplyTask start
304+
EventType: event.ActionGroupType,
305+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
306+
Action: event.ApplyAction,
307+
GroupName: "apply-3",
308+
Type: event.Started,
309+
},
310+
},
311+
{
312+
// Apply Pod1 third
313+
EventType: event.ApplyType,
314+
ApplyEvent: &testutil.ExpApplyEvent{
315+
GroupName: "apply-3",
316+
Operation: event.Created,
317+
Identifier: object.UnstructuredToObjMetadata(pod1Obj),
318+
Error: nil,
319+
},
320+
},
321+
{
322+
// ApplyTask finished
323+
EventType: event.ActionGroupType,
324+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
325+
Action: event.ApplyAction,
326+
GroupName: "apply-3",
327+
Type: event.Finished,
328+
},
329+
},
330+
{
331+
// WaitTask start
332+
EventType: event.ActionGroupType,
333+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
334+
Action: event.WaitAction,
335+
GroupName: "wait-3",
336+
Type: event.Started,
337+
},
338+
},
339+
{
340+
// Pod1 reconcile Pending.
341+
EventType: event.WaitType,
342+
WaitEvent: &testutil.ExpWaitEvent{
343+
GroupName: "wait-3",
344+
Operation: event.ReconcilePending,
240345
Identifier: object.UnstructuredToObjMetadata(pod1Obj),
241346
},
242347
},
243348
{
244349
// Pod1 confirmed Current.
245350
EventType: event.WaitType,
246351
WaitEvent: &testutil.ExpWaitEvent{
247-
GroupName: "wait-2",
352+
GroupName: "wait-3",
248353
Operation: event.Reconciled,
249354
Identifier: object.UnstructuredToObjMetadata(pod1Obj),
250355
},
@@ -254,7 +359,7 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
254359
EventType: event.ActionGroupType,
255360
ActionGroupEvent: &testutil.ExpActionGroupEvent{
256361
Action: event.WaitAction,
257-
GroupName: "wait-2",
362+
GroupName: "wait-3",
258363
Type: event.Finished,
259364
},
260365
},
@@ -279,6 +384,12 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
279384
}
280385
Expect(testutil.EventsToExpEvents(applierEvents)).To(testutil.Equal(expEvents))
281386

387+
By("verify namespace1 created")
388+
e2eutil.AssertUnstructuredExists(ctx, c, namespace1Obj)
389+
390+
By("verify namespace2 created")
391+
e2eutil.AssertUnstructuredExists(ctx, c, namespace2Obj)
392+
282393
By("verify pod1 created and ready")
283394
result := e2eutil.AssertUnstructuredExists(ctx, c, pod1Obj)
284395
podIP, found, err := object.NestedField(result.Object, "status", "podIP")
@@ -503,6 +614,96 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
503614
Type: event.Finished,
504615
},
505616
},
617+
{
618+
// PruneTask start
619+
EventType: event.ActionGroupType,
620+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
621+
Action: event.DeleteAction,
622+
GroupName: "prune-3",
623+
Type: event.Started,
624+
},
625+
},
626+
{
627+
// Delete Namespace2 last
628+
EventType: event.DeleteType,
629+
DeleteEvent: &testutil.ExpDeleteEvent{
630+
GroupName: "prune-3",
631+
Operation: event.Deleted,
632+
Identifier: object.UnstructuredToObjMetadata(namespace2Obj),
633+
},
634+
},
635+
{
636+
// Delete Namespace1 last
637+
EventType: event.DeleteType,
638+
DeleteEvent: &testutil.ExpDeleteEvent{
639+
GroupName: "prune-3",
640+
Operation: event.Deleted,
641+
Identifier: object.UnstructuredToObjMetadata(namespace1Obj),
642+
},
643+
},
644+
{
645+
// PruneTask finished
646+
EventType: event.ActionGroupType,
647+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
648+
Action: event.DeleteAction,
649+
GroupName: "prune-3",
650+
Type: event.Finished,
651+
},
652+
},
653+
{
654+
// WaitTask start
655+
EventType: event.ActionGroupType,
656+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
657+
Action: event.WaitAction,
658+
GroupName: "wait-3",
659+
Type: event.Started,
660+
},
661+
},
662+
{
663+
// Namespace2 reconcile Pending.
664+
EventType: event.WaitType,
665+
WaitEvent: &testutil.ExpWaitEvent{
666+
GroupName: "wait-3",
667+
Operation: event.ReconcilePending,
668+
Identifier: object.UnstructuredToObjMetadata(namespace2Obj),
669+
},
670+
},
671+
{
672+
// Namespace1 reconcile Pending.
673+
EventType: event.WaitType,
674+
WaitEvent: &testutil.ExpWaitEvent{
675+
GroupName: "wait-3",
676+
Operation: event.ReconcilePending,
677+
Identifier: object.UnstructuredToObjMetadata(namespace1Obj),
678+
},
679+
},
680+
{
681+
// Namespace1 confirmed NotFound.
682+
EventType: event.WaitType,
683+
WaitEvent: &testutil.ExpWaitEvent{
684+
GroupName: "wait-3",
685+
Operation: event.Reconciled,
686+
Identifier: object.UnstructuredToObjMetadata(namespace1Obj),
687+
},
688+
},
689+
{
690+
// Namespace2 confirmed NotFound.
691+
EventType: event.WaitType,
692+
WaitEvent: &testutil.ExpWaitEvent{
693+
GroupName: "wait-3",
694+
Operation: event.Reconciled,
695+
Identifier: object.UnstructuredToObjMetadata(namespace2Obj),
696+
},
697+
},
698+
{
699+
// WaitTask finished
700+
EventType: event.ActionGroupType,
701+
ActionGroupEvent: &testutil.ExpActionGroupEvent{
702+
Action: event.WaitAction,
703+
GroupName: "wait-3",
704+
Type: event.Finished,
705+
},
706+
},
506707
{
507708
// DeleteInvTask start
508709
EventType: event.ActionGroupType,
@@ -532,4 +733,10 @@ func dependsOnTest(ctx context.Context, c client.Client, invConfig invconfig.Inv
532733

533734
By("verify pod3 deleted")
534735
e2eutil.AssertUnstructuredDoesNotExist(ctx, c, pod3Obj)
736+
737+
By("verify namespace1 deleted")
738+
e2eutil.AssertUnstructuredDoesNotExist(ctx, c, namespace1Obj)
739+
740+
By("verify namespace2 deleted")
741+
e2eutil.AssertUnstructuredDoesNotExist(ctx, c, namespace2Obj)
535742
}

test/e2e/e2eutil/common.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,11 @@ func UnstructuredIsTerminating(obj *unstructured.Unstructured) bool {
402402
}
403403
return false
404404
}
405+
406+
func UnstructuredNamespace(name string) *unstructured.Unstructured {
407+
u := &unstructured.Unstructured{}
408+
u.SetAPIVersion("v1")
409+
u.SetKind("Namespace")
410+
u.SetName(name)
411+
return u
412+
}

0 commit comments

Comments
 (0)