Skip to content

Commit

Permalink
renaiming and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Nov 8, 2023
1 parent 9dfe4ea commit 9f56023
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
37 changes: 22 additions & 15 deletions agent/xdsv2/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]prot
switch proxyStateCluster.Group.(type) {
case *pbproxystate.Cluster_FailoverGroup:
fg := proxyStateCluster.GetFailoverGroup()
clusters, eps, err := pr.makeEnvoyAggregateCluster(name, proxyStateCluster.Protocol, fg)
clusters, eps, err := pr.makeEnvoyAggregateClusterAndEndpoint(name, proxyStateCluster.Protocol, fg)
if err != nil {
return nil, nil, err
}
// for each cluster, add it to clusters map and add endpoint to endpoint map
for _, c := range clusters {
envoyClusters[c.Name] = c
if ep, ok := eps[c.Name]; ok {
Expand All @@ -43,10 +44,12 @@ func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]prot

case *pbproxystate.Cluster_EndpointGroup:
eg := proxyStateCluster.GetEndpointGroup()
cluster, eps, err := pr.makeEnvoyCluster(name, proxyStateCluster.Protocol, eg)
cluster, eps, err := pr.makeEnvoyClusterAndEndpoint(name, proxyStateCluster.Protocol, eg)
if err != nil {
return nil, nil, err
}

// for each cluster, add it to clusters map and add endpoint to endpoint map
envoyClusters[cluster.Name] = cluster
if ep, ok := eps[cluster.Name]; ok {
envoyEndpoints[cluster.Name] = ep
Expand All @@ -58,16 +61,16 @@ func (pr *ProxyResources) makeClustersAndEndpoints(name string) (map[string]prot
return envoyClusters, envoyEndpoints, nil
}

func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Protocol,
func (pr *ProxyResources) makeEnvoyClusterAndEndpoint(name string, protocol pbproxystate.Protocol,
eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) {
if eg != nil {
switch t := eg.Group.(type) {
case *pbproxystate.EndpointGroup_Dynamic:
dynamic := eg.GetDynamic()
return pr.makeEnvoyDynamicCluster(name, protocol, dynamic)
return pr.makeEnvoyDynamicClusterAndEndpoint(name, protocol, dynamic)
case *pbproxystate.EndpointGroup_Static:
static := eg.GetStatic()
return pr.makeEnvoyStaticCluster(name, protocol, static)
return pr.makeEnvoyStaticClusterAndEndpoint(name, protocol, static)
case *pbproxystate.EndpointGroup_Dns:
dns := eg.GetDns()
return pr.makeEnvoyDnsCluster(name, protocol, dns)
Expand All @@ -81,7 +84,7 @@ func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbproxystate.Pr
return nil, nil, fmt.Errorf("no endpoint group")
}

func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxystate.Protocol,
func (pr *ProxyResources) makeEnvoyDynamicClusterAndEndpoint(name string, protocol pbproxystate.Protocol,
dynamic *pbproxystate.DynamicEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) {
cluster := &envoy_cluster_v3.Cluster{
Name: name,
Expand Down Expand Up @@ -128,19 +131,18 @@ func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbproxys
cluster.TransportSocket = envoyTransportSocket
}

// Generate Envoy endpoint
endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment)
//if cluster.Name != xdscommon.LocalAppClusterName {
if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok {
protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints)
endpointResources[cluster.Name] = protoEndpoint
}
//}

return cluster, endpointResources, nil

}

func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol pbproxystate.Protocol,
func (pr *ProxyResources) makeEnvoyStaticClusterAndEndpoint(name string, protocol pbproxystate.Protocol,
static *pbproxystate.StaticEndpointGroup) (*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) {
cluster := &envoy_cluster_v3.Cluster{
Name: name,
Expand Down Expand Up @@ -197,26 +199,26 @@ func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol pbpr
return cluster, nil, nil
}

func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbproxystate.Protocol,
func (pr *ProxyResources) makeEnvoyAggregateClusterAndEndpoint(name string, protocol pbproxystate.Protocol,
fg *pbproxystate.FailoverGroup) (map[string]*envoy_cluster_v3.Cluster, map[string]*envoy_endpoint_v3.ClusterLoadAssignment, error) {
clusters := make(map[string]*envoy_cluster_v3.Cluster)
endpointResources := make(map[string]*envoy_endpoint_v3.ClusterLoadAssignment)
if fg != nil {
var egNames []string
for _, eg := range fg.EndpointGroups {
cluster, eps, err := pr.makeEnvoyCluster(eg.Name, protocol, eg)
cluster, eps, err := pr.makeEnvoyClusterAndEndpoint(eg.Name, protocol, eg)
if err != nil {
return nil, eps, err
}
egNames = append(egNames, cluster.Name)

// add failover cluster
clusters[cluster.Name] = cluster

//if endpointList, ok := pr.proxyState.Endpoints[cluster.Name]; ok {
// protoEndpoint := makeEnvoyClusterLoadAssignment(cluster.Name, endpointList.Endpoints)
// add endpoint for failover cluster
if ep, ok := eps[cluster.Name]; ok {
endpointResources[cluster.Name] = ep
}
//}
}
aggregateClusterConfig, err := anypb.New(&envoy_aggregate_cluster_v3.ClusterConfig{
Clusters: egNames,
Expand All @@ -226,6 +228,7 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox
return nil, nil, err
}

// create aggregate cluster
c := &envoy_cluster_v3.Cluster{
Name: name,
ConnectTimeout: fg.Config.ConnectTimeout,
Expand All @@ -244,7 +247,11 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbprox
if err != nil {
return nil, nil, err
}

// add aggregate cluster
clusters[c.Name] = c

// add endpoint for aggregate cluster
if endpointList, ok := pr.proxyState.Endpoints[c.Name]; ok {
protoEndpoint := makeEnvoyClusterLoadAssignment(c.Name, endpointList.Endpoints)
endpointResources[c.Name] = protoEndpoint
Expand Down Expand Up @@ -379,7 +386,7 @@ func addEnvoyLBToCluster(dynamicConfig *pbproxystate.DynamicEndpointGroupConfig,
return nil
}

func (pr *ProxyResources) makeEnvoyClusterFromL4Destination(l4 *pbproxystate.L4Destination) error {
func (pr *ProxyResources) makeEnvoyClustersAndEndpointsFromL4Destination(l4 *pbproxystate.L4Destination) error {
switch l4.Destination.(type) {
case *pbproxystate.L4Destination_Cluster:
pr.addEnvoyClustersAndEndpointsToEnvoyResources(l4.GetCluster().GetName())
Expand Down
2 changes: 1 addition & 1 deletion agent/xdsv2/listener_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (pr *ProxyResources) makeEnvoyResourcesForSNIDestination(sni *pbproxystate.
}

func (pr *ProxyResources) makeEnvoyResourcesForL4Destination(l4 *pbproxystate.Router_L4) ([]*envoy_listener_v3.Filter, error) {
err := pr.makeEnvoyClusterFromL4Destination(l4.L4)
err := pr.makeEnvoyClustersAndEndpointsFromL4Destination(l4.L4)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions agent/xdsv2/route_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func makeEnvoyQueryParamFromProxystateQueryMatch(psMatch *pbproxystate.QueryPara

func (pr *ProxyResources) addEnvoyClustersAndEndpointsToEnvoyResources(clusterName string) {
clusters, endpoints, _ := pr.makeClustersAndEndpoints(clusterName)

for name, cluster := range clusters {
pr.envoyResources[xdscommon.ClusterType][name] = cluster
}
Expand Down

0 comments on commit 9f56023

Please sign in to comment.