dubbo.apache.org/dubbo-go/v3@v3.1.1/remoting/xds/xds_client_factory.go (about)

     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  
    18  package xds
    19  
    20  import (
    21  	v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
    22  
    23  	"google.golang.org/grpc"
    24  	"google.golang.org/grpc/credentials/insecure"
    25  )
    26  
    27  import (
    28  	xdsCommon "dubbo.apache.org/dubbo-go/v3/remoting/xds/common"
    29  	"dubbo.apache.org/dubbo-go/v3/remoting/xds/mapping"
    30  	"dubbo.apache.org/dubbo-go/v3/xds/client"
    31  	"dubbo.apache.org/dubbo-go/v3/xds/client/bootstrap"
    32  	"dubbo.apache.org/dubbo-go/v3/xds/client/resource/version"
    33  )
    34  
    35  // xdsClientFactoryFunction generates new xds client
    36  // when running ut, it's for for ut to replace
    37  var xdsClientFactoryFunction = func(localIP, podName, namespace string, istioAddr xdsCommon.HostAddr) (client.XDSClient, error) {
    38  	// todo fix these ugly magic num
    39  	v3NodeProto := &v3corepb.Node{
    40  		Id:                   "sidecar~" + localIP + "~" + podName + "." + namespace + "~" + namespace + ".svc.cluster.local",
    41  		UserAgentName:        gRPCUserAgentName,
    42  		UserAgentVersionType: &v3corepb.Node_UserAgentVersion{UserAgentVersion: "1.45.0"},
    43  		ClientFeatures:       []string{clientFeatureNoOverprovisioning},
    44  		Metadata:             mapping.GetDubboGoMetadata(""),
    45  	}
    46  
    47  	nonNilCredsConfigV2 := &bootstrap.Config{
    48  		XDSServer: &bootstrap.ServerConfig{
    49  			ServerURI:    istioAddr.String(),
    50  			Creds:        grpc.WithTransportCredentials(insecure.NewCredentials()),
    51  			TransportAPI: version.TransportV3,
    52  			NodeProto:    v3NodeProto,
    53  		},
    54  		ClientDefaultListenerResourceNameTemplate: "%s",
    55  	}
    56  
    57  	newClient, err := client.NewWithConfig(nonNilCredsConfigV2)
    58  	if err != nil {
    59  		return nil, err
    60  	}
    61  	return newClient, nil
    62  }