forked from kubernetes-sigs/aws-load-balancer-controller
/
targetgroups.go
54 lines (47 loc) · 1.37 KB
/
targetgroups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package alb
import (
"github.com/coreos/alb-ingress-controller/log"
)
// TargetGroups is a slice of TargetGroup pointers
type TargetGroups []*TargetGroup
// LookupBySvc returns the position of a TargetGroup by its SvcName, returning -1 if unfound.
func (t TargetGroups) LookupBySvc(svc string) int {
for p, v := range t {
if v.SvcName == svc {
return p
}
}
log.Infof("No TG matching service found. SVC %s", "controller", svc)
return -1
}
// Find returns the position of a TargetGroup by its ID, returning -1 if unfound.
func (t TargetGroups) Find(tg *TargetGroup) int {
for p, v := range t {
if *v.ID == *tg.ID {
return p
}
}
return -1
}
// Reconcile kicks off the state synchronization for every target group inside this TargetGroups
// instance.
func (t TargetGroups) Reconcile(lb *LoadBalancer) error {
for _, targetgroup := range t {
if err := targetgroup.Reconcile(lb); err != nil {
return err
}
if targetgroup.deleted {
i := lb.TargetGroups.Find(targetgroup)
lb.TargetGroups = append(lb.TargetGroups[:i], lb.TargetGroups[i+1:]...)
}
}
return nil
}
// StripDesiredState removes the DesiredTags, DesiredTargetGroup, and DesiredTargets from all TargetGroups
func (t TargetGroups) StripDesiredState() {
for _, targetgroup := range t {
targetgroup.DesiredTags = nil
targetgroup.DesiredTargetGroup = nil
targetgroup.DesiredTargets = nil
}
}