Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Commit e7a4ab0

Browse files
committed
Watcher: Correctly handle .Type==&"ERROR" watch events
If a watch sends back {"type":"ERROR","object":{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"too old resource version: 500000 (557576)","reason":"Gone","code":410}} instead of returning opaque errors from proto proto: wrong wireType = 6 for field ServiceAccountName it should return an APIError: kubernetes api: Failure 410 too old resource version: 500000 (557287)
1 parent 1b199c2 commit e7a4ab0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

watch.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ func (w *watcherJSON) Next(r Resource) (string, error) {
6363
if event.Type == "" {
6464
return "", errors.New("watch event had no type field")
6565
}
66+
if event.Type == EventError {
67+
status := &metav1.Status{}
68+
if err := json.Unmarshal([]byte(event.Object), status); err != nil {
69+
return "", fmt.Errorf("decoding event error: %v", err)
70+
}
71+
return event.Type, &APIError{
72+
Status: status,
73+
Code: int(*status.Code),
74+
}
75+
}
6676
if err := json.Unmarshal([]byte(event.Object), r); err != nil {
6777
return "", fmt.Errorf("decode resource: %v", err)
6878
}
@@ -85,6 +95,16 @@ func (w *watcherPB) Next(r Resource) (string, error) {
8595
if event.Type == nil || *event.Type == "" {
8696
return "", errors.New("watch event had no type field")
8797
}
98+
if *event.Type == EventError {
99+
status := &metav1.Status{}
100+
if err := proto.Unmarshal(unknown.Raw, status); err != nil {
101+
return "", fmt.Errorf("decoding event error: %v", err)
102+
}
103+
return *event.Type, &APIError{
104+
Status: status,
105+
Code: int(*status.Code),
106+
}
107+
}
88108
if err := proto.Unmarshal(unknown.Raw, msg); err != nil {
89109
return "", err
90110
}

0 commit comments

Comments
 (0)