github.com/cilium/cilium@v1.16.2/pkg/k8s/watchers/subscriber/ces.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package subscriber 5 6 import ( 7 cilium_v2a1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1" 8 ) 9 10 // NewCES creates a new ces subscriber list. 11 func NewCES() *CESList { 12 return &CESList{} 13 } 14 15 // CESHandler is implemented by event handlers responding to 16 // CiliumEndpointSlice events. 17 type CESHandler interface { 18 OnAdd(ces *cilium_v2a1.CiliumEndpointSlice) 19 OnUpdate(oldCES, newCES *cilium_v2a1.CiliumEndpointSlice) 20 OnDelete(ces *cilium_v2a1.CiliumEndpointSlice) 21 } 22 23 // Register registers the CES event handler as a subscriber. 24 func (l *CESList) Register(c CESHandler) { 25 l.Lock() 26 defer l.Unlock() 27 l.subs = append(l.subs, c) 28 } 29 30 // NotifyAdd notifies all the subscribers of an add event to an object. 31 func (l *CESList) NotifyAdd(ces *cilium_v2a1.CiliumEndpointSlice) { 32 l.RLock() 33 defer l.RUnlock() 34 for _, s := range l.subs { 35 s.OnAdd(ces) 36 } 37 } 38 39 // NotifyUpdate notifies all the subscribers of an update event to an object. 40 func (l *CESList) NotifyUpdate(oldCES, newCES *cilium_v2a1.CiliumEndpointSlice) { 41 l.RLock() 42 defer l.RUnlock() 43 for _, s := range l.subs { 44 s.OnUpdate(oldCES, newCES) 45 } 46 } 47 48 // NotifyDelete notifies all the subscribers of a delete event to an object. 49 func (l *CESList) NotifyDelete(ces *cilium_v2a1.CiliumEndpointSlice) { 50 l.RLock() 51 defer l.RUnlock() 52 for _, s := range l.subs { 53 s.OnDelete(ces) 54 } 55 } 56 57 // CESList holds the CES subscribers to any CiliumEndpointSlice resource / object changes in 58 // the K8s watchers. 59 type CESList struct { 60 list 61 subs []CESHandler 62 }