From 61558f4d19d977bf07b14873abc339ef271a6c0b Mon Sep 17 00:00:00 2001 From: Prashanth Balasubramanian Date: Fri, 3 Jun 2016 11:22:56 -0700 Subject: [PATCH] Get rid of default-zone everywhere. --- controllers/gce/backends/backends_test.go | 16 ++++++++++++---- controllers/gce/controller/cluster_manager.go | 6 +----- controllers/gce/controller/fakes.go | 2 +- controllers/gce/instances/instances.go | 4 +++- controllers/gce/instances/instances_test.go | 2 +- .../gce/loadbalancers/loadbalancers_test.go | 6 +++--- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/controllers/gce/backends/backends_test.go b/controllers/gce/backends/backends_test.go index db1991fef..65ffbbb7e 100644 --- a/controllers/gce/backends/backends_test.go +++ b/controllers/gce/backends/backends_test.go @@ -27,10 +27,12 @@ import ( "k8s.io/kubernetes/pkg/util/sets" ) +const defaultZone = "zone-a" + func newBackendPool(f BackendServices, fakeIGs instances.InstanceGroups, syncWithCloud bool) BackendPool { namer := &utils.Namer{} - nodePool := instances.NewNodePool(fakeIGs, "default-zone") - nodePool.Init(&instances.FakeZoneLister{[]string{"zone-a"}}) + nodePool := instances.NewNodePool(fakeIGs) + nodePool.Init(&instances.FakeZoneLister{[]string{defaultZone}}) healthChecks := healthchecks.NewHealthChecker(healthchecks.NewFakeHealthChecks(), "/", namer) healthChecks.Init(&healthchecks.FakeHealthCheckGetter{nil}) return NewBackendPool( @@ -82,8 +84,14 @@ func TestBackendPoolAdd(t *testing.T) { t.Fatalf("Unexpected create for existing backend service") } } - gotBackend, _ := f.GetBackendService(beName) - gotGroup, _ := fakeIGs.GetInstanceGroup(namer.IGName(), "default-zone") + gotBackend, err := f.GetBackendService(beName) + if err != nil { + t.Fatalf("Failed to find a backend with name %v: %v", beName, err) + } + gotGroup, err := fakeIGs.GetInstanceGroup(namer.IGName(), defaultZone) + if err != nil { + t.Fatalf("Failed to find instance group %v", namer.IGName()) + } if gotBackend.Backends[0].Group != gotGroup.SelfLink { t.Fatalf( "Broken instance group link: %v %v", diff --git a/controllers/gce/controller/cluster_manager.go b/controllers/gce/controller/cluster_manager.go index 85ca39263..2e1057b39 100644 --- a/controllers/gce/controller/cluster_manager.go +++ b/controllers/gce/controller/cluster_manager.go @@ -261,13 +261,9 @@ func NewClusterManager( // Names are fundamental to the cluster, the uid allocator makes sure names don't collide. cluster := ClusterManager{ClusterNamer: &utils.Namer{name}} - zone, err := cloud.GetZone() - if err != nil { - return nil, err - } // NodePool stores GCE vms that are in this Kubernetes cluster. - cluster.instancePool = instances.NewNodePool(cloud, zone.FailureDomain) + cluster.instancePool = instances.NewNodePool(cloud) // BackendPool creates GCE BackendServices and associated health checks. healthChecker := healthchecks.NewHealthChecker(cloud, defaultHealthCheckPath, cluster.ClusterNamer) diff --git a/controllers/gce/controller/fakes.go b/controllers/gce/controller/fakes.go index db783ca0d..a2d8bb632 100644 --- a/controllers/gce/controller/fakes.go +++ b/controllers/gce/controller/fakes.go @@ -50,7 +50,7 @@ func NewFakeClusterManager(clusterName string) *fakeClusterManager { fakeHCs := healthchecks.NewFakeHealthChecks() namer := &utils.Namer{clusterName} - nodePool := instances.NewNodePool(fakeIGs, defaultZone) + nodePool := instances.NewNodePool(fakeIGs) nodePool.Init(&instances.FakeZoneLister{[]string{"zone-a"}}) healthChecker := healthchecks.NewHealthChecker(fakeHCs, "/", namer) diff --git a/controllers/gce/instances/instances.go b/controllers/gce/instances/instances.go index 7ca045e6e..b49a6df79 100644 --- a/controllers/gce/instances/instances.go +++ b/controllers/gce/instances/instances.go @@ -46,7 +46,7 @@ type Instances struct { // NewNodePool creates a new node pool. // - cloud: implements InstanceGroups, used to sync Kubernetes nodes with // members of the cloud InstanceGroup. -func NewNodePool(cloud InstanceGroups, defaultZone string) NodePool { +func NewNodePool(cloud InstanceGroups) NodePool { return &Instances{cloud, storage.NewInMemoryPool(), nil} } @@ -146,6 +146,8 @@ func (i *Instances) Get(name, zone string) (*compute.InstanceGroup, error) { return ig, nil } +// splitNodesByZones takes a list of node names and returns a map of zone:node names. +// It figures out the zones by asking the zoneLister. func (i *Instances) splitNodesByZone(names []string) map[string][]string { nodesByZone := map[string][]string{} for _, name := range names { diff --git a/controllers/gce/instances/instances_test.go b/controllers/gce/instances/instances_test.go index a20caf8b5..515e22a6f 100644 --- a/controllers/gce/instances/instances_test.go +++ b/controllers/gce/instances/instances_test.go @@ -25,7 +25,7 @@ import ( const defaultZone = "default-zone" func newNodePool(f *FakeInstanceGroups, zone string) NodePool { - pool := NewNodePool(f, zone) + pool := NewNodePool(f) pool.Init(&FakeZoneLister{[]string{zone}}) return pool } diff --git a/controllers/gce/loadbalancers/loadbalancers_test.go b/controllers/gce/loadbalancers/loadbalancers_test.go index 84f08c8cf..ef5bcaae3 100644 --- a/controllers/gce/loadbalancers/loadbalancers_test.go +++ b/controllers/gce/loadbalancers/loadbalancers_test.go @@ -29,7 +29,7 @@ import ( const ( testDefaultBeNodePort = int64(3000) - defaultZone = "default-zone" + defaultZone = "zone-a" ) func newFakeLoadBalancerPool(f LoadBalancers, t *testing.T) LoadBalancerPool { @@ -39,8 +39,8 @@ func newFakeLoadBalancerPool(f LoadBalancers, t *testing.T) LoadBalancerPool { namer := &utils.Namer{} healthChecker := healthchecks.NewHealthChecker(fakeHCs, "/", namer) healthChecker.Init(&healthchecks.FakeHealthCheckGetter{nil}) - nodePool := instances.NewNodePool(fakeIGs, defaultZone) - nodePool.Init(&instances.FakeZoneLister{[]string{"zone-a"}}) + nodePool := instances.NewNodePool(fakeIGs) + nodePool.Init(&instances.FakeZoneLister{[]string{defaultZone}}) backendPool := backends.NewBackendPool( fakeBackends, healthChecker, nodePool, namer, []int64{}, false) return NewLoadBalancerPool(f, backendPool, testDefaultBeNodePort, namer)