Skip to content

Commit 5e3ee03

Browse files
committed
DONOTMERGE: additional debugging
Signed-off-by: timflannagan <[email protected]>
1 parent 9be8f50 commit 5e3ee03

File tree

2 files changed

+156
-136
lines changed

2 files changed

+156
-136
lines changed

pkg/controller/operators/adoption_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ func (r *AdoptionReconciler) adopt(ctx context.Context, operator *decorators.Ope
281281
}
282282
candidate := cObj.DeepCopyObject()
283283

284+
r.log.Info("adopt - attempting to adopt component", "gvk", cObj.GetObjectKind(), "name", cObj.GetName(), "namespace", cObj.GetNamespace())
285+
284286
adopted, err := operator.AdoptComponent(candidate)
285287
if err != nil {
286288
return err
@@ -292,6 +294,8 @@ func (r *AdoptionReconciler) adopt(ctx context.Context, operator *decorators.Ope
292294
if !ok {
293295
return fmt.Errorf("Unable to typecast runtime.Object to client.Object")
294296
}
297+
r.log.Info("adopt - successfully adopted component (pre-patch)", "gvk", cObj.GetObjectKind(), "name", cObj.GetName(), "namespace", cObj.GetNamespace())
298+
295299
return r.Patch(ctx, pCObj, client.MergeFrom(cObj))
296300
}
297301

test/e2e/operator_test.go

Lines changed: 152 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -76,172 +76,180 @@ var _ = Describe("Operator API", func() {
7676
// 14. Ensure the reference to ns-a is eventually removed from o's status.components.refs field
7777
// 15. Delete o
7878
// 16. Ensure o is not re-created
79-
It("should surface components in its status", func() {
80-
o := &operatorsv1.Operator{}
81-
o.SetName(genName("o-"))
82-
83-
Eventually(func() error {
84-
return client.Create(clientCtx, o)
85-
}).Should(Succeed())
86-
87-
Consistently(o).ShouldNot(ContainCopiedCSVReferences())
79+
Context("when an Operator resource can select its components by label", func() {
80+
var (
81+
o *operatorsv1.Operator
82+
)
83+
BeforeEach(func() {
84+
o = &operatorsv1.Operator{}
85+
o.SetName(genName("o-"))
8886

89-
defer func() {
9087
Eventually(func() error {
91-
err := client.Delete(clientCtx, o)
92-
if apierrors.IsNotFound(err) {
93-
return nil
94-
}
95-
96-
return err
88+
return client.Create(clientCtx, o)
9789
}).Should(Succeed())
98-
}()
90+
})
91+
AfterEach(func() {
92+
By("Checking whether the test case had failed")
93+
if CurrentGinkgoTestDescription().Failed {
94+
ctx.Ctx().DescribeResource(fmt.Sprintf("kubectl get operators %s -o yaml", o.GetName()))
95+
ctx.Ctx().DescribeResource(fmt.Sprintf("kubectl -n %s logs -l app=olm-operator --tail=50 --prefix --timestamps", *olmNamespace))
96+
}
97+
Eventually(func() error {
98+
return controllerclient.IgnoreNotFound(client.Delete(clientCtx, o))
99+
}).Should(Succeed())
100+
})
99101

100-
By("eventually having a status that contains its component label selector")
101-
w, err := operatorClient.Watch(clientCtx, listOpts)
102-
Expect(err).ToNot(HaveOccurred())
103-
defer w.Stop()
102+
It("should not contain copied csv status references", func() {
103+
Consistently(o).ShouldNot(ContainCopiedCSVReferences())
104+
})
104105

105-
deadline, cancel := context.WithTimeout(clientCtx, 1*time.Minute)
106-
defer cancel()
106+
It("should surface referenced components in its status", func() {
107+
By("eventually having a status that contains its component label selector")
108+
w, err := operatorClient.Watch(clientCtx, listOpts)
109+
Expect(err).To(BeNil())
110+
defer w.Stop()
107111

108-
expectedKey := "operators.coreos.com/" + o.GetName()
109-
awaitPredicates(deadline, w, operatorPredicate(func(op *operatorsv1.Operator) bool {
110-
if op.Status.Components == nil || op.Status.Components.LabelSelector == nil {
111-
return false
112-
}
112+
deadline, cancel := context.WithTimeout(clientCtx, 1*time.Minute)
113+
defer cancel()
113114

114-
for _, requirement := range op.Status.Components.LabelSelector.MatchExpressions {
115-
if requirement.Key == expectedKey && requirement.Operator == metav1.LabelSelectorOpExists {
116-
return true
115+
expectedKey := "operators.coreos.com/" + o.GetName()
116+
awaitPredicates(deadline, w, operatorPredicate(func(op *operatorsv1.Operator) bool {
117+
if op.Status.Components == nil || op.Status.Components.LabelSelector == nil {
118+
return false
117119
}
118-
}
119120

120-
return false
121-
}))
122-
defer w.Stop()
121+
for _, requirement := range op.Status.Components.LabelSelector.MatchExpressions {
122+
if requirement.Key == expectedKey && requirement.Operator == metav1.LabelSelectorOpExists {
123+
return true
124+
}
125+
}
123126

124-
// Create namespaces ns-a and ns-b
125-
nsA := &corev1.Namespace{}
126-
nsA.SetName(genName("ns-a-"))
127-
nsB := &corev1.Namespace{}
128-
nsB.SetName(genName("ns-b-"))
127+
return false
128+
}))
129+
defer w.Stop()
129130

130-
for _, ns := range []*corev1.Namespace{nsA, nsB} {
131-
Eventually(func() error {
132-
return client.Create(clientCtx, ns)
133-
}).Should(Succeed())
131+
// Create namespaces ns-a and ns-b
132+
nsA := &corev1.Namespace{}
133+
nsA.SetName(genName("ns-a-"))
134+
nsB := &corev1.Namespace{}
135+
nsB.SetName(genName("ns-b-"))
134136

135-
defer func(n *corev1.Namespace) {
137+
for _, ns := range []*corev1.Namespace{nsA, nsB} {
136138
Eventually(func() error {
137-
err := client.Delete(clientCtx, n)
138-
if apierrors.IsNotFound(err) {
139-
return nil
140-
}
141-
return err
139+
return client.Create(clientCtx, ns)
142140
}).Should(Succeed())
143-
}(ns)
144-
}
145141

146-
// Label ns-a with o's component label
147-
setComponentLabel := func(m metav1.Object) error {
148-
m.SetLabels(map[string]string{expectedKey: ""})
149-
return nil
150-
}
151-
Eventually(Apply(nsA, setComponentLabel)).Should(Succeed())
142+
defer func(n *corev1.Namespace) {
143+
Eventually(func() error {
144+
err := client.Delete(clientCtx, n)
145+
if apierrors.IsNotFound(err) {
146+
return nil
147+
}
148+
return err
149+
}).Should(Succeed())
150+
}(ns)
151+
}
152152

153-
// Ensure o's status.components.refs field eventually contains a reference to ns-a
154-
By("eventually listing a single component reference")
155-
componentRefEventuallyExists(w, true, getReference(scheme, nsA))
153+
// Label ns-a with o's component label
154+
setComponentLabel := func(m metav1.Object) error {
155+
m.SetLabels(map[string]string{expectedKey: ""})
156+
return nil
157+
}
158+
Eventually(Apply(nsA, setComponentLabel)).Should(Succeed())
156159

157-
// Create ServiceAccounts sa-a and sa-b in namespaces ns-a and ns-b respectively
158-
saA := &corev1.ServiceAccount{}
159-
saA.SetName(genName("sa-a-"))
160-
saA.SetNamespace(nsA.GetName())
161-
saB := &corev1.ServiceAccount{}
162-
saB.SetName(genName("sa-b-"))
163-
saB.SetNamespace(nsB.GetName())
160+
// Ensure o's status.components.refs field eventually contains a reference to ns-a
161+
By("eventually listing a single component reference")
162+
componentRefEventuallyExists(w, true, getReference(scheme, nsA))
164163

165-
for _, sa := range []*corev1.ServiceAccount{saA, saB} {
166-
Eventually(func() error {
167-
return client.Create(clientCtx, sa)
168-
}).Should(Succeed())
169-
defer func(sa *corev1.ServiceAccount) {
164+
// Create ServiceAccounts sa-a and sa-b in namespaces ns-a and ns-b respectively
165+
saA := &corev1.ServiceAccount{}
166+
saA.SetName(genName("sa-a-"))
167+
saA.SetNamespace(nsA.GetName())
168+
saB := &corev1.ServiceAccount{}
169+
saB.SetName(genName("sa-b-"))
170+
saB.SetNamespace(nsB.GetName())
171+
172+
for _, sa := range []*corev1.ServiceAccount{saA, saB} {
170173
Eventually(func() error {
171-
err := client.Delete(clientCtx, sa)
172-
if apierrors.IsNotFound(err) {
173-
return nil
174-
}
175-
return err
174+
return client.Create(clientCtx, sa)
176175
}).Should(Succeed())
177-
}(sa)
178-
}
176+
defer func(sa *corev1.ServiceAccount) {
177+
Eventually(func() error {
178+
err := client.Delete(clientCtx, sa)
179+
if apierrors.IsNotFound(err) {
180+
return nil
181+
}
182+
return err
183+
}).Should(Succeed())
184+
}(sa)
185+
}
179186

180-
// Label sa-a and sa-b with o's component label
181-
Eventually(Apply(saA, setComponentLabel)).Should(Succeed())
182-
Eventually(Apply(saB, setComponentLabel)).Should(Succeed())
187+
// Label sa-a and sa-b with o's component label
188+
Eventually(Apply(saA, setComponentLabel)).Should(Succeed())
189+
Eventually(Apply(saB, setComponentLabel)).Should(Succeed())
183190

184-
// Ensure o's status.components.refs field eventually contains references to sa-a and sa-b
185-
By("eventually listing multiple component references")
186-
componentRefEventuallyExists(w, true, getReference(scheme, saA))
187-
componentRefEventuallyExists(w, true, getReference(scheme, saB))
191+
// Ensure o's status.components.refs field eventually contains references to sa-a and sa-b
192+
By("eventually listing multiple component references")
193+
componentRefEventuallyExists(w, true, getReference(scheme, saA))
194+
componentRefEventuallyExists(w, true, getReference(scheme, saB))
188195

189-
// Remove the component label from sa-b
190-
Eventually(Apply(saB, func(m metav1.Object) error {
191-
m.SetLabels(nil)
192-
return nil
193-
})).Should(Succeed())
196+
// Remove the component label from sa-b
197+
Eventually(Apply(saB, func(m metav1.Object) error {
198+
m.SetLabels(nil)
199+
return nil
200+
})).Should(Succeed())
194201

195-
// Ensure the reference to sa-b is eventually removed from o's status.components.refs field
196-
By("removing a component's reference when it no longer bears the component label")
197-
componentRefEventuallyExists(w, false, getReference(scheme, saB))
202+
// Ensure the reference to sa-b is eventually removed from o's status.components.refs field
203+
By("removing a component's reference when it no longer bears the component label")
204+
componentRefEventuallyExists(w, false, getReference(scheme, saB))
198205

199-
// Delete o
200-
Eventually(func() error {
201-
err := client.Delete(clientCtx, o)
202-
if err != nil && !apierrors.IsNotFound(err) {
203-
return err
204-
}
205-
return nil
206-
}).Should(Succeed())
206+
// Delete o
207+
Eventually(func() error {
208+
err := client.Delete(clientCtx, o)
209+
if err != nil && !apierrors.IsNotFound(err) {
210+
return err
211+
}
212+
return nil
213+
}).Should(Succeed())
207214

208-
// Ensure that o is eventually recreated (because some of its components still exist).
209-
By("recreating the Operator when any components still exist")
210-
Eventually(func() error {
211-
return client.Get(clientCtx, types.NamespacedName{Name: o.GetName()}, o)
212-
}).Should(Succeed())
215+
// Ensure that o is eventually recreated (because some of its components still exist).
216+
By("recreating the Operator when any components still exist")
217+
Eventually(func() error {
218+
return client.Get(clientCtx, types.NamespacedName{Name: o.GetName()}, o)
219+
}).Should(Succeed())
213220

214-
// Delete ns-a
215-
Eventually(func() error {
216-
err := client.Delete(clientCtx, nsA)
217-
if apierrors.IsNotFound(err) {
218-
return nil
219-
}
220-
return err
221-
}).Should(Succeed())
221+
// Delete ns-a
222+
Eventually(func() error {
223+
err := client.Delete(clientCtx, nsA)
224+
if apierrors.IsNotFound(err) {
225+
return nil
226+
}
227+
return err
228+
}).Should(Succeed())
222229

223-
// Ensure the reference to ns-a is eventually removed from o's status.components.refs field
224-
By("removing a component's reference when it no longer exists")
225-
componentRefEventuallyExists(w, false, getReference(scheme, nsA))
230+
// Ensure the reference to ns-a is eventually removed from o's status.components.refs field
231+
By("removing a component's reference when it no longer exists")
232+
componentRefEventuallyExists(w, false, getReference(scheme, nsA))
226233

227-
// Delete o
228-
Eventually(func() error {
229-
err := client.Delete(clientCtx, o)
230-
if apierrors.IsNotFound(err) {
231-
return nil
232-
}
233-
return err
234-
}).Should(Succeed())
234+
// Delete o
235+
Eventually(func() error {
236+
err := client.Delete(clientCtx, o)
237+
if apierrors.IsNotFound(err) {
238+
return nil
239+
}
240+
return err
241+
}).Should(Succeed())
235242

236-
// Ensure that o is consistently not found
237-
By("verifying the Operator is permanently deleted if it has no components")
238-
Consistently(func() error {
239-
err := client.Get(clientCtx, types.NamespacedName{Name: o.GetName()}, o)
240-
if apierrors.IsNotFound(err) {
241-
return nil
242-
}
243-
return err
244-
}).Should(Succeed())
243+
// Ensure that o is consistently not found
244+
By("verifying the Operator is permanently deleted if it has no components")
245+
Consistently(func() error {
246+
err := client.Get(clientCtx, types.NamespacedName{Name: o.GetName()}, o)
247+
if apierrors.IsNotFound(err) {
248+
return nil
249+
}
250+
return err
251+
}).Should(Succeed())
252+
})
245253
})
246254

247255
Context("when a subscription to a package exists", func() {
@@ -329,6 +337,13 @@ var _ = Describe("Operator API", func() {
329337
})
330338

331339
AfterEach(func() {
340+
By("Checking whether the test case had failed")
341+
if CurrentGinkgoTestDescription().Failed {
342+
ctx.Ctx().DescribeResource(fmt.Sprintf("kubectl get operators %s -o yaml", operatorName.Name))
343+
ctx.Ctx().DescribeResource(fmt.Sprintf("kubectl -n %s get sa kiali-operator -o yaml", ns.GetName()))
344+
ctx.Ctx().DescribeResource(fmt.Sprintf("kubectl -n %s logs -l app=olm-operator --tail=50 --prefix --timestamps", *olmNamespace))
345+
}
346+
332347
By("Deleting the testing namespace")
333348
Eventually(func() error {
334349
return controllerclient.IgnoreNotFound(client.Delete(clientCtx, ns))
@@ -529,6 +544,7 @@ func ReferenceComponents(refs []*corev1.ObjectReference) gomegatypes.GomegaMatch
529544

530545
for _, ref := range refs {
531546
if _, ok := actual[*ref]; !ok {
547+
ctx.Ctx().Logf("reference missing: %v - %v - %v", ref.GetObjectKind(), ref.Name, ref.Namespace)
532548
return false, nil
533549
}
534550
}

0 commit comments

Comments
 (0)