cmd/coorindator: ignore pod cleanup if Kubernetes is unavailable

* if Kubernetes init fails, don't attempt to clean existing pods
* TODOs for disabling kubePool

Updates golang/go#12546

Change-Id: I392f6cc4af31fdf307e5aa907a243ff7f5a98b00
Reviewed-on: https://go-review.googlesource.com/17104
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/coordinator/coordinator.go b/cmd/coordinator/coordinator.go
index e7bfdfb..53098ff 100644
--- a/cmd/coordinator/coordinator.go
+++ b/cmd/coordinator/coordinator.go
@@ -265,6 +265,7 @@
 		}
 	}
 
+	// TODO(evanbrown: disable kubePool if init fails)
 	err = initKube()
 	if err != nil {
 		kubeErr = err
@@ -305,7 +306,9 @@
 		http.HandleFunc("/dosomework/", handleDoSomeWork(workc))
 	} else {
 		go gcePool.cleanUpOldVMs()
-		go kubePool.cleanUpOldPods(context.Background())
+		if kubeErr == nil {
+			go kubePool.cleanUpOldPods(context.Background())
+		}
 
 		if *enableDebugProd {
 			http.HandleFunc("/dosomework/", handleDoSomeWork(workc))
@@ -1153,6 +1156,7 @@
 	if !ok {
 		return nil, fmt.Errorf("invalid BuildletType %q for %q", buildletType, st.conf.Name)
 	}
+	// TODO(evanbrown): if pool is disabled, return an error
 	return poolForConf(bconf), nil
 }
 
diff --git a/cmd/coordinator/kube.go b/cmd/coordinator/kube.go
index 9ecf8d4..2a56dda 100644
--- a/cmd/coordinator/kube.go
+++ b/cmd/coordinator/kube.go
@@ -53,10 +53,12 @@
 	registryPrefix += "/" + projectID
 	if !hasCloudPlatformScope() {
 		return errors.New("coordinator not running with access to the Cloud Platform scope.")
-
 	}
 	httpClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
-	containerService, _ = container.New(httpClient)
+	containerService, err = container.New(httpClient)
+	if err != nil {
+		return fmt.Errorf("could not create client for Google Container Engine")
+	}
 
 	cluster, err := containerService.Projects.Zones.Clusters.Get(projectID, projectZone, clusterName).Do()
 	if err != nil {
@@ -329,6 +331,7 @@
 		pods, err := kubeClient.GetPods(ctx)
 		if err != nil {
 			log.Printf("Error cleaning pods: %v", err)
+			return
 		}
 		for _, pod := range pods {
 			if pod.ObjectMeta.Annotations == nil {