Skip to content

Commit

Permalink
TargetGroup names are not unique enough in the current state, if two …
Browse files Browse the repository at this point in the history
…services were using the same port they would conflict. This wasn't a problem when services were nodeports only.
  • Loading branch information
bigkraig committed Jul 27, 2018
1 parent 972b6c5 commit 7b98e25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/alb/tg/targetgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ type NewDesiredTargetGroupOptions struct {
func NewDesiredTargetGroup(o *NewDesiredTargetGroupOptions) *TargetGroup {
hasher := md5.New()
hasher.Write([]byte(o.LoadBalancerID))
hasher.Write([]byte(fmt.Sprintf("%d", o.Port)))
hasher.Write([]byte(o.SvcName))
hasher.Write([]byte(fmt.Sprintf("%d", o.SvcPort)))
hasher.Write([]byte(*o.Annotations.TargetGroup.BackendProtocol))

targetType := aws.String("instance")
if *o.Annotations.TargetGroup.TargetType == "pod" {
targetType = aws.String("ip")
hasher.Write([]byte(*targetType))
}

name := hex.EncodeToString(hasher.Sum(nil))
id := fmt.Sprintf("%.12s-%.5d-%.5s-%.7s", o.Store.GetConfig().ALBNamePrefix, o.Port, *o.Annotations.TargetGroup.BackendProtocol, name)
n := fmt.Sprintf("%s-%s", o.SvcName, hex.EncodeToString(hasher.Sum(nil)))
id := fmt.Sprintf("%.12s-%.19s", o.Store.GetConfig().ALBNamePrefix, n)

// TODO: Quick fix as we can't have the loadbalancer and target groups share pointers to the same
// tags. Each modify tags individually and can cause bad side-effects.
Expand Down
4 changes: 4 additions & 0 deletions internal/ingress/controller/alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func NewALBController(config *config.Configuration, mc metric.Collector) *ALBCon
albrgt.NewRGT(sess, config.ClusterName)
albwafregional.NewWAFRegional(sess)

if len(config.ALBNamePrefix) > 12 {
glog.Fatalf("ALB Name prefix must be 12 characters or less")
}

if config.ALBNamePrefix == "" {
config.ALBNamePrefix = generateAlbNamePrefix(config.ClusterName)
}
Expand Down

0 comments on commit 7b98e25

Please sign in to comment.