Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix: some status updates are discarded by the status updater (#…
Browse files Browse the repository at this point in the history
…4337)"

This reverts commit 14830c7.
zhaohuabing authored Nov 21, 2024
1 parent 78da42c commit 045b2af
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/provider/kubernetes/status_updater.go
Original file line number Diff line number Diff line change
@@ -56,13 +56,15 @@ 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),
}
}
@@ -127,6 +129,9 @@ 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():
@@ -143,6 +148,7 @@ 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,
}
}
@@ -154,13 +160,18 @@ 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.
u.updateChannel <- update
select {
case <-u.enabled:
u.updateChannel <- update
default:

Check warning on line 173 in internal/provider/kubernetes/status_updater.go

Codecov / codecov/patch

internal/provider/kubernetes/status_updater.go#L173

Added line #L173 was not covered by tests
}
}

// isStatusEqual checks if two objects have equivalent status.

0 comments on commit 045b2af

Please sign in to comment.