diff --git a/internal/dataplane/config_status.go b/internal/dataplane/config_status.go index 9168456791..7ab50b1719 100644 --- a/internal/dataplane/config_status.go +++ b/internal/dataplane/config_status.go @@ -42,8 +42,8 @@ func (n *ChannelConfigNotifier) SubscribeConfigStatus() chan ConfigStatus { return n.ch } -func NewChannelConfigNotifier(ch chan ConfigStatus) *ChannelConfigNotifier { +func NewChannelConfigNotifier() *ChannelConfigNotifier { return &ChannelConfigNotifier{ - ch: ch, + ch: make(chan ConfigStatus, 1), } } diff --git a/internal/dataplane/kong_client.go b/internal/dataplane/kong_client.go index 2cbe108a0b..6fcbf9e017 100644 --- a/internal/dataplane/kong_client.go +++ b/internal/dataplane/kong_client.go @@ -537,7 +537,7 @@ func handleSendToClientResult(client sendconfig.KonnectAwareClient, logger logru return newSHA, nil } -// SetConfigStatusNotifier sets a notifier notifies configurations to subscribers +// SetConfigStatusNotifier sets a notifier which notifies subscribers about configuration sending results. // Currently it is used for uploading the node status to konnect runtime group. func (c *KongClient) SetConfigStatusNotifier(n ConfigStatusNotifier) { c.lock.Lock() diff --git a/internal/konnect/node_agent.go b/internal/konnect/node_agent.go index 6898f3a401..4318927f20 100644 --- a/internal/konnect/node_agent.go +++ b/internal/konnect/node_agent.go @@ -108,13 +108,15 @@ func (a *NodeAgent) clearOutdatedNodes() error { } func (a *NodeAgent) subscribeConfigStatus(ctx context.Context) { + ch := a.configStatusSubscriber.SubscribeConfigStatus() + chDone := ctx.Done() + for { select { - case <-ctx.Done(): - err := ctx.Err() - a.Logger.Info("subscribe loop stopped", "message", err.Error()) + case <-chDone: + a.Logger.Info("subscribe loop stopped", "message", ctx.Err().Error()) return - case configStatus := <-a.configStatusSubscriber.SubscribeConfigStatus(): + case configStatus := <-ch: a.configStatus.Store(uint32(configStatus)) } } diff --git a/internal/manager/run.go b/internal/manager/run.go index 613d1fe836..7147599239 100644 --- a/internal/manager/run.go +++ b/internal/manager/run.go @@ -200,8 +200,7 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic, d hostname, _ := os.Hostname() version := metadata.Release // set channel to send config status. - configStatusChan := make(chan dataplane.ConfigStatus, 1) - configStatusNotifier := dataplane.NewChannelConfigNotifier(configStatusChan) + configStatusNotifier := dataplane.NewChannelConfigNotifier() dataplaneClient.SetConfigStatusNotifier(configStatusNotifier) agent := konnect.NewNodeAgent(