@@ -86,11 +86,36 @@ var _ = Describe("Bundle", Ordered, func() {
8686 })
8787
8888 AfterEach (func () {
89- By ("Cleaning up all resources" )
90- for _ , ns := range []string {namespace1 , namespace2 , namespace3 , namespace4 } {
91- cmd := exec .Command ("kubectl" , "delete" , "namespace" , ns , "--ignore-not-found" )
92- _ , err := utils .Run (cmd )
93- Expect (err ).NotTo (HaveOccurred ())
89+ specReport := CurrentSpecReport ()
90+ if ! specReport .Failed () {
91+ By ("Cleaning up all resources" )
92+ for _ , ns := range []string {namespace1 , namespace2 , namespace3 , namespace4 } {
93+ cmd := exec .Command ("kubectl" , "delete" , "namespace" , ns , "--ignore-not-found" )
94+ _ , err := utils .Run (cmd )
95+ Expect (err ).NotTo (HaveOccurred ())
96+ }
97+ } else {
98+ // collect logs in case it failed
99+ By ("Collecting logs from deployed operators" )
100+ for _ , ns := range []string {namespace1 , namespace2 , namespace3 , namespace4 } {
101+ By ("Logs from operator in namespace " + ns )
102+ cmd := exec .Command ("kubectl" , "logs" , "-l" , "control-plane=controller-manager" , "--namespace" , ns )
103+ controllerLogs , err := utils .Run (cmd )
104+ if err == nil {
105+ _ , _ = fmt .Fprintf (GinkgoWriter , "Controller logs:\n %s" , controllerLogs )
106+ } else {
107+ _ , _ = fmt .Fprintf (GinkgoWriter , "Failed to get Controller logs: %s" , err )
108+ }
109+ }
110+
111+ By ("Collecting functions" )
112+ cmd := exec .Command ("kubectl" , "get" , "function" , "-A" , "-o" , "yaml" )
113+ out , err := utils .Run (cmd )
114+ if err == nil {
115+ _ , _ = fmt .Fprintf (GinkgoWriter , "Functions:\n %s" , out )
116+ } else {
117+ _ , _ = fmt .Fprintf (GinkgoWriter , "Failed to get functions: %s" , err )
118+ }
94119 }
95120 })
96121
@@ -111,12 +136,14 @@ var _ = Describe("Bundle", Ordered, func() {
111136 })
112137
113138 AfterAll (func () {
114- By ("Uninstalling the operator" )
115- out , err := utils .OperatorSdkRun ("cleanup" ,
116- "--namespace" , namespace1 ,
117- "--delete-all" )
118- Expect (err ).NotTo (HaveOccurred ())
119- _ , _ = fmt .Fprint (GinkgoWriter , out )
139+ specReport := CurrentSpecReport ()
140+ if ! specReport .Failed () {
141+ By ("Uninstalling the operator" )
142+ out , err := utils .OperatorSdkRun ("cleanup" ,
143+ "--namespace" , namespace1 )
144+ Expect (err ).NotTo (HaveOccurred ())
145+ _ , _ = fmt .Fprint (GinkgoWriter , out )
146+ }
120147 })
121148
122149 It ("should reconcile function in own namespace" , func () {
@@ -140,12 +167,14 @@ var _ = Describe("Bundle", Ordered, func() {
140167 })
141168
142169 AfterAll (func () {
143- By ("Uninstalling the operator" )
144- out , err := utils .OperatorSdkRun ("cleanup" ,
145- "--namespace" , namespace1 ,
146- "--delete-all" )
147- Expect (err ).NotTo (HaveOccurred ())
148- _ , _ = fmt .Fprint (GinkgoWriter , out )
170+ specReport := CurrentSpecReport ()
171+ if ! specReport .Failed () {
172+ By ("Uninstalling the operator" )
173+ out , err := utils .OperatorSdkRun ("cleanup" ,
174+ "--namespace" , namespace1 )
175+ Expect (err ).NotTo (HaveOccurred ())
176+ _ , _ = fmt .Fprint (GinkgoWriter , out )
177+ }
149178 })
150179
151180 It ("should reconcile function in dedicated namespace" , func () {
@@ -170,12 +199,14 @@ var _ = Describe("Bundle", Ordered, func() {
170199 })
171200
172201 AfterAll (func () {
173- By ("Uninstalling the operator" )
174- out , err := utils .OperatorSdkRun ("cleanup" ,
175- "--namespace" , namespace1 ,
176- "--delete-all" )
177- Expect (err ).NotTo (HaveOccurred ())
178- _ , _ = fmt .Fprint (GinkgoWriter , out )
202+ specReport := CurrentSpecReport ()
203+ if ! specReport .Failed () {
204+ By ("Uninstalling the operator" )
205+ out , err := utils .OperatorSdkRun ("cleanup" ,
206+ "--namespace" , namespace1 )
207+ Expect (err ).NotTo (HaveOccurred ())
208+ _ , _ = fmt .Fprint (GinkgoWriter , out )
209+ }
179210 })
180211
181212 It ("should reconcile function in dedicated namespaces" , func () {
@@ -210,19 +241,21 @@ var _ = Describe("Bundle", Ordered, func() {
210241 })
211242
212243 AfterAll (func () {
213- By ("Uninstalling the operator from " + namespace1 )
214- out , err := utils .OperatorSdkRun ("cleanup" ,
215- "--namespace" , namespace1 ,
216- "--delete-operator-groups" )
217- Expect (err ).NotTo (HaveOccurred ())
218- _ , _ = fmt .Fprint (GinkgoWriter , out )
219-
220- By ("Uninstalling the operator from " + namespace3 )
221- out , err = utils .OperatorSdkRun ("cleanup" ,
222- "--namespace" , namespace3 ,
223- "--delete-all" )
224- Expect (err ).NotTo (HaveOccurred ())
225- _ , _ = fmt .Fprint (GinkgoWriter , out )
244+ specReport := CurrentSpecReport ()
245+ if ! specReport .Failed () {
246+ By ("Uninstalling the operator from " + namespace1 )
247+ out , err := utils .OperatorSdkRun ("cleanup" ,
248+ "--namespace" , namespace1 ,
249+ "--delete-operator-groups" ) // dont delete CRDs, as operator in ns3 still has them
250+ Expect (err ).NotTo (HaveOccurred ())
251+ _ , _ = fmt .Fprint (GinkgoWriter , out )
252+
253+ By ("Uninstalling the operator from " + namespace3 )
254+ out , err = utils .OperatorSdkRun ("cleanup" ,
255+ "--namespace" , namespace3 )
256+ Expect (err ).NotTo (HaveOccurred ())
257+ _ , _ = fmt .Fprint (GinkgoWriter , out )
258+ }
226259 })
227260
228261 It ("should reconcile function in dedicated namespaces" , func () {
@@ -248,12 +281,14 @@ var _ = Describe("Bundle", Ordered, func() {
248281 })
249282
250283 AfterAll (func () {
251- By ("Uninstalling the operator" )
252- out , err := utils .OperatorSdkRun ("cleanup" ,
253- "--namespace" , namespace1 ,
254- "--delete-all" )
255- Expect (err ).NotTo (HaveOccurred ())
256- _ , _ = fmt .Fprint (GinkgoWriter , out )
284+ specReport := CurrentSpecReport ()
285+ if ! specReport .Failed () {
286+ By ("Uninstalling the operator" )
287+ out , err := utils .OperatorSdkRun ("cleanup" ,
288+ "--namespace" , namespace1 )
289+ Expect (err ).NotTo (HaveOccurred ())
290+ _ , _ = fmt .Fprint (GinkgoWriter , out )
291+ }
257292 })
258293
259294 It ("should reconcile function in all namespaces" , func () {
0 commit comments