11package adaptor
22
33import (
4+ "context"
45 "fmt"
56 "log/slog"
67 "os"
78
89 corev1 "k8s.io/api/core/v1"
10+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+ "k8s.io/client-go/kubernetes"
12+ "k8s.io/client-go/util/retry"
913
1014 internalclient "github.com/skupperproject/skupper/internal/kube/client"
1115 "github.com/skupperproject/skupper/internal/kube/secrets"
@@ -14,8 +18,10 @@ import (
1418)
1519
1620// Syncs the live router config with the configmap (bridge configuration,
17- // secrets for services with TLS enabled, and secrets and connectors for links)
21+ // secrets for services with TLS enabled, and secrets and connectors for links
22+ // as well as proxy profiles)
1823type ConfigSync struct {
24+ cli internalclient.Clients
1925 agentPool * qdr.AgentPool
2026 controller * watchers.EventProcessor
2127 namespace string
@@ -37,6 +43,7 @@ func sslSecretsWatcher(namespace string, eventProcessor *watchers.EventProcessor
3743func NewConfigSync (cli internalclient.Clients , namespace string , path string , routerConfigMap string , metrics watchers.MetricsProvider ) * ConfigSync {
3844 controller := watchers .NewEventProcessor ("config-sync" , cli , watchers .WithMetricsProvider (metrics ))
3945 configSync := & ConfigSync {
46+ cli : cli ,
4047 agentPool : qdr .NewAgentPool ("amqp://localhost:5672" , nil ),
4148 controller : controller ,
4249 namespace : namespace ,
@@ -88,6 +95,26 @@ func (c *ConfigSync) key(name string) string {
8895 return fmt .Sprintf ("%s/%s" , c .namespace , name )
8996}
9097
98+ func UpdateRouterConfig (client kubernetes.Interface , ctxt context.Context , update * qdr.RouterConfig , configmap * corev1.ConfigMap ) error {
99+ return retry .RetryOnConflict (retry .DefaultRetry , func () error {
100+ return updateRouterConfig (client , ctxt , update , configmap )
101+ })
102+ }
103+
104+ func updateRouterConfig (client kubernetes.Interface , ctxt context.Context , update * qdr.RouterConfig , configmap * corev1.ConfigMap ) error {
105+
106+ err := update .WriteToConfigMap (configmap )
107+ if err != nil {
108+ return err
109+ }
110+
111+ _ , err = client .CoreV1 ().ConfigMaps (configmap .Namespace ).Update (ctxt , configmap , metav1.UpdateOptions {})
112+ if err != nil {
113+ return err
114+ }
115+ return nil
116+ }
117+
91118func (c * ConfigSync ) configEvent (key string , configmap * corev1.ConfigMap ) error {
92119 if configmap == nil {
93120 return nil
@@ -102,6 +129,18 @@ func (c *ConfigSync) configEvent(key string, configmap *corev1.ConfigMap) error
102129 if err := c .syncSslProfilesToRouter (desired .SslProfiles ); err != nil {
103130 return err
104131 }
132+ // Note: change to a proxy secret is one case where a non-skupper resource
133+ // requires update to the router config and config map
134+ proxyUpdates , err := c .syncProxyProfileCredentialsToDisk (key , desired .ProxyProfiles )
135+ if err != nil {
136+ return err
137+ } else {
138+ for _ , update := range proxyUpdates {
139+ if _ , ok := desired .ProxyProfiles [update .Name ]; ok {
140+ desired .ProxyProfiles [update .Name ] = update
141+ }
142+ }
143+ }
105144 if err := c .syncProxyProfilesToRouter (desired .ProxyProfiles ); err != nil {
106145 return err
107146 }
@@ -113,6 +152,13 @@ func (c *ConfigSync) configEvent(key string, configmap *corev1.ConfigMap) error
113152 c .logger .Error ("sync failed" , slog .Any ("error" , err ))
114153 return err
115154 }
155+ if len (proxyUpdates ) > 0 {
156+ err := UpdateRouterConfig (c .cli .GetKubeClient (), context .TODO (), desired , configmap )
157+ if err != nil {
158+ return err
159+ }
160+ }
161+
116162 return nil
117163}
118164
@@ -222,6 +268,7 @@ func (c *ConfigSync) syncSslProfilesToRouter(desired map[string]qdr.SslProfile)
222268 if err := agent .CreateSslProfile (profile ); err != nil {
223269 return err
224270 }
271+ continue
225272 }
226273 if current != profile {
227274 if err := agent .UpdateSslProfile (profile ); err != nil {
@@ -240,7 +287,7 @@ func (c *ConfigSync) syncSslProfilesToRouter(desired map[string]qdr.SslProfile)
240287}
241288
242289func (c * ConfigSync ) syncSslProfileCredentialsToDisk (profiles map [string ]qdr.SslProfile ) error {
243- delta := c .profileSyncer .Expect (profiles )
290+ delta := c .profileSyncer .ExpectSslProfiles (profiles )
244291 return delta .Error ()
245292}
246293
@@ -261,6 +308,7 @@ func (c *ConfigSync) syncProxyProfilesToRouter(desired map[string]qdr.ProxyProfi
261308 if err := agent .CreateProxyProfile (profile ); err != nil {
262309 return err
263310 }
311+ continue
264312 }
265313 if current != profile {
266314 if err := agent .UpdateProxyProfile (profile ); err != nil {
@@ -278,6 +326,11 @@ func (c *ConfigSync) syncProxyProfilesToRouter(desired map[string]qdr.ProxyProfi
278326 return nil
279327}
280328
329+ func (c * ConfigSync ) syncProxyProfileCredentialsToDisk (key string , profiles map [string ]qdr.ProxyProfile ) (map [string ]qdr.ProxyProfile , error ) {
330+ delta := c .profileSyncer .ExpectProxyProfiles (key , profiles )
331+ return delta .ProxyUpdates , delta .Error ()
332+ }
333+
281334func (c * ConfigSync ) recoverTracking () error {
282335 configmap , err := c .config .Get (c .key (c .routerConfigMap ))
283336 if err != nil {
0 commit comments