@@ -30,6 +30,8 @@ import (
3030 "github.com/deckhouse/virtualization/test/e2e/internal/kubectl"
3131)
3232
33+ const d8vContainerPrefix = "d8v"
34+
3335// SaveTestCaseDump dump some resources, logs and descriptions that may help in further diagnostic.
3436//
3537// NOTE: This method is called in AfterEach for failed specs only. Avoid to use Expect,
@@ -89,7 +91,7 @@ func (f *Framework) saveTestCaseResources(testCaseFullText, dumpPath string) {
8991 ShowManagedFields : true ,
9092 })
9193 if result .Error () != nil {
92- GinkgoWriter .Printf ("Get resources error:\n %s\n %w \n %s\n " , result .GetCmd (), result .Error (), result .StdErr ())
94+ GinkgoWriter .Printf ("Get resources error:\n %s\n %v \n %s\n " , result .GetCmd (), result .Error (), result .StdErr ())
9395 }
9496
9597 // Stdout may present even if error is occurred.
@@ -147,23 +149,42 @@ func (f *Framework) saveIntvirtvmiDescriptions(testCaseFullText, dumpPath string
147149}
148150
149151func (f * Framework ) writePodLogs (name , namespace , filePath , testCaseFullText string ) {
150- podLogs , err := f .Clients .KubeClient ().CoreV1 ().Pods (namespace ).GetLogs (name , & corev1.PodLogOptions {}).Stream (context .Background ())
152+ pod , err := f .Clients .kubeClient .CoreV1 ().Pods (namespace ).Get (context .Background (), name , metav1.GetOptions {})
153+ if err != nil {
154+ GinkgoWriter .Printf ("Failed to get pod:\n PodName: %s\n Error: %v\n " , name , err )
155+ return
156+ }
157+
158+ for _ , container := range pod .Spec .Containers {
159+ if ! strings .HasPrefix (container .Name , d8vContainerPrefix ) {
160+ GinkgoWriter .Printf ("Skipping container without d8v prefix:\n PodName: %s\n Container: %s\n " , pod .Name , container .Name )
161+ continue
162+ }
163+ f .writePodContainerLogs (pod , container .Name , filePath , testCaseFullText )
164+ }
165+ }
166+
167+ func (f * Framework ) writePodContainerLogs (pod * corev1.Pod , containerName , filePath , testCaseFullText string ) {
168+ podLogs , err := f .Clients .KubeClient ().CoreV1 ().Pods (pod .Namespace ).GetLogs (pod .Name ,
169+ & corev1.PodLogOptions {
170+ Container : containerName ,
171+ }).Stream (context .Background ())
151172 if err != nil {
152- GinkgoWriter .Printf ("Failed to get logs:\n PodName: %s\n Error: %w \n " , name , err )
173+ GinkgoWriter .Printf ("Failed to get logs:\n PodName: %s\n Container: %s \ n Error: %v \n " , pod . Name , containerName , err )
153174 return
154175 }
155176 defer podLogs .Close ()
156177
157178 logs , err := io .ReadAll (podLogs )
158179 if err != nil {
159- GinkgoWriter .Printf ("Failed to read logs:\n PodName: %s\n Error: %w \n " , name , err )
180+ GinkgoWriter .Printf ("Failed to read logs:\n PodName: %s\n Container: %s \ n Error: %v \n " , pod . Name , containerName , err )
160181 return
161182 }
162183
163- fileName := fmt .Sprintf ("%s/e2e_failed__%s__%s__logs.json" , filePath , testCaseFullText , name )
184+ fileName := fmt .Sprintf ("%s/e2e_failed__%s__%s__% s__logs.json" , filePath , testCaseFullText , pod . Name , containerName )
164185 err = os .WriteFile (fileName , logs , 0o644 )
165186 if err != nil {
166- GinkgoWriter .Printf ("Failed to save logs:\n PodName: %s\n Error: %w \n " , name , err )
187+ GinkgoWriter .Printf ("Failed to save logs:\n PodName: %s\n Container: %s \ n Error: %v \n " , pod . Name , containerName , err )
167188 }
168189}
169190
@@ -176,7 +197,7 @@ func (f *Framework) writePodDescription(name, namespace, filePath, testCaseFullT
176197 fileName := fmt .Sprintf ("%s/e2e_failed__%s__%s__describe" , filePath , testCaseFullText , name )
177198 err := os .WriteFile (fileName , describeCmd .StdOutBytes (), 0o644 )
178199 if err != nil {
179- GinkgoWriter .Printf ("Failed to save pod description:\n PodName: %s\n Error: %w \n " , name , err )
200+ GinkgoWriter .Printf ("Failed to save pod description:\n PodName: %s\n Error: %v \n " , name , err )
180201 }
181202}
182203
@@ -191,7 +212,7 @@ func (f *Framework) writeVirtualMachineGuestInfo(pod corev1.Pod, filePath, testC
191212 fileName := fmt .Sprintf ("%s/e2e_failed__%s__%s__vlctl_guest_info" , filePath , testCaseFullText , pod .Name )
192213 err := os .WriteFile (fileName , vlctlGuestInfoCmd .StdOutBytes (), 0o644 )
193214 if err != nil {
194- GinkgoWriter .Printf ("Failed to save pod guest info:\n PodName: %s\n Error: %w \n " , pod .Name , err )
215+ GinkgoWriter .Printf ("Failed to save pod guest info:\n PodName: %s\n Error: %v \n " , pod .Name , err )
195216 }
196217 }
197218 }
0 commit comments