@@ -244,17 +244,16 @@ func deleteRemoteCluster(cr *v1alpha1.GKECluster, log *logrus.Entry) error {
244244}
245245
246246func collectLogs (c * RemoteCluster , cr * v1alpha1.GKECluster , log * logrus.Entry , started chan int ) {
247- done := make (chan error )
248-
249247 logPath := path .Join ("/tmp" , cr .Status .ClusterName )
250248 err := os .Mkdir (logPath , os .ModePerm )
251249 if err != nil {
252250 log .Warningf ("Failed to create pod logs dir, won't collect pod logs %v" , err )
253- started <- 1
251+ close ( started )
254252 return
255253 }
256- started <- 1
254+ close ( started )
257255
256+ done := make (chan error )
258257 go retrieveLogs (cr , c , log , logPath , done )
259258
260259 defer func () {
@@ -267,7 +266,6 @@ func collectLogs(c *RemoteCluster, cr *v1alpha1.GKECluster, log *logrus.Entry, s
267266 select {
268267 case <- time .After (time .Minute * 5 ):
269268 log .Infof ("timeout collecting logs for %s" , cr .Status .ClusterName )
270- close (done )
271269 return
272270 case <- done :
273271 log .Infof ("finished collecting logs for %s" , cr .Status .ClusterName )
@@ -325,7 +323,7 @@ func checkTimeout(cr *v1alpha1.GKECluster, log *logrus.Entry) error {
325323 if sinceFirstCleaned < waitDur {
326324 log .Debugf ("timestamp FirstCleaned: %s => %s since then. Wait until %s have elapsed since first cleaning" , cr .Status .FirstCleanedAt , sinceFirstCleaned , waitDur )
327325 } else {
328- log .Debug ("timestamp FirstCleaned: %s => %s since then. Proceed with deleting cluster" , cr .Status .FirstCleanedAt , sinceFirstCleaned )
326+ log .Debugf ("timestamp FirstCleaned: %s => %s since then. Proceed with deleting cluster" , cr .Status .FirstCleanedAt , sinceFirstCleaned )
329327 cr .Status .Message = "deleting cluster"
330328 if err = action .Update (cr ); err != nil {
331329 log .Errorf ("Failed to update status: %v" , err )
@@ -375,13 +373,7 @@ func deleteGKECluster(cr *v1alpha1.GKECluster, log *logrus.Entry) error {
375373
376374 started := make (chan int )
377375 go collectLogs (gkecluster , cr , log , started )
378- select {
379- case <- time .After (time .Second * 5 ):
380- break
381- case <- started :
382- break
383- }
384- close (started )
376+ <- started
385377 }
386378
387379 switch cr .Status .Message {
@@ -707,15 +699,7 @@ type CollectedPod struct {
707699
708700func retrieveLogs (cr * v1alpha1.GKECluster , cluster * RemoteCluster , log * logrus.Entry , logPath string , done chan error ) {
709701 log .Infof ("Collecting data from GKE cluster %s" , cluster .Name )
710- defer func () {
711- // avoid close chan repeatedly
712- select {
713- case <- time .After (time .Millisecond * 100 ):
714- close (done )
715- case <- done :
716- break
717- }
718- }()
702+ defer close (done )
719703
720704 annotations := cr .GetAnnotations ()
721705 _ , ok := annotations ["infrabox.net/root-url" ]
@@ -763,7 +747,7 @@ func retrieveLogs(cr *v1alpha1.GKECluster, cluster *RemoteCluster, log *logrus.E
763747 filename := "pod_" + pod .Namespace + "_" + pod .Pod + "_" + container + ".txt"
764748 filename = path .Join (logPath , filename )
765749 if err := ioutil .WriteFile (filename , * data , os .ModePerm ); err != nil {
766- log .Warningf ("Failed to write pod logs: %v" , err )
750+ log .Debugf ("Failed to write pod logs: %v" , err )
767751 continue
768752 }
769753 }
@@ -772,13 +756,13 @@ func retrieveLogs(cr *v1alpha1.GKECluster, cluster *RemoteCluster, log *logrus.E
772756 archivePath := path .Join (logPath , "pods_log.zip" )
773757 err = archiver .Archive ([]string {logPath }, archivePath )
774758 if err != nil {
775- log .Warningf ("Failed to archive log: %v" , err )
759+ log .Debugf ("Failed to archive log: %v" , err )
776760 return
777761 }
778762
779763 archiveData , err := ioutil .ReadFile (archivePath )
780764 if err != nil {
781- log .Warningf ("Failed to archive log: %v" , err )
765+ log .Debugf ("Failed to archive log: %v" , err )
782766 return
783767 }
784768 err = uploadToArchive (cr , log , & archiveData , archivePath )
0 commit comments