A Go-based tool for monitoring Kubernetes resources and handling watch events, including error recovery for scenarios like GOAWAY errors and resource version expiration.
- Watches Kubernetes pods for
ADDED,MODIFIED,DELETED, andERRORevents. - Handles common watch errors (e.g.,
GOAWAY, resource version expiration). - Configurable timeout for detecting stuck watches.
- Go 1.22+
- Kubernetes cluster access (configured via
kubeconfig).
- Clone the repository:
git clone <repository-url> cd k8s-watch-go
- Install dependencies:
go mod download
Run the tool with default settings:
GODEBUG=http2debug=2 go run watch-client.go --kubeconfig=/path/to/kubeconfig [--namespace=your-namespace] 2>&1 | tee http2-debug.log- Timeout: Adjust the watch timeout in
goaway-test.go(default:3m). - Logging: Modify log output format or level as needed.
The tool automatically recovers from:
GOAWAYerrors (server-initiated connection closure).- Resource version expiration (stale watches).
Monitor 1hour, found some GOAWAY related logs,
$ grep GOAWAY http2-debug.log
2025/07/31 12:42:23 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:45:08 http2: Framer 0xc0000f0000: read GOAWAY len=8 LastStreamID=1 ErrCode=NO_ERROR Debug=""
2025/07/31 12:45:08 http2: Transport received GOAWAY len=8 LastStreamID=1 ErrCode=NO_ERROR Debug=""
2025/07/31 12:45:10 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:47:23 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:50:32 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:52:42 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:54:25 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:56:26 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 12:58:25 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:00:07 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:08:10 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:11:13 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:13:48 http2: Framer 0xc000346000: read GOAWAY len=8 LastStreamID=1 ErrCode=NO_ERROR Debug=""
2025/07/31 13:13:48 http2: Transport received GOAWAY len=8 LastStreamID=1 ErrCode=NO_ERROR Debug=""
2025/07/31 13:20:53 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:29:41 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:38:31 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:41:20 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:42:44 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:44:47 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...
2025/07/31 13:48:45 Watch channel closed. Possibly due to GOAWAY or timeout. Reconnecting...Pull requests are welcome. For major changes, open an issue first.