@@ -59,7 +59,9 @@ const (
59
59
type edsOptFunc func (* edsOpt )
60
60
61
61
type edsOpt struct {
62
- loadBalancingWeight uint32
62
+ loadBalancingWeight uint32
63
+ healthStatus corev3.HealthStatus
64
+ setInitialHealthStatus bool
63
65
}
64
66
65
67
func EdsLoadBalancingWeight (weight uint32 ) edsOptFunc {
@@ -68,6 +70,13 @@ func EdsLoadBalancingWeight(weight uint32) edsOptFunc {
68
70
}
69
71
}
70
72
73
+ func EdsLbEndpointHealthStatus (status corev3.HealthStatus ) edsOptFunc {
74
+ return func (opt * edsOpt ) {
75
+ opt .healthStatus = status
76
+ opt .setInitialHealthStatus = true
77
+ }
78
+ }
79
+
71
80
func initEdsOpt (opt * edsOpt ) {
72
81
if opt .loadBalancingWeight < 1 {
73
82
opt .loadBalancingWeight = defaultLoadBalancingWeight
@@ -110,13 +119,32 @@ func (e *endpointDiscoveryService) instanceEndpoint(instance EDSInstanceConfig)
110
119
}
111
120
112
121
func (e * endpointDiscoveryService ) lbEndpoints (instances []EDSInstanceConfig ) []* endpointv3.LbEndpoint {
122
+ if e .opt .setInitialHealthStatus {
123
+ return e .lbEndpointsWithInitialStatus (instances , e .opt .healthStatus )
124
+ }
125
+ return e .lbEndpointsDefault (instances )
126
+ }
127
+
128
+ func (e * endpointDiscoveryService ) lbEndpointsWithInitialStatus (instances []EDSInstanceConfig , status corev3.HealthStatus ) []* endpointv3.LbEndpoint {
129
+ endpoints := make ([]* endpointv3.LbEndpoint , len (instances ))
130
+ for idx , ins := range instances {
131
+ endpoints [idx ] = & endpointv3.LbEndpoint {
132
+ HostIdentifier : & endpointv3.LbEndpoint_Endpoint {
133
+ Endpoint : e .instanceEndpoint (ins ),
134
+ },
135
+ HealthStatus : status ,
136
+ }
137
+ }
138
+ return endpoints
139
+ }
140
+
141
+ func (e * endpointDiscoveryService ) lbEndpointsDefault (instances []EDSInstanceConfig ) []* endpointv3.LbEndpoint {
113
142
endpoints := make ([]* endpointv3.LbEndpoint , len (instances ))
114
143
for idx , ins := range instances {
115
144
endpoints [idx ] = & endpointv3.LbEndpoint {
116
145
HostIdentifier : & endpointv3.LbEndpoint_Endpoint {
117
146
Endpoint : e .instanceEndpoint (ins ),
118
147
},
119
- HealthStatus : corev3 .HealthStatus_UNHEALTHY , // initial status = unhealthy
120
148
}
121
149
}
122
150
return endpoints
0 commit comments