Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #245 from joshwget/lb-target-links
Browse files Browse the repository at this point in the history
Add a link on load balancers for each target service
  • Loading branch information
ibuildthecloud authored Feb 15, 2017
2 parents 40f5c8c + fad8a5c commit cf5b2de
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions rancher/lb_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,36 @@ import (
"strconv"
"strings"

"github.com/docker/libcompose/utils"
legacyClient "github.com/rancher/go-rancher/client"
"github.com/rancher/go-rancher/v2"
)

// Links to target services should be automatically added to load balancers
func (r *RancherService) populateLbLinks() error {
links, err := r.getLinks()
if err != nil {
return err
}

var linkServiceNames []string
for link := range links {
linkServiceNames = append(linkServiceNames, link.ServiceName)
}

lbConfig := r.RancherConfig().LbConfig
serviceType := FindServiceType(r)
if lbConfig != nil && (serviceType == LbServiceType || serviceType == LegacyLbServiceType) {
for _, portRule := range lbConfig.PortRules {
if portRule.Service != "" && !utils.Contains(linkServiceNames, portRule.Service) {
r.serviceConfig.Links = append(r.serviceConfig.Links, portRule.Service)
}
}
}

return nil
}

func populateLbFields(r *RancherService, launchConfig *client.LaunchConfig, service *CompositeService) error {
serviceType := FindServiceType(r)

Expand Down
6 changes: 5 additions & 1 deletion rancher/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func (f *NormalFactory) Hash(service *RancherService) (digest.ServiceHash, error
}

func (f *NormalFactory) configAndHash(r *RancherService) (digest.ServiceHash, *CompositeService, error) {
if err := r.populateLbLinks(); err != nil {
return digest.ServiceHash{}, nil, err
}

rancherService, launchConfig, secondaryLaunchConfigs, err := f.config(r)
if err != nil {
return digest.ServiceHash{}, nil, err
Expand Down Expand Up @@ -150,7 +154,7 @@ func (f *NormalFactory) Upgrade(r *RancherService, force bool, selected []string

service := hash.Service != existingHash.Service || isForce(r.Name(), force, selected)
launchConfig := hash.LaunchConfig != existingHash.LaunchConfig || isForce(r.Name(), force, selected)
for oldSecondary, _ := range existingHash.SecondaryLaunchConfigs {
for oldSecondary := range existingHash.SecondaryLaunchConfigs {
if _, ok := hash.SecondaryLaunchConfigs[oldSecondary]; !ok {
removedSecondaryNames = append(removedSecondaryNames, oldSecondary)
}
Expand Down

0 comments on commit cf5b2de

Please sign in to comment.