Skip to content

Commit

Permalink
fix: some status updates are discarded by the status updater (envoypr…
Browse files Browse the repository at this point in the history
…oxy#4337)

Signed-off-by: Huabing Zhao <[email protected]>
  • Loading branch information
zhaohuabing authored Sep 27, 2024
1 parent 9b161ee commit 14830c7
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions internal/provider/kubernetes/status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ func (m MutatorFunc) Mutate(old client.Object) client.Object {
type UpdateHandler struct {
log logr.Logger
client client.Client
sendUpdates chan struct{}
updateChannel chan Update
}

func NewUpdateHandler(log logr.Logger, client client.Client) *UpdateHandler {
return &UpdateHandler{
log: log,
client: client,
sendUpdates: make(chan struct{}),
updateChannel: make(chan Update, 100),
}
}
Expand Down Expand Up @@ -129,9 +127,6 @@ func (u *UpdateHandler) Start(ctx context.Context) error {
u.log.Info("started status update handler")
defer u.log.Info("stopped status update handler")

// Enable Updaters to start sending updates to this handler.
close(u.sendUpdates)

for {
select {
case <-ctx.Done():
Expand All @@ -148,7 +143,6 @@ func (u *UpdateHandler) Start(ctx context.Context) error {
// Writer retrieves the interface that should be used to write to the UpdateHandler.
func (u *UpdateHandler) Writer() Updater {
return &UpdateWriter{
enabled: u.sendUpdates,
updateChannel: u.updateChannel,
}
}
Expand All @@ -160,18 +154,13 @@ type Updater interface {

// UpdateWriter takes status updates and sends these to the UpdateHandler via a channel.
type UpdateWriter struct {
enabled <-chan struct{}
updateChannel chan<- Update
}

// Send sends the given Update off to the update channel for writing by the UpdateHandler.
func (u *UpdateWriter) Send(update Update) {
// Non-blocking receive to see if we should pass along update.
select {
case <-u.enabled:
u.updateChannel <- update
default:
}
u.updateChannel <- update
}

// isStatusEqual checks if two objects have equivalent status.
Expand Down

0 comments on commit 14830c7

Please sign in to comment.