@@ -704,16 +704,14 @@ func processResults(ctx context.Context, antreaClientset antrea.Interface, k8sCl
704
704
705
705
// download logs from kubernetes api
706
706
if failedNodes != nil {
707
- err = downloadFallbackAgentBundleFromKubernetes (ctx , antreaClientset , k8sClient , failedNodes , dir )
708
- if err != nil {
707
+ if err = downloadFallbackAgentBundleFromKubernetes (ctx , antreaClientset , k8sClient , failedNodes , dir ); err != nil {
709
708
fmt .Println ("Failed to download agent bundle from kubernetes api: " + err .Error ())
710
709
} else {
711
710
allFailed = false
712
711
}
713
712
}
714
713
if controllerFailed {
715
- err = downloadFallbackControllerBundleFromKubernetes (ctx , antreaClientset , k8sClient , dir )
716
- if err != nil {
714
+ if err = downloadFallbackControllerBundleFromKubernetes (ctx , antreaClientset , k8sClient , dir ); err != nil {
717
715
fmt .Println ("Failed to download controller bundle from kubernetes api: " + err .Error ())
718
716
} else {
719
717
allFailed = false
@@ -762,7 +760,7 @@ func downloadFallbackControllerBundleFromKubernetes(ctx context.Context, antreaC
762
760
if err := downloadPodLogs (ctx , k8sClient , pod .Namespace , pod .Name , k8s .GetPodContainerNames (pod ), tmpDir ); err != nil {
763
761
return err
764
762
}
765
- return packPodLogs (pod , dir , tmpDir )
763
+ return packPodBundle (pod , dir , tmpDir )
766
764
}
767
765
768
766
func downloadFallbackAgentBundleFromKubernetes (ctx context.Context , antreaClientset antrea.Interface , k8sClient kubernetes.Interface , failedNodes []string , dir string ) error {
@@ -807,15 +805,15 @@ func downloadFallbackAgentBundleFromKubernetes(ctx context.Context, antreaClient
807
805
if err != nil {
808
806
return err
809
807
}
810
- return packPodLogs (& pod , dir , tmpDir )
808
+ return packPodBundle (& pod , dir , tmpDir )
811
809
}(); err != nil {
812
810
errors = append (errors , err )
813
811
}
814
812
}
815
813
return utilerror .NewAggregate (errors )
816
814
}
817
815
818
- func packPodLogs (pod * corev1.Pod , dir string , logsDir string ) error {
816
+ func packPodBundle (pod * corev1.Pod , dir string , bundleDir string ) error {
819
817
prefix := "agent_"
820
818
if strings .Contains (pod .Name , "controller" ) {
821
819
prefix = "controller_"
@@ -824,17 +822,16 @@ func packPodLogs(pod *corev1.Pod, dir string, logsDir string) error {
824
822
f , err := defaultFS .Create (gzFileName )
825
823
if err != nil {
826
824
return err
827
- } else {
828
- defer f .Close ()
829
- _ , err := compress .PackDir (defaultFS , logsDir , f )
830
- return err
831
825
}
826
+ defer f .Close ()
827
+ _ , err = compress .PackDir (defaultFS , bundleDir , f )
828
+ return err
832
829
}
833
830
834
- func downloadPodLogs (ctx context.Context , k8sClient kubernetes.Interface , namespace string , podName string , containers []string , tmpDir string ) error {
831
+ func downloadPodLogs (ctx context.Context , k8sClient kubernetes.Interface , namespace string , podName string , containers []string , dir string ) error {
835
832
downloadContainerLogs := func (containerName string ) error {
836
833
containerDirName , _ := strings .CutPrefix (containerName , "antrea-" )
837
- containerLogDir := filepath .Join (tmpDir , "logs" , containerDirName )
834
+ containerLogDir := filepath .Join (dir , "logs" , containerDirName )
838
835
err := os .MkdirAll (containerLogDir , 0755 )
839
836
if err != nil {
840
837
return err
@@ -854,8 +851,7 @@ func downloadPodLogs(ctx context.Context, k8sClient kubernetes.Interface, namesp
854
851
return err
855
852
}
856
853
857
- _ , err = io .Copy (f , logStream )
858
- if err != nil {
854
+ if _ , err = io .Copy (f , logStream ); err != nil {
859
855
return err
860
856
}
861
857
return logStream .Close ()
0 commit comments