@@ -34,10 +34,7 @@ import (
34
34
internalgrpclog "google.golang.org/grpc/internal/grpclog"
35
35
"google.golang.org/grpc/status"
36
36
"google.golang.org/grpc/xds/internal/xdsclient"
37
- "google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
38
- "google.golang.org/protobuf/types/known/timestamppb"
39
37
40
- v3adminpb "github.com/envoyproxy/go-control-plane/envoy/admin/v3"
41
38
v3statusgrpc "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
42
39
v3statuspb "github.com/envoyproxy/go-control-plane/envoy/service/status/v3"
43
40
)
@@ -77,7 +74,7 @@ func NewClientStatusDiscoveryServer() (*ClientStatusDiscoveryServer, error) {
77
74
return s , nil
78
75
}
79
76
80
- // StreamClientStatus implementations interface ClientStatusDiscoveryServiceServer.
77
+ // StreamClientStatus implements interface ClientStatusDiscoveryServiceServer.
81
78
func (s * ClientStatusDiscoveryServer ) StreamClientStatus (stream v3statusgrpc.ClientStatusDiscoveryService_StreamClientStatusServer ) error {
82
79
for {
83
80
req , err := stream .Recv ()
@@ -97,13 +94,13 @@ func (s *ClientStatusDiscoveryServer) StreamClientStatus(stream v3statusgrpc.Cli
97
94
}
98
95
}
99
96
100
- // FetchClientStatus implementations interface ClientStatusDiscoveryServiceServer.
97
+ // FetchClientStatus implements interface ClientStatusDiscoveryServiceServer.
101
98
func (s * ClientStatusDiscoveryServer ) FetchClientStatus (_ context.Context , req * v3statuspb.ClientStatusRequest ) (* v3statuspb.ClientStatusResponse , error ) {
102
99
return s .buildClientStatusRespForReq (req )
103
100
}
104
101
105
- // buildClientStatusRespForReq fetches the status from the client, and returns
106
- // the response to be sent back to xdsclient .
102
+ // buildClientStatusRespForReq fetches the status of xDS resources from the
103
+ // xdsclient, and returns the response to be sent back to the csds client .
107
104
//
108
105
// If it returns an error, the error is a status error.
109
106
func (s * ClientStatusDiscoveryServer ) buildClientStatusRespForReq (req * v3statuspb.ClientStatusRequest ) (* v3statuspb.ClientStatusResponse , error ) {
@@ -119,16 +116,7 @@ func (s *ClientStatusDiscoveryServer) buildClientStatusRespForReq(req *v3statusp
119
116
return nil , status .Errorf (codes .InvalidArgument , "node_matchers are not supported, request contains node_matchers: %v" , req .NodeMatchers )
120
117
}
121
118
122
- dump := s .xdsClient .DumpResources ()
123
- ret := & v3statuspb.ClientStatusResponse {
124
- Config : []* v3statuspb.ClientConfig {
125
- {
126
- Node : s .xdsClient .BootstrapConfig ().NodeProto ,
127
- GenericXdsConfigs : dumpToGenericXdsConfig (dump ),
128
- },
129
- },
130
- }
131
- return ret , nil
119
+ return s .xdsClient .DumpResources ()
132
120
}
133
121
134
122
// Close cleans up the resources.
@@ -137,45 +125,3 @@ func (s *ClientStatusDiscoveryServer) Close() {
137
125
s .xdsClientClose ()
138
126
}
139
127
}
140
-
141
- func dumpToGenericXdsConfig (dump map [string ]map [string ]xdsresource.UpdateWithMD ) []* v3statuspb.ClientConfig_GenericXdsConfig {
142
- var ret []* v3statuspb.ClientConfig_GenericXdsConfig
143
- for typeURL , updates := range dump {
144
- for name , update := range updates {
145
- config := & v3statuspb.ClientConfig_GenericXdsConfig {
146
- TypeUrl : typeURL ,
147
- Name : name ,
148
- VersionInfo : update .MD .Version ,
149
- XdsConfig : update .Raw ,
150
- LastUpdated : timestamppb .New (update .MD .Timestamp ),
151
- ClientStatus : serviceStatusToProto (update .MD .Status ),
152
- }
153
- if errState := update .MD .ErrState ; errState != nil {
154
- config .ErrorState = & v3adminpb.UpdateFailureState {
155
- LastUpdateAttempt : timestamppb .New (errState .Timestamp ),
156
- Details : errState .Err .Error (),
157
- VersionInfo : errState .Version ,
158
- }
159
- }
160
- ret = append (ret , config )
161
- }
162
- }
163
- return ret
164
- }
165
-
166
- func serviceStatusToProto (serviceStatus xdsresource.ServiceStatus ) v3adminpb.ClientResourceStatus {
167
- switch serviceStatus {
168
- case xdsresource .ServiceStatusUnknown :
169
- return v3adminpb .ClientResourceStatus_UNKNOWN
170
- case xdsresource .ServiceStatusRequested :
171
- return v3adminpb .ClientResourceStatus_REQUESTED
172
- case xdsresource .ServiceStatusNotExist :
173
- return v3adminpb .ClientResourceStatus_DOES_NOT_EXIST
174
- case xdsresource .ServiceStatusACKed :
175
- return v3adminpb .ClientResourceStatus_ACKED
176
- case xdsresource .ServiceStatusNACKed :
177
- return v3adminpb .ClientResourceStatus_NACKED
178
- default :
179
- return v3adminpb .ClientResourceStatus_UNKNOWN
180
- }
181
- }
0 commit comments