Move hostname detection logic to allow replacement

This commit is contained in:
Daniel Smith
2014-06-11 18:57:15 -07:00
parent 187f7d2534
commit 7c17db672e
3 changed files with 13 additions and 10 deletions

View File

@@ -60,6 +60,7 @@ type DockerInterface interface {
// The main kubelet implementation
type Kubelet struct {
Hostname string
Client registry.EtcdClient
DockerClient DockerInterface
FileCheckFrequency time.Duration
@@ -427,15 +428,10 @@ func (kl *Kubelet) getKubeletStateFromEtcd(key string, changeChannel chan<- []ap
// The channel to send new configurations across
// This function loops forever and is intended to be run in a go routine.
func (kl *Kubelet) SyncAndSetupEtcdWatch(changeChannel chan<- []api.ContainerManifest) {
hostname, err := exec.Command("hostname", "-f").Output()
if err != nil {
log.Printf("Couldn't determine hostname : %v", err)
return
}
key := "/registry/hosts/" + strings.TrimSpace(string(hostname))
key := "/registry/hosts/" + strings.TrimSpace(string(kl.Hostname))
// First fetch the initial configuration (watch only gives changes...)
for {
err = kl.getKubeletStateFromEtcd(key, changeChannel)
err := kl.getKubeletStateFromEtcd(key, changeChannel)
if err == nil {
// We got a successful response, etcd is up, set up the watch.
break