@@ -145,8 +145,7 @@ func (h *headerManger) getAPIServerRequestDestAddress(r *http.Request) (name, ip
145145 }
146146 name , err = h .getGatewayNodeName (& node )
147147 if err != nil {
148- return "" , "" , "" , fmt .Errorf ("gateway include node %s, has no active endpoints, error %s" ,
149- node .Name , err .Error ())
148+ return "" , "" , "" , fmt .Errorf ("can not find gateway node for node %s, error %s" , node .Name , err .Error ())
150149 }
151150 ip = getNodeIP (& node )
152151 if ip == "" {
@@ -180,8 +179,7 @@ func (h *headerManger) getNormalRequestDestAddress(r *http.Request) (name, ip, p
180179 }
181180 name , err = h .getGatewayNodeName (& node )
182181 if err != nil {
183- return "" , "" , "" , fmt .Errorf ("gateway include node %s, has no active endpoints, error %s" ,
184- node .Name , err .Error ())
182+ return "" , "" , "" , fmt .Errorf ("can not find gateway node for node %s, error %s" , node .Name , err .Error ())
185183 }
186184 ip = getNodeIP (& node )
187185 if ip == "" {
@@ -241,6 +239,15 @@ func (h *headerManger) getGatewayNodeName(node *v1.Node) (string, error) {
241239 }
242240 return "" , err
243241 }
244- rand .Seed (time .Now ().Unix ())
245- return gw .Status .ActiveEndpoints [rand .Intn (len (gw .Status .ActiveEndpoints ))].NodeName , nil
242+ if gw .Status .ActiveEndpoints == nil || len (gw .Status .ActiveEndpoints ) == 0 {
243+ return "" , fmt .Errorf ("no active endpoints for gateway %s" , gwName )
244+ }
245+ names := make ([]string , 0 )
246+ for _ , ep := range gw .Status .ActiveEndpoints {
247+ if ep .Type == v1beta1 .Proxy {
248+ names = append (names , ep .NodeName )
249+ }
250+ }
251+ rand .New (rand .NewSource (time .Now ().Unix ()))
252+ return names [rand .Intn (len (names ))], nil
246253}
0 commit comments