github.com/cilium/cilium@v1.16.2/operator/watchers/bgp.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package watchers 5 6 import ( 7 "context" 8 9 "github.com/cilium/cilium/pkg/bgp/manager" 10 "github.com/cilium/cilium/pkg/k8s/client" 11 "github.com/cilium/cilium/pkg/k8s/resource" 12 slim_corev1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1" 13 ) 14 15 // StartBGPBetaLBIPAllocator starts the service watcher if it hasn't already and looks 16 // for service of type LoadBalancer. Once it finds a service of that type, it 17 // will try to allocate an external IP (LoadBalancerIP) for it. 18 func StartBGPBetaLBIPAllocator(ctx context.Context, clientset client.Clientset, services resource.Resource[*slim_corev1.Service]) { 19 go func() { 20 store, err := services.Store(ctx) 21 if err != nil { 22 log.WithError(err).Fatal("Failed to retrieve service store") 23 } 24 25 m, err := manager.New(ctx, clientset, store.CacheStore()) 26 if err != nil { 27 log.WithError(err).Fatal("Error creating BGP manager") 28 } 29 30 for ev := range services.Events(ctx) { 31 switch ev.Kind { 32 case resource.Sync: 33 m.MarkSynced() 34 case resource.Upsert: 35 m.OnUpdateService(nil, ev.Object) 36 case resource.Delete: 37 m.OnDeleteService(ev.Object) 38 } 39 ev.Done(nil) 40 } 41 }() 42 }