blob: 91ede4118f8e9b9b4c930afb2991b90f94c3ad5b [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xds
import (
clusterv3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
endpointv3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
envoy_resource "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
)
import (
"github.com/apache/dubbo-kubernetes/pkg/core/xds"
"github.com/apache/dubbo-kubernetes/pkg/xds/envoy/tags"
"github.com/apache/dubbo-kubernetes/pkg/xds/generator"
)
type EndpointMap map[xds.ServiceName][]*endpointv3.ClusterLoadAssignment
func GatherOutboundEndpoints(rs *xds.ResourceSet) EndpointMap {
return gatherEndpoints(rs, generator.OriginOutbound)
}
func gatherEndpoints(rs *xds.ResourceSet, origin string) EndpointMap {
em := EndpointMap{}
for _, res := range rs.Resources(envoy_resource.EndpointType) {
if res.Origin != origin {
continue
}
cla := res.Resource.(*endpointv3.ClusterLoadAssignment)
serviceName := tags.ServiceFromClusterName(cla.ClusterName)
em[serviceName] = append(em[serviceName], cla)
}
for _, res := range rs.Resources(envoy_resource.ClusterType) {
if res.Origin != origin {
continue
}
cluster := res.Resource.(*clusterv3.Cluster)
serviceName := tags.ServiceFromClusterName(cluster.Name)
if cluster.LoadAssignment != nil {
em[serviceName] = append(em[serviceName], cluster.LoadAssignment)
}
}
return em
}