New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
csds: return empty response if xds client is not set #4505
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ package csds | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"time" | ||
|
||
|
@@ -76,11 +75,12 @@ type ClientStatusDiscoveryServer struct { | |
func NewClientStatusDiscoveryServer() (*ClientStatusDiscoveryServer, error) { | ||
xdsC, err := newXDSClient() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create xds client: %v", err) | ||
logger.Warningf("failed to create xds client: %v", err) | ||
// Return an explicit nil here, otherwise the nil returned from | ||
// client.New() is a typed nil (type *Client, not the interface). | ||
return &ClientStatusDiscoveryServer{}, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me a long time to figure out what this comment means. Let's change it: // xdsC is a typed nil here, so we if we assign it to the xdsClient field, the
// nil checks in the handlers will not handle it properly. Or you could fix this by doing: newXDSClient = func() (xdsClientInterface, error) {
c, err := client.New()
if err != nil {
return nil, err
}
return c, nil
} Or slightly better: newXDSClient = func() xdsClientInterface {
c, err := client.New()
if err != nil {
logger.Warningf(...)
return nil
}
return c
} But ACTUALLY, why do we even have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to
Why is this better? If we add more things to |
||
} | ||
return &ClientStatusDiscoveryServer{ | ||
xdsClient: xdsC, | ||
}, nil | ||
return &ClientStatusDiscoveryServer{xdsClient: xdsC}, nil | ||
} | ||
|
||
// StreamClientStatus implementations interface ClientStatusDiscoveryServiceServer. | ||
|
@@ -113,6 +113,9 @@ func (s *ClientStatusDiscoveryServer) FetchClientStatus(_ context.Context, req * | |
// | ||
// If it returns an error, the error is a status error. | ||
func (s *ClientStatusDiscoveryServer) buildClientStatusRespForReq(req *v3statuspb.ClientStatusRequest) (*v3statuspb.ClientStatusResponse, error) { | ||
if s.xdsClient == nil { | ||
return &v3statuspb.ClientStatusResponse{}, nil | ||
} | ||
// Field NodeMatchers is unsupported, by design | ||
// https://github.com/grpc/proposal/blob/master/A40-csds-support.md#detail-node-matching. | ||
if len(req.NodeMatchers) != 0 { | ||
|
@@ -137,7 +140,9 @@ func (s *ClientStatusDiscoveryServer) buildClientStatusRespForReq(req *v3statusp | |
|
||
// Close cleans up the resources. | ||
func (s *ClientStatusDiscoveryServer) Close() { | ||
s.xdsClient.Close() | ||
if s.xdsClient != nil { | ||
s.xdsClient.Close() | ||
} | ||
} | ||
|
||
// nodeProtoToV3 converts the given proto into a v3.Node. n is from bootstrap | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above,
s/practise/practice/
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done