@@ -108,19 +108,17 @@ type NewDesiredTargetGroupsOptions struct {
108
108
109
109
// NewDesiredTargetGroups returns a new targetgroups.TargetGroups based on an extensions.Ingress.
110
110
func NewDesiredTargetGroups (o * NewDesiredTargetGroupsOptions ) (TargetGroups , error ) {
111
- var output TargetGroups
112
111
var backends []* extensions.IngressBackend
113
-
114
112
if o .Ingress .Spec .Backend != nil {
115
113
backends = append (backends , o .Ingress .Spec .Backend )
116
114
}
117
-
118
115
for _ , rule := range o .Ingress .Spec .Rules {
119
116
for i := range rule .HTTP .Paths {
120
117
backends = append (backends , & rule .HTTP .Paths [i ].Backend )
121
118
}
122
119
}
123
120
121
+ var targetGroupsInUse TargetGroups
124
122
for _ , backend := range backends {
125
123
if action .Use (backend .ServicePort .String ()) {
126
124
// action annotations do not need target groups
@@ -138,11 +136,17 @@ func NewDesiredTargetGroups(o *NewDesiredTargetGroupsOptions) (TargetGroups, err
138
136
})
139
137
140
138
if err != nil {
141
- return nil , err
139
+ return o . ExistingTargetGroups , err
142
140
}
143
-
144
- output = append (output , targetGroup )
141
+ targetGroupsInUse = append (targetGroupsInUse , targetGroup )
145
142
}
146
143
144
+ output := targetGroupsInUse
145
+ for _ , tg := range o .ExistingTargetGroups {
146
+ if _ , tgInUse := targetGroupsInUse .FindById (tg .ID ); tgInUse == nil {
147
+ tg .StripDesiredState ()
148
+ output = append (output , tg )
149
+ }
150
+ }
147
151
return output , nil
148
152
}
0 commit comments