Fix mislooping in ssh.go. Add retries to AddSSHKeys.

(cherry picked from commit 4d5d0457ef)
This commit is contained in:
CJ Cullen 2015-06-15 23:00:01 -07:00 committed by Brendan Burns
parent db645dd31a
commit e98f79e4bc
2 changed files with 42 additions and 31 deletions

View File

@ -32,6 +32,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
"code.google.com/p/gcfg"
compute "code.google.com/p/google-api-go-client/compute/v1"
@ -483,13 +484,16 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
}
func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
project, err := gce.service.Projects.Get(gce.projectID).Do()
if err != nil {
return err
glog.Errorf("Could not get project: %v", err)
return false, nil
}
hostname, err := os.Hostname()
if err != nil {
return err
glog.Errorf("Could not get hostname: %v", err)
return false, nil
}
keyString := fmt.Sprintf("%s:%s %s@%s", user, strings.TrimSpace(string(keyData)), user, hostname)
found := false
@ -511,9 +515,15 @@ func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error
}
op, err := gce.service.Projects.SetCommonInstanceMetadata(gce.projectID, project.CommonInstanceMetadata).Do()
if err != nil {
return err
glog.Errorf("Could not Set Metadata: %v", err)
return false, nil
}
return gce.waitForGlobalOp(op)
if err := gce.waitForGlobalOp(op); err != nil {
glog.Errorf("Could not Set Metadata: %v", err)
return false, nil
}
return true, nil
})
}
func addKey(metadataBefore, keyString string) string {

View File

@ -223,11 +223,12 @@ func MakeSSHTunnels(user, keyfile string, addresses []string) (SSHTunnelList, er
}
func (l SSHTunnelList) Open() error {
for ix := range l {
for ix := 0; ix < len(l); ix++ {
if err := l[ix].Tunnel.Open(); err != nil {
// Remove a failed Open from the list.
glog.Errorf("Failed to open tunnel %v: %v", l[ix], err)
l = append(l[:ix], l[ix+1:]...)
ix--
}
}
if len(l) == 0 {