@@ -2,15 +2,14 @@ package clusters
22
33import (
44 "context"
5- "github.com/gogo/protobuf/proto"
65 "github.com/admiral/admiral/pkg/apis/admiral/v1"
76 "github.com/admiral/admiral/pkg/controller/admiral"
87 "github.com/admiral/admiral/pkg/controller/common"
98 "github.com/admiral/admiral/pkg/controller/istio"
109 "github.com/admiral/admiral/pkg/controller/secret"
1110 "github.com/admiral/admiral/pkg/controller/util"
11+ "github.com/gogo/protobuf/proto"
1212 "k8s.io/client-go/rest"
13- "strconv"
1413 "strings"
1514 "time"
1615
@@ -20,8 +19,8 @@ import (
2019 "sync"
2120
2221 istioModel "istio.io/istio/pilot/pkg/model"
23- k8sV1 "k8s.io/api/core/v1"
2422 k8sAppsV1 "k8s.io/api/apps/v1"
23+ k8sV1 "k8s.io/api/core/v1"
2524 k8s "k8s.io/client-go/kubernetes"
2625
2726 networking "istio.io/api/networking/v1alpha3"
@@ -476,7 +475,7 @@ func createServiceEntryForNewServiceOrPod(namespace string, sourceIdentity strin
476475 for sourceCluster , serviceInstance := range sourceServices {
477476 localFqdn := serviceInstance .Name + common .Sep + serviceInstance .Namespace + common .DotLocalDomainSuffix
478477 rc := remoteRegistry .remoteControllers [sourceCluster ]
479- var meshPorts = getMeshPorts (sourceCluster , serviceInstance , sourceDeployments [sourceCluster ])
478+ var meshPorts = GetMeshPorts (sourceCluster , serviceInstance , sourceDeployments [sourceCluster ])
480479 for key , serviceEntry := range serviceEntries {
481480 for _ , ep := range serviceEntry .Endpoints {
482481 clusterIngress := rc .ServiceController .Cache .GetLoadBalancer (admiral .IstioIngressServiceName , common .NamespaceIstioSystem )
@@ -511,6 +510,7 @@ func createServiceEntryForNewServiceOrPod(namespace string, sourceIdentity strin
511510 }
512511}
513512
513+
514514func getServiceForDeployment (rc * RemoteController , deployment * k8sAppsV1.Deployment , namespace string ) * k8sV1.Service {
515515
516516 cachedService := rc .ServiceController .Cache .Get (namespace )
@@ -530,7 +530,7 @@ func getServiceForDeployment(rc *RemoteController, deployment *k8sAppsV1.Deploym
530530 }
531531 //make sure the service matches the deployment Selector and also has a mesh port in the port spec
532532 if match {
533- ports := getMeshPorts (rc .ClusterID , service , deployment )
533+ ports := GetMeshPorts (rc .ClusterID , service , deployment )
534534 if len (ports ) > 0 {
535535 matchedService = service
536536 break
@@ -540,35 +540,6 @@ func getServiceForDeployment(rc *RemoteController, deployment *k8sAppsV1.Deploym
540540 return matchedService
541541}
542542
543- func getMeshPorts (clusterName string , destService * k8sV1.Service ,
544- destDeployment * k8sAppsV1.Deployment ) map [string ]uint32 {
545- var ports = make (map [string ]uint32 )
546- var meshPorts = destDeployment .Spec .Template .Annotations [common .SidecarEnabledPorts ]
547- if len (meshPorts ) == 0 {
548- log .Infof (LogFormat , "GetMeshPorts" , "service" , destService .Name , clusterName , "No mesh ports present, defaulting to first port" )
549- //TODO default to 8090 instead if the first port?
550- ports [destService .Spec .Ports [0 ].Name ] = uint32 (destService .Spec .Ports [0 ].Port )
551- return ports
552- }
553-
554- meshPortsSplit := strings .Split (meshPorts , "," )
555- var meshPortMap = make (map [uint32 ]uint32 )
556- for _ , meshPort := range meshPortsSplit {
557- port , err := strconv .ParseUint (meshPort , 10 , 32 )
558- if err != nil {
559- continue
560- }
561- meshPortMap [uint32 (port )] = uint32 (port )
562- }
563- for _ , servicePort := range destService .Spec .Ports {
564- if _ , ok := meshPortMap [uint32 (servicePort .Port )]; ok {
565- log .Debugf (LogFormat , "GetMeshPorts" , servicePort .Port , destService .Name , clusterName , "Adding mesh port" )
566- ports [common .Http ] = uint32 (servicePort .Port )
567- }
568- }
569- return ports
570- }
571-
572543func getDependentClusters (dependents * common.Map , identityClusterCache * common.MapOfMaps , sourceServices map [string ]* k8sV1.Service ) map [string ]string {
573544 var dependentClusters = make (map [string ]string )
574545 //TODO optimize this map construction
0 commit comments