@@ -16,36 +16,42 @@ import (
1616)
1717
1818type ConfigMapWatcher struct {
19- client kubernetes.Interface
19+ clients [] kubernetes.Interface
2020 namespace string
2121 selector fields.Selector
2222 configs chan provider.EgressConfig
2323}
2424
25- func NewConfigMapWatcher (client kubernetes.Interface , namespace , selectorStr string , configs chan provider.EgressConfig ) (* ConfigMapWatcher , error ) {
25+ func NewConfigMapWatcher (clients [] kubernetes.Interface , namespace , selectorStr string , configs chan provider.EgressConfig ) (* ConfigMapWatcher , error ) {
2626 selector , err := fields .ParseSelector (selectorStr )
2727 if err != nil {
2828 return nil , err
2929 }
3030
3131 return & ConfigMapWatcher {
32- client : client ,
32+ clients : clients ,
3333 namespace : namespace ,
3434 selector : selector ,
3535 configs : configs ,
3636 }, nil
3737}
3838
3939func (c * ConfigMapWatcher ) Run (ctx context.Context ) {
40+ for _ , client := range c .clients {
41+ c .runForClient (ctx , client )
42+ }
43+ }
44+
45+ func (c * ConfigMapWatcher ) runForClient (ctx context.Context , client kubernetes.Interface ) {
4046 informer := cache .NewSharedIndexInformer (
4147 & cache.ListWatch {
4248 ListFunc : func (options metav1.ListOptions ) (runtime.Object , error ) {
4349 options .LabelSelector = c .selector .String ()
44- return c . client .CoreV1 ().ConfigMaps (c .namespace ).List (ctx , options )
50+ return client .CoreV1 ().ConfigMaps (c .namespace ).List (ctx , options )
4551 },
4652 WatchFunc : func (options metav1.ListOptions ) (watch.Interface , error ) {
4753 options .LabelSelector = c .selector .String ()
48- return c . client .CoreV1 ().ConfigMaps (c .namespace ).Watch (ctx , options )
54+ return client .CoreV1 ().ConfigMaps (c .namespace ).Watch (ctx , options )
4955 },
5056 },
5157 & v1.ConfigMap {},
@@ -105,11 +111,23 @@ func (c *ConfigMapWatcher) del(obj interface{}) {
105111}
106112
107113func (c * ConfigMapWatcher ) ListConfigs (ctx context.Context ) ([]provider.EgressConfig , error ) {
114+ egressConfigs := []provider.EgressConfig {}
115+ for _ , client := range c .clients {
116+ configs , err := c .listConfigsForClient (ctx , client )
117+ if err != nil {
118+ return nil , err
119+ }
120+ egressConfigs = append (egressConfigs , configs ... )
121+ }
122+ return egressConfigs , nil
123+ }
124+
125+ func (c * ConfigMapWatcher ) listConfigsForClient (ctx context.Context , client kubernetes.Interface ) ([]provider.EgressConfig , error ) {
108126 opts := metav1.ListOptions {
109127 LabelSelector : c .selector .String (),
110128 }
111129
112- configMaps , err := c . client .CoreV1 ().ConfigMaps (c .namespace ).List (ctx , opts )
130+ configMaps , err := client .CoreV1 ().ConfigMaps (c .namespace ).List (ctx , opts )
113131 if err != nil {
114132 return nil , err
115133 }
0 commit comments