Activate gce minion list.

This commit is contained in:
Brendan Burns
2014-06-29 21:00:22 -07:00
parent d75bd790d3
commit d5516e4cdc
7 changed files with 38 additions and 5 deletions

View File

@@ -38,6 +38,6 @@ type TCPLoadBalancer interface {
type Instances interface {
IPAddress(name string) (net.IP, error)
// Lists instances that match 'filter' which is a regular expression which must match the entire instance name
// Lists instances that match 'filter' which is a regular expression which must match the entire instance name (fqdn)
List(filter string) ([]string, error)
}

View File

@@ -21,6 +21,7 @@ import (
"io/ioutil"
"net"
"net/http"
"os/exec"
"strconv"
"strings"
"time"
@@ -181,7 +182,31 @@ func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
return ip, nil
}
// This is hacky, compute the delta between hostame and hostname -f
func fqdnSuffix() (string, error) {
fullHostname, err := exec.Command("hostname", "-f").Output()
if err != nil {
return "", err
}
hostname, err := exec.Command("hostname").Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(fullHostname)[len(string(hostname)):]), nil
}
func (gce *GCECloud) List(filter string) ([]string, error) {
// GCE gives names without their fqdn suffix, so get that here for appending.
// This is needed because the kubelet looks for its jobs in /registry/hosts/<fqdn>/pods
// We should really just replace this convention, with a negotiated naming protocol for kubelet's
// to register with the master.
suffix, err := fqdnSuffix()
if err != nil {
return []string{}, err
}
if len(suffix) > 0 {
suffix = "." + suffix
}
listCall := gce.service.Instances.List(gce.projectID, gce.zone)
if len(filter) > 0 {
listCall = listCall.Filter("name eq " + filter)
@@ -192,7 +217,7 @@ func (gce *GCECloud) List(filter string) ([]string, error) {
}
var instances []string
for _, instance := range res.Items {
instances = append(instances, instance.Name)
instances = append(instances, instance.Name+suffix)
}
return instances, nil
}