@@ -133,7 +133,7 @@ func (n *NlbPlugin) Alias() string {
133
133
func (n * NlbPlugin ) Init (c client.Client , options cloudprovider.CloudProviderOptions , ctx context.Context ) error {
134
134
n .mutex .Lock ()
135
135
defer n .mutex .Unlock ()
136
- err := startWatchTargetGroup (ctx )
136
+ err := startWatchTargetGroup ()
137
137
if err != nil {
138
138
return err
139
139
}
@@ -245,13 +245,29 @@ func (n *NlbPlugin) OnPodUpdated(c client.Client, pod *corev1.Pod, ctx context.C
245
245
246
246
// enable network
247
247
if ! networkManager .GetNetworkDisabled () {
248
- tgbList := & elbv2api.TargetGroupBindingList {}
249
- err = c .List (ctx , tgbList , client.MatchingLabels {ResourceTagKey : ResourceTagValue , SvcSelectorKey : pod .GetName ()})
248
+ selector := client.MatchingLabels {
249
+ ResourceTagKey : ResourceTagValue ,
250
+ SvcSelectorKey : pod .GetName (),
251
+ }
252
+ var tgbList elbv2api.TargetGroupBindingList
253
+ err = c .List (ctx , & tgbList , selector )
250
254
if err != nil {
251
255
return pod , cperrors .ToPluginError (err , cperrors .ApiCallError )
252
256
}
253
257
if len (tgbList .Items ) != len (svc .Spec .Ports ) {
254
- return pod , cperrors .ToPluginError (n .syncTargetGroupAndService (lbConfig , pod , c , ctx ), cperrors .ApiCallError )
258
+ var tgList ackv1alpha1.TargetGroupList
259
+ err = c .List (ctx , & tgList , selector )
260
+ if err != nil {
261
+ return pod , cperrors .ToPluginError (err , cperrors .ApiCallError )
262
+ }
263
+ patch := client .RawPatch (types .MergePatchType ,
264
+ []byte (fmt .Sprintf (`{"metadata":{"labels":{"%s":"false"}}}` , AWSTargetGroupSyncStatus )))
265
+ for _ , tg := range tgList .Items {
266
+ err = c .Patch (ctx , & tg , patch )
267
+ if err != nil {
268
+ return pod , cperrors .ToPluginError (err , cperrors .ApiCallError )
269
+ }
270
+ }
255
271
}
256
272
}
257
273
@@ -580,6 +596,8 @@ func watchTargetGroup(ctx context.Context) error {
580
596
if err != nil {
581
597
continue
582
598
}
599
+ log .Infof ("targetGroup sync request watched, start to sync %s/%s, ARN: %s" ,
600
+ targetGroup .GetNamespace (), targetGroup .GetName (), targetGroupARN )
583
601
err = syncListenerAndTargetGroupBinding (ctx , cw , targetGroup , & targetGroupARN )
584
602
if err != nil {
585
603
log .Errorf ("syncListenerAndTargetGroupBinding by targetGroup %s error %v" ,
@@ -600,10 +618,13 @@ func watchTargetGroup(ctx context.Context) error {
600
618
return nil
601
619
}
602
620
603
- func startWatchTargetGroup (ctx context. Context ) error {
621
+ func startWatchTargetGroup () error {
604
622
var err error
605
623
startOnce .Do (func () {
606
- err = watchTargetGroup (ctx )
624
+ err = watchTargetGroup (context .Background ())
625
+ if err == nil {
626
+ log .Info ("start to watch TargetGroups successfully" )
627
+ }
607
628
})
608
629
return err
609
630
}
0 commit comments