Skip to content

Commit

Permalink
Use a single instance group.
Browse files Browse the repository at this point in the history
  • Loading branch information
bprashanth committed Jan 25, 2016
1 parent 391460c commit 1a9e6b5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
25 changes: 10 additions & 15 deletions Ingress/controllers/gce/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ func (b *Backends) create(ig *compute.InstanceGroup, namedPort *compute.NamedPor

// Add will get or create a Backend for the given port.
func (b *Backends) Add(port int64) error {
name := b.namer.BeName(port)

// Preemptive addition of a backend to the pool is only to force instance
// cleanup if user runs out of quota mid-way through this function, and
// decides to delete Ingress. A better solutions is to have the node pool
// cleaup after itself.
// We must track the port even if creating the backend failed, because
// we might've created a health-check for it.
be := &compute.BackendService{}
defer func() { b.snapshotter.Add(portKey(port), be) }()

ig, namedPort, err := b.nodePool.AddInstanceGroup(name, port)
ig, namedPort, err := b.nodePool.AddInstanceGroup(b.namer.IGName(), port)
if err != nil {
return err
}
Expand All @@ -123,7 +119,6 @@ func (b *Backends) Add(port int64) error {
return err
}
}
// Both the backend and instance group might exist, but be disconnected.
if err := b.edgeHop(be, ig); err != nil {
return err
}
Expand All @@ -142,9 +137,7 @@ func (b *Backends) Delete(port int64) (err error) {
b.snapshotter.Delete(portKey(port))
}
}()
// Try deleting health checks and instance groups, even if a backend is
// not found. This guards against the case where we create one of the
// other 2 and run out of quota creating the backend.
// Try deleting health checks even if a backend is not found.
if err = b.cloud.DeleteBackendService(name); err != nil &&
!utils.IsHTTPErrorCode(err, http.StatusNotFound) {
return err
Expand All @@ -153,10 +146,6 @@ func (b *Backends) Delete(port int64) (err error) {
!utils.IsHTTPErrorCode(err, http.StatusNotFound) {
return err
}
glog.Infof("Deleting instance group %v", name)
if err = b.nodePool.DeleteInstanceGroup(name); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -219,6 +208,12 @@ func (b *Backends) GC(svcNodePorts []int64) error {
return err
}
}
if len(svcNodePorts) == 0 {
glog.Infof("Deleting instance group %v", b.namer.IGName())
if err := b.nodePool.DeleteInstanceGroup(b.namer.IGName()); err != nil {
return err
}
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion Ingress/controllers/gce/backends/backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestBackendPoolAdd(t *testing.T) {
}
}
gotBackend, _ := f.GetBackendService(beName)
gotGroup, _ := fakeIGs.GetInstanceGroup(beName)
gotGroup, _ := fakeIGs.GetInstanceGroup(namer.IGName())
if gotBackend.Backends[0].Group != gotGroup.SelfLink {
t.Fatalf(
"Broken instance group link: %v %v",
Expand Down
3 changes: 2 additions & 1 deletion Ingress/controllers/gce/instances/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func NewNodePool(cloud InstanceGroups) NodePool {
return &Instances{cloud, storage.NewInMemoryPool()}
}

// AddInstanceGroup creates or gets an instance group.
// AddInstanceGroup creates or gets an instance group if it doesn't exist
// and adds the given port to it.
func (i *Instances) AddInstanceGroup(name string, port int64) (*compute.InstanceGroup, *compute.NamedPort, error) {
ig, _ := i.Get(name)
if ig == nil {
Expand Down
2 changes: 1 addition & 1 deletion Ingress/controllers/gce/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
alphaNumericChar = "0"

// Current docker image version. Only used in debug logging.
imageVersion = "0.5.2-ig"
imageVersion = "0.5.2"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions Ingress/controllers/gce/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ func (n *Namer) decorateName(name string) string {
if n.ClusterName == "" {
return name
}
return n.Trucate(fmt.Sprintf("%v%v%v", name, clusterNameDelimiter, n.ClusterName))
return n.Truncate(fmt.Sprintf("%v%v%v", name, clusterNameDelimiter, n.ClusterName))
}

// BeName constructs the name for a backend.
func (n *Namer) BeName(port int64) string {
return n.decorateName(fmt.Sprintf("%v-%d", backendPrefix, port))
}

// IgName constructs the name for an Instance Group.
func (n *Namer) IgName(port int64) string {
// IGName constructs the name for an Instance Group.
func (n *Namer) IGName() string {
// Currently all ports are added to a single instance group.
return n.decorateName(igPrefix)
}
Expand Down

0 comments on commit 1a9e6b5

Please sign in to comment.