Skip to content

Commit

Permalink
Merge pull request #141 from moio/watchnames_propagate_errors
Browse files Browse the repository at this point in the history
WatchNames: return errors via WebSocket
  • Loading branch information
MbolotSuse authored Mar 1, 2024
2 parents 641178e + d138622 commit 7913f27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/stores/proxy/proxy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func (s *Store) WatchNames(apiOp *types.APIRequest, schema *types.APISchema, w t
} else {
logrus.Debugf("WatchNames received error: %v", item)
}
result <- item
continue
}

Expand Down
13 changes: 10 additions & 3 deletions pkg/stores/proxy/proxy_store_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package proxy

import (
"fmt"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -88,6 +88,7 @@ func receiveUntil(wc chan watch.Event, d time.Duration) error {
timer := time.NewTicker(d)
defer timer.Stop()
secretNames := []string{"testsecret1", "testsecret2"}
errMsgs := []string{"err1", "err2", "err3"}
for {
select {
case event, ok := <-wc:
Expand All @@ -96,7 +97,13 @@ func receiveUntil(wc chan watch.Event, d time.Duration) error {
}

if event.Type == watch.Error {
return errors.New(fmt.Sprintf("watch chan should not have sent events of type [%s]", watch.Error))
status, ok := event.Object.(*metav1.Status)
if !ok {
continue
}
if strings.HasSuffix(status.Message, errMsgs[0]) {
errMsgs = errMsgs[1:]
}
}
secret, ok := event.Object.(*v1.Secret)
if !ok {
Expand All @@ -105,7 +112,7 @@ func receiveUntil(wc chan watch.Event, d time.Duration) error {
if secret.Name == secretNames[0] {
secretNames = secretNames[1:]
}
if len(secretNames) == 0 {
if len(secretNames) == 0 && len(errMsgs) == 0 {
return nil
}
continue
Expand Down

0 comments on commit 7913f27

Please sign in to comment.