Skip to content

Commit

Permalink
fix notify status
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Feb 14, 2023
1 parent 7c88a66 commit 9db5099
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,24 +413,27 @@ 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()
if failuresCount := len(translationFailures); failuresCount > 0 {
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")
}

shas, err := c.sendOutToClients(ctx, kongstate, formatVersion, c.kongConfig)
if err != nil {
configStatus = ConfigStatusApplyFailed
*configStatus = ConfigStatusApplyFailed
return err
}

Expand Down
3 changes: 2 additions & 1 deletion internal/konnect/node_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/manager/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 9db5099

Please sign in to comment.