-
Notifications
You must be signed in to change notification settings - Fork 419
/
istio_pools.go
62 lines (56 loc) · 2.65 KB
/
istio_pools.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// -------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// --------------------------------------------------------------------------------------------
package appgw
import (
"fmt"
n "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-03-01/network"
"github.com/Azure/go-autorest/autorest/to"
"k8s.io/klog/v2"
)
func (c *appGwConfigBuilder) getIstioBackendAddressPool(destinationID istioDestinationIdentifier, serviceBackendPair serviceBackendPortPair, addressPools map[string]*n.ApplicationGatewayBackendAddressPool) *n.ApplicationGatewayBackendAddressPool {
endpoints, err := c.k8sContext.GetEndpointsByService(destinationID.serviceKey())
if err != nil {
logLine := fmt.Sprintf("Failed fetching endpoints for service: %s", destinationID.serviceKey())
klog.Errorf(logLine)
//TODO(rhea): add recorder event for error
return nil
}
for _, subset := range endpoints.Subsets {
if _, portExists := getUniqueTCPPorts(subset)[serviceBackendPair.BackendPort]; portExists {
backendServicePort := ""
if destinationID.DestinationPort != 0 {
backendServicePort = fmt.Sprint(destinationID.DestinationPort)
} else {
// TODO(delqn): lookup port by name
}
poolName := generateAddressPoolName(destinationID.serviceFullName(), backendServicePort, serviceBackendPair.BackendPort)
if pool, ok := addressPools[poolName]; ok {
return pool
}
pool := c.newPool(poolName, subset)
pool.ID = to.StringPtr(c.appGwIdentifier.AddressPoolID(poolName))
return pool
}
logLine := fmt.Sprintf("Backend target port %d does not have matching endpoint port", serviceBackendPair.BackendPort)
klog.Error(logLine)
//TODO(rhea): add recorder event for error
}
return nil
}
func (c *appGwConfigBuilder) newIstioBackendPoolMap(cbCtx *ConfigBuilderContext) map[istioDestinationIdentifier]*n.ApplicationGatewayBackendAddressPool {
defaultPool := defaultBackendAddressPool(c.appGwIdentifier)
addressPools := map[string]*n.ApplicationGatewayBackendAddressPool{
*defaultPool.Name: &defaultPool,
}
backendPoolMap := make(map[istioDestinationIdentifier]*n.ApplicationGatewayBackendAddressPool)
_, _, istioServiceBackendPairMap, _ := c.getIstioDestinationsAndSettingsMap(cbCtx)
for destinationID, serviceBackendPair := range istioServiceBackendPairMap {
backendPoolMap[destinationID] = &defaultPool
if pool := c.getIstioBackendAddressPool(destinationID, serviceBackendPair, addressPools); pool != nil {
backendPoolMap[destinationID] = pool
}
}
return backendPoolMap
}