diff --git a/internal/config/config.go b/internal/config/config.go index f8dd1bb..6a5af2d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -80,8 +80,8 @@ func Get() Config { v.MustBindEnv("podmetadata.nodename", "NODE_NAME") v.MustBindEnv("podmetadata.podname", "POD_NAME") - v.MustBindEnv("keepalive", "KEEP_ALIVE") - v.MustBindEnv("keepalivetimeout", "KEEP_ALIVE_TIMEOUT") + _ = v.BindEnv("keepalive", "KEEP_ALIVE") + _ = v.BindEnv("keepalivetimeout", "KEEP_ALIVE_TIMEOUT") _ = v.BindEnv("log.level", "LOG_LEVEL") diff --git a/internal/proxy/client.go b/internal/proxy/client.go index d4c5bb7..2309028 100644 --- a/internal/proxy/client.go +++ b/internal/proxy/client.go @@ -165,11 +165,10 @@ func (c *Client) run(ctx context.Context, stream cloudproxyv1alpha.CloudProxyAPI case <-ctx.Done(): return ctx.Err() case <-stream.Context().Done(): - return fmt.Errorf("stream closed") + return fmt.Errorf("stream closed %w", stream.Context().Err()) case <-time.After(time.Duration(c.keepAlive.Load())): if !c.isAlive() { - if c.lastSeenError.Load() != nil { - err := c.lastSeenError.Load() + if err := c.lastSeenError.Load(); err != nil { return fmt.Errorf("recived error: %w", *err) } return fmt.Errorf("last seen too old, closing stream") diff --git a/internal/proxy/client_test.go b/internal/proxy/client_test.go index 20ecdd3..0a1c446 100644 --- a/internal/proxy/client_test.go +++ b/internal/proxy/client_test.go @@ -447,6 +447,21 @@ func TestClient_run(t *testing.T) { wantLastSeenUpdated: true, wantErr: true, }, + { + name: "stream not alive", + args: args{ + ctx: func() context.Context { + return context.Background() + }, + tuneMockStream: func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient) { + m.EXPECT().Send(gomock.Any()).Return(nil).AnyTimes() // expected 0 or 1 times + m.EXPECT().Context().Return(context.Background()).AnyTimes() // expected 0 or 1 times + m.EXPECT().Recv().Return(nil, fmt.Errorf("test error")) + }, + }, + wantLastSeenUpdated: false, + wantErr: true, + }, } for _, tt := range tests { tt := tt @@ -455,7 +470,7 @@ func TestClient_run(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() - c := New(nil, nil, logrus.New(), "clusterID", "version", time.Second, time.Minute) + c := New(nil, nil, logrus.New(), "clusterID", "version", time.Second, time.Second) stream := mock_proxy.NewMockCloudProxyAPI_StreamCloudProxyClient(ctrl) if tt.args.tuneMockStream != nil { tt.args.tuneMockStream(stream)