1
2
3
4 package e2e
5
6 import (
7 "context"
8 "fmt"
9 "time"
10
11 . "github.com/onsi/ginkgo/v2"
12 . "github.com/onsi/gomega"
13 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14 "sigs.k8s.io/cli-utils/pkg/apply"
15 "sigs.k8s.io/cli-utils/pkg/apply/event"
16 "sigs.k8s.io/cli-utils/pkg/object"
17 "sigs.k8s.io/cli-utils/pkg/testutil"
18 "sigs.k8s.io/cli-utils/test/e2e/e2eutil"
19 "sigs.k8s.io/cli-utils/test/e2e/invconfig"
20 )
21
22 func reconciliationFailed(ctx context.Context, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
23 By("Apply resources")
24 applier := invConfig.ApplierFactoryFunc()
25 inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
26
27 inventoryInfo := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
28
29 podObj := e2eutil.WithNodeSelector(e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod1), namespaceName), "foo", "bar")
30 resources := []*unstructured.Unstructured{
31 podObj,
32 }
33
34 applierEvents := e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
35 ReconcileTimeout: 2 * time.Minute,
36 EmitStatusEvents: false,
37 }))
38
39 expEvents := expectedPodEvents(podObj, event.ReconcileFailed)
40 received := testutil.EventsToExpEvents(applierEvents)
41
42 Expect(received).To(testutil.Equal(expEvents))
43 }
44
45 func reconciliationTimeout(ctx context.Context, invConfig invconfig.InventoryConfig, inventoryName, namespaceName string) {
46 By("Apply resources")
47 applier := invConfig.ApplierFactoryFunc()
48 inventoryID := fmt.Sprintf("%s-%s", inventoryName, namespaceName)
49
50 inventoryInfo := invconfig.CreateInventoryInfo(invConfig, inventoryName, namespaceName, inventoryID)
51
52 podObj := e2eutil.PodWithImage(e2eutil.WithNamespace(e2eutil.ManifestToUnstructured(pod1), namespaceName), "kubernetes-pause", "does-not-exist")
53 resources := []*unstructured.Unstructured{
54 podObj,
55 }
56
57 applierEvents := e2eutil.RunCollect(applier.Run(ctx, inventoryInfo, resources, apply.ApplierOptions{
58 ReconcileTimeout: 30 * time.Second,
59 EmitStatusEvents: false,
60 }))
61
62 expEvents := expectedPodEvents(podObj, event.ReconcileTimeout)
63 receivedEvents := testutil.EventsToExpEvents(applierEvents)
64
65 expEvents, receivedEvents = e2eutil.FilterOptionalEvents(expEvents, receivedEvents)
66
67 Expect(receivedEvents).To(testutil.Equal(expEvents))
68 }
69
70 func expectedPodEvents(pod *unstructured.Unstructured, waitStatus event.WaitEventStatus) []testutil.ExpEvent {
71 return []testutil.ExpEvent{
72 {
73
74 EventType: event.InitType,
75 InitEvent: &testutil.ExpInitEvent{},
76 },
77 {
78
79 EventType: event.ActionGroupType,
80 ActionGroupEvent: &testutil.ExpActionGroupEvent{
81 Action: event.InventoryAction,
82 GroupName: "inventory-add-0",
83 Type: event.Started,
84 },
85 },
86 {
87
88 EventType: event.ActionGroupType,
89 ActionGroupEvent: &testutil.ExpActionGroupEvent{
90 Action: event.InventoryAction,
91 GroupName: "inventory-add-0",
92 Type: event.Finished,
93 },
94 },
95 {
96
97 EventType: event.ActionGroupType,
98 ActionGroupEvent: &testutil.ExpActionGroupEvent{
99 Action: event.ApplyAction,
100 GroupName: "apply-0",
101 Type: event.Started,
102 },
103 },
104 {
105
106 EventType: event.ApplyType,
107 ApplyEvent: &testutil.ExpApplyEvent{
108 GroupName: "apply-0",
109 Status: event.ApplySuccessful,
110 Identifier: object.UnstructuredToObjMetadata(pod),
111 Error: nil,
112 },
113 },
114 {
115
116 EventType: event.ActionGroupType,
117 ActionGroupEvent: &testutil.ExpActionGroupEvent{
118 Action: event.ApplyAction,
119 GroupName: "apply-0",
120 Type: event.Finished,
121 },
122 },
123 {
124
125 EventType: event.ActionGroupType,
126 ActionGroupEvent: &testutil.ExpActionGroupEvent{
127 Action: event.WaitAction,
128 GroupName: "wait-0",
129 Type: event.Started,
130 },
131 },
132 {
133
134 EventType: event.WaitType,
135 WaitEvent: &testutil.ExpWaitEvent{
136 GroupName: "wait-0",
137 Status: event.ReconcilePending,
138 Identifier: object.UnstructuredToObjMetadata(pod),
139 },
140 },
141 {
142
143 EventType: event.WaitType,
144 WaitEvent: &testutil.ExpWaitEvent{
145 GroupName: "wait-0",
146 Status: waitStatus,
147 Identifier: object.UnstructuredToObjMetadata(pod),
148 },
149 },
150 {
151
152 EventType: event.ActionGroupType,
153 ActionGroupEvent: &testutil.ExpActionGroupEvent{
154 Action: event.WaitAction,
155 GroupName: "wait-0",
156 Type: event.Finished,
157 },
158 },
159 {
160
161 EventType: event.ActionGroupType,
162 ActionGroupEvent: &testutil.ExpActionGroupEvent{
163 Action: event.InventoryAction,
164 GroupName: "inventory-set-0",
165 Type: event.Started,
166 },
167 },
168 {
169
170 EventType: event.ActionGroupType,
171 ActionGroupEvent: &testutil.ExpActionGroupEvent{
172 Action: event.InventoryAction,
173 GroupName: "inventory-set-0",
174 Type: event.Finished,
175 },
176 },
177 }
178 }
179
View as plain text