1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
1
18
package xds
2
19
3
20
import (
4
21
"encoding/json"
5
22
"fmt"
6
23
"io/ioutil"
7
24
"net/http"
8
- "os"
9
25
"strings"
10
26
"sync"
11
27
"time"
@@ -173,7 +189,7 @@ func NewXDSWrappedClient(podName, namespace, localIP string, istioAddr Addr) (*W
173
189
174
190
func (w * WrappedClient ) getServiceUniqueKeyHostAddrMapFromPilot () (map [string ]string , error ) {
175
191
req , _ := http .NewRequest (http .MethodGet , fmt .Sprintf ("http://%s:8080/debug/adsz" , w .istiodPodIP ), nil )
176
- token , err := os .ReadFile (istiodTokenPath )
192
+ token , err := ioutil .ReadFile (istiodTokenPath )
177
193
if err != nil {
178
194
return nil , err
179
195
}
@@ -229,12 +245,25 @@ func getHostNameAndPortFromAddr(hostAddr string) (string, string) {
229
245
return hostName , port
230
246
}
231
247
248
+ func (w * WrappedClient ) GetClusterUpdateIgnoreVersion (hostAddr string ) resource.ClusterUpdate {
249
+ hostName , port := getHostNameAndPortFromAddr (hostAddr )
250
+ w .cdsMapLock .RLock ()
251
+ defer w .cdsMapLock .Unlock ()
252
+ for clusterName , v := range w .cdsMap {
253
+ clusterNameData := strings .Split (clusterName , "|" )
254
+ if clusterNameData [1 ] == port && clusterNameData [3 ] == hostName {
255
+ return v
256
+ }
257
+ }
258
+ return resource.ClusterUpdate {}
259
+ }
260
+
232
261
func (w * WrappedClient ) getAllVersionClusterName (hostAddr string ) []string {
233
262
hostName , port := getHostNameAndPortFromAddr (hostAddr )
234
263
allVersionClusterNames := make ([]string , 0 )
235
264
w .cdsMapLock .RLock ()
236
265
defer w .cdsMapLock .Unlock ()
237
- for clusterName , _ := range w .cdsMap {
266
+ for clusterName := range w .cdsMap {
238
267
clusterNameData := strings .Split (clusterName , "|" )
239
268
if clusterNameData [1 ] == port && clusterNameData [3 ] == hostName {
240
269
allVersionClusterNames = append (allVersionClusterNames , clusterName )
@@ -296,7 +325,7 @@ func (w *WrappedClient) registerHostLevelSubscription(hostAddr, interfaceName, s
296
325
w .hostAddrClusterCtxMapLock .Unlock ()
297
326
298
327
oldlisteningClusterMap := make (map [string ]bool )
299
- for cluster , _ := range listeningClustersCancelMap {
328
+ for cluster := range listeningClustersCancelMap {
300
329
oldlisteningClusterMap [cluster ] = false
301
330
}
302
331
for _ , updatedClusterName := range updatedAllVersionedClusterName {
@@ -485,7 +514,7 @@ func (w *WrappedClient) initClientAndLoadLocalHostAddr() error {
485
514
// todo: what's going on? istiod can't discover istiod.istio-system.svc.cluster.local!!
486
515
if clusterNameList [3 ] == w .istiodAddr .HostnameOrIP {
487
516
// 1. find istiod podIP
488
- // todo: When would eds level watch be cancelled ?
517
+ // todo: When would eds level watch be canceled ?
489
518
cancel1 = xdsClient .WatchEndpoints (update .ClusterName , func (endpoint resource.EndpointsUpdate , err error ) {
490
519
if foundIstiod {
491
520
return
@@ -502,7 +531,7 @@ func (w *WrappedClient) initClientAndLoadLocalHostAddr() error {
502
531
return
503
532
}
504
533
// 2. found local hostAddr
505
- // todo: When would eds level watch be cancelled ?
534
+ // todo: When would eds level watch be canceled ?
506
535
cancel2 = xdsClient .WatchEndpoints (update .ClusterName , func (endpoint resource.EndpointsUpdate , err error ) {
507
536
if foundLocal {
508
537
return
@@ -580,7 +609,7 @@ func getDubboGoMetadata(dubboGoMetadata string) *structpb.Struct {
580
609
}
581
610
582
611
func (w * WrappedClient ) runWatchingResource () {
583
- for _ = range w .cdsUpdateEventChan {
612
+ for range w .cdsUpdateEventChan {
584
613
w .cdsUpdateEventHandlersLock .RLock ()
585
614
for _ , h := range w .cdsUpdateEventHandlers {
586
615
h ()
0 commit comments