[REV] change init-probe and add healthy check for endpoint host in xds

This commit is contained in:
barnett 2019-03-14 20:46:52 +08:00
parent 962140db1c
commit 380f5430f5
2 changed files with 19 additions and 2 deletions

View File

@ -30,6 +30,7 @@ import (
"google.golang.org/grpc"
v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2"
endpointapi "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint"
envoyv2 "github.com/goodrain/rainbond/node/core/envoy/v2"
"github.com/Sirupsen/logrus"
@ -132,7 +133,12 @@ func (d *DependServiceHealthController) checkEDS() bool {
readyLength := 0
for _, endpoint := range endpoints {
if len(endpoint.Endpoints) > 0 && len(endpoint.Endpoints[0].LbEndpoints) > 0 {
readyLength++
//first LbEndpoints healthy is not nil. so endpoint is not notreadyaddress
if host, ok := endpoint.Endpoints[0].LbEndpoints[0].HostIdentifier.(*endpointapi.LbEndpoint_Endpoint); ok {
if host.Endpoint != nil && host.Endpoint.HealthCheckConfig != nil {
readyLength++
}
}
}
}
if readyLength >= d.dependServiceCount {

View File

@ -63,16 +63,27 @@ func OneNodeClusterLoadAssignment(serviceAlias, namespace string, endpoints []*c
}
protocol := string(subset.Ports[0].Protocol)
addressList := subset.Addresses
var notready bool
if len(addressList) == 0 {
notready = true
addressList = subset.NotReadyAddresses
}
getHealty := func() *endpoint.Endpoint_HealthCheckConfig {
if notready {
return nil
}
return &endpoint.Endpoint_HealthCheckConfig{
PortValue: uint32(toport),
}
}
var lbe []endpoint.LbEndpoint
for _, address := range addressList {
envoyAddress := envoyv2.CreateSocketAddress(protocol, address.IP, uint32(toport))
lbe = append(lbe, endpoint.LbEndpoint{
HostIdentifier: &endpoint.LbEndpoint_Endpoint{
Endpoint: &endpoint.Endpoint{
Address: &envoyAddress,
Address: &envoyAddress,
HealthCheckConfig: getHealty(),
},
},
})