Add backends of proper type to backend service
This commit is contained in:
parent
cd3e546c80
commit
962dddda9a
1 changed files with 37 additions and 23 deletions
|
@ -202,18 +202,7 @@ func (b *Backends) create(igs []*compute.InstanceGroup, namedPort *compute.Named
|
||||||
}
|
}
|
||||||
|
|
||||||
func newBackendService(igs []*compute.InstanceGroup, bm BalancingMode, namedPort *compute.NamedPort, healthCheckLinks []string, protocol utils.AppProtocol, name string) *compute.BackendService {
|
func newBackendService(igs []*compute.InstanceGroup, bm BalancingMode, namedPort *compute.NamedPort, healthCheckLinks []string, protocol utils.AppProtocol, name string) *compute.BackendService {
|
||||||
backends := getBackendsForIGs(igs)
|
backends := getBackendsForIGs(igs, bm)
|
||||||
for _, b := range backends {
|
|
||||||
switch bm {
|
|
||||||
case Rate:
|
|
||||||
b.MaxRatePerInstance = maxRPS
|
|
||||||
default:
|
|
||||||
// TODO: Set utilization and connection limits when we accept them
|
|
||||||
// as valid fields.
|
|
||||||
}
|
|
||||||
b.BalancingMode = string(bm)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &compute.BackendService{
|
return &compute.BackendService{
|
||||||
Name: name,
|
Name: name,
|
||||||
Protocol: string(protocol),
|
Protocol: string(protocol),
|
||||||
|
@ -315,10 +304,22 @@ func (b *Backends) List() ([]interface{}, error) {
|
||||||
return interList, nil
|
return interList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBackendsForIGs(igs []*compute.InstanceGroup) []*compute.Backend {
|
func getBackendsForIGs(igs []*compute.InstanceGroup, bm BalancingMode) []*compute.Backend {
|
||||||
backends := []*compute.Backend{}
|
var backends []*compute.Backend
|
||||||
for _, ig := range igs {
|
for _, ig := range igs {
|
||||||
backends = append(backends, &compute.Backend{Group: ig.SelfLink})
|
b := &compute.Backend{
|
||||||
|
Group: ig.SelfLink,
|
||||||
|
BalancingMode: string(bm),
|
||||||
|
}
|
||||||
|
switch bm {
|
||||||
|
case Rate:
|
||||||
|
b.MaxRatePerInstance = maxRPS
|
||||||
|
default:
|
||||||
|
// TODO: Set utilization and connection limits when we accept them
|
||||||
|
// as valid fields.
|
||||||
|
}
|
||||||
|
|
||||||
|
backends = append(backends, b)
|
||||||
}
|
}
|
||||||
return backends
|
return backends
|
||||||
}
|
}
|
||||||
|
@ -340,18 +341,31 @@ func (b *Backends) edgeHop(be *compute.BackendService, igs []*compute.InstanceGr
|
||||||
glog.Infof("Backend %v has a broken edge, expected igs %+v, current igs %+v",
|
glog.Infof("Backend %v has a broken edge, expected igs %+v, current igs %+v",
|
||||||
be.Name, igLinks.List(), beIGs.List())
|
be.Name, igLinks.List(), beIGs.List())
|
||||||
|
|
||||||
newBackends := []*compute.Backend{}
|
originalBackends := be.Backends
|
||||||
for _, b := range getBackendsForIGs(igs) {
|
var addIGs []*compute.InstanceGroup
|
||||||
if !beIGs.Has(b.Group) {
|
for _, ig := range igs {
|
||||||
newBackends = append(newBackends, b)
|
if !beIGs.Has(ig.SelfLink) {
|
||||||
|
addIGs = append(addIGs, ig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
be.Backends = append(be.Backends, newBackends...)
|
|
||||||
|
var errs []string
|
||||||
|
for _, bm := range []BalancingMode{Rate, Utilization} {
|
||||||
|
addBEs := getBackendsForIGs(addIGs, bm)
|
||||||
|
be.Backends = append(originalBackends, addBEs...)
|
||||||
|
|
||||||
if err := b.cloud.UpdateBackendService(be); err != nil {
|
if err := b.cloud.UpdateBackendService(be); err != nil {
|
||||||
|
if utils.IsHTTPErrorCode(err, http.StatusBadRequest) {
|
||||||
|
glog.Infof("Error updating backend service backends with balancing mode %v:%v", bm, err)
|
||||||
|
errs = append(errs, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("%v", strings.Join(errs, "\n"))
|
||||||
|
}
|
||||||
|
|
||||||
// Sync syncs backend services corresponding to ports in the given list.
|
// Sync syncs backend services corresponding to ports in the given list.
|
||||||
func (b *Backends) Sync(svcNodePorts []ServicePort) error {
|
func (b *Backends) Sync(svcNodePorts []ServicePort) error {
|
||||||
|
|
Loading…
Reference in a new issue