From 9db5099396dca3d3d0441a6170fccb410404480b Mon Sep 17 00:00:00 2001 From: Yi Tao Date: Tue, 14 Feb 2023 15:38:21 +0800 Subject: [PATCH] fix notify status --- internal/dataplane/kong_client.go | 11 +++++++---- internal/konnect/node_agent.go | 3 ++- internal/manager/run.go | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/dataplane/kong_client.go b/internal/dataplane/kong_client.go index a2626a1f90..7554bf99c8 100644 --- a/internal/dataplane/kong_client.go +++ b/internal/dataplane/kong_client.go @@ -413,8 +413,11 @@ func (c *KongClient) Update(ctx context.Context) error { formatVersion = "3.0" } - configStatus := ConfigStatusOK - defer c.configStatusNotifier.NotifyConfigStatus(configStatus) + configStatus := new(ConfigStatus) + *configStatus = ConfigStatusOK + defer func(status *ConfigStatus) { + c.configStatusNotifier.NotifyConfigStatus(*status) + }(configStatus) // parse the Kubernetes objects from the storer into Kong configuration kongstate, translationFailures := p.Build() @@ -422,7 +425,7 @@ func (c *KongClient) Update(ctx context.Context) error { c.prometheusMetrics.RecordTranslationFailure() c.recordResourceFailureEvents(translationFailures, KongConfigurationTranslationFailedEventReason) c.logger.Debugf("%d translation failures have occurred when building data-plane configuration", failuresCount) - configStatus = ConfigStatusTranslationErrorHappened + *configStatus = ConfigStatusTranslationErrorHappened } else { c.prometheusMetrics.RecordTranslationSuccess() c.logger.Debug("successfully built data-plane configuration") @@ -430,7 +433,7 @@ func (c *KongClient) Update(ctx context.Context) error { shas, err := c.sendOutToClients(ctx, kongstate, formatVersion, c.kongConfig) if err != nil { - configStatus = ConfigStatusApplyFailed + *configStatus = ConfigStatusApplyFailed return err } diff --git a/internal/konnect/node_agent.go b/internal/konnect/node_agent.go index aeb61f4307..163ca56aff 100644 --- a/internal/konnect/node_agent.go +++ b/internal/konnect/node_agent.go @@ -17,6 +17,7 @@ const ( NodeOutdateInterval = 5 * time.Minute ) +// ConfigStatusSubscriber subscribes status of configuring kong. // REVIEW: define the subscriber here, or internal/adminapi for common usage? type ConfigStatusSubscriber interface { Subscribe() chan dataplane.ConfigStatus @@ -110,7 +111,7 @@ func (a *NodeAgent) clearOutdatedNodes() error { // nodes to remove: // (1) since only one KIC node is allowed in a runtime group, all the nodes with other hostnames are considered outdated. // (2) in some cases(kind/minikube restart), rebuilt pod uses the same name. So nodes updated for >5mins before should be deleted. - if node.Hostname != a.Hostname || time.Now().Sub(time.Unix(node.UpdatedAt, 0)) > NodeOutdateInterval { + if node.Hostname != a.Hostname || time.Since(time.Unix(node.UpdatedAt, 0)) > NodeOutdateInterval { deleteNode = true } } diff --git a/internal/manager/run.go b/internal/manager/run.go index f9109abf30..8229bd02d4 100644 --- a/internal/manager/run.go +++ b/internal/manager/run.go @@ -211,7 +211,8 @@ func Run(ctx context.Context, c *Config, diagnostic util.ConfigDumpDiagnostic, d c.Konnect.RefreshNodePeriod, setupLog, konnectNodeAPIClient, - configStatusSubscriber) + configStatusSubscriber, + ) agent.Run(ctx) } }