constellation/cli/internal/azure/loadbalancer.go

287 lines
11 KiB
Go
Raw Normal View History

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
2022-05-24 04:04:42 -04:00
package azure
import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork"
"github.com/edgelesssys/constellation/internal/constants"
)
// LoadBalancer defines a Azure load balancer.
type LoadBalancer struct {
Name string
Subscription string
ResourceGroup string
Location string
PublicIPID string
UID string
}
const (
BackendAddressPoolWorkerName = "backendAddressWorkerPool"
BackendAddressPoolControlPlaneName = "backendAddressControlPlanePool"
frontEndIPConfigName = "frontEndIPConfig"
kubeHealthProbeName = "kubeHealthProbe"
verifyHealthProbeName = "verifyHealthProbe"
coordHealthProbeName = "coordHealthProbe"
debugdHealthProbeName = "debugdHealthProbe"
2022-08-31 21:40:29 -04:00
konnectivityHealthProbeName = "konnectivityHealthProbe"
2022-05-24 04:04:42 -04:00
)
// Azure returns a Azure representation of LoadBalancer.
func (l LoadBalancer) Azure() armnetwork.LoadBalancer {
backEndAddressPoolNodeName := BackendAddressPoolWorkerName + "-" + l.UID
backEndAddressPoolControlPlaneName := BackendAddressPoolControlPlaneName + "-" + l.UID
return armnetwork.LoadBalancer{
Name: to.Ptr(l.Name),
Location: to.Ptr(l.Location),
SKU: &armnetwork.LoadBalancerSKU{Name: to.Ptr(armnetwork.LoadBalancerSKUNameStandard)},
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.LoadBalancerPropertiesFormat{
FrontendIPConfigurations: []*armnetwork.FrontendIPConfiguration{
{
Name: to.Ptr(frontEndIPConfigName),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.FrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &armnetwork.PublicIPAddress{
ID: to.Ptr(l.PublicIPID),
2022-05-24 04:04:42 -04:00
},
},
},
},
BackendAddressPools: []*armnetwork.BackendAddressPool{
2022-08-29 05:55:46 -04:00
{Name: to.Ptr(backEndAddressPoolNodeName)},
{Name: to.Ptr(backEndAddressPoolControlPlaneName)},
{Name: to.Ptr("all")},
2022-05-24 04:04:42 -04:00
},
Probes: []*armnetwork.Probe{
{
Name: to.Ptr(kubeHealthProbeName),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.ProbePropertiesFormat{
Protocol: to.Ptr(armnetwork.ProbeProtocolTCP),
2022-08-01 10:51:34 -04:00
Port: to.Ptr(int32(constants.KubernetesPort)),
2022-05-24 04:04:42 -04:00
},
},
{
Name: to.Ptr(verifyHealthProbeName),
Properties: &armnetwork.ProbePropertiesFormat{
Protocol: to.Ptr(armnetwork.ProbeProtocolTCP),
Port: to.Ptr[int32](constants.VerifyServiceNodePortGRPC),
},
},
2022-05-24 04:04:42 -04:00
{
Name: to.Ptr(coordHealthProbeName),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.ProbePropertiesFormat{
Protocol: to.Ptr(armnetwork.ProbeProtocolTCP),
Port: to.Ptr[int32](constants.BootstrapperPort),
2022-05-24 04:04:42 -04:00
},
},
{
Name: to.Ptr(debugdHealthProbeName),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.ProbePropertiesFormat{
Protocol: to.Ptr(armnetwork.ProbeProtocolTCP),
2022-08-01 10:51:34 -04:00
Port: to.Ptr[int32](constants.DebugdPort),
2022-05-24 04:04:42 -04:00
},
},
2022-08-31 21:40:29 -04:00
{
Name: to.Ptr(konnectivityHealthProbeName),
Properties: &armnetwork.ProbePropertiesFormat{
Protocol: to.Ptr(armnetwork.ProbeProtocolTCP),
Port: to.Ptr[int32](constants.KonnectivityPort),
},
},
2022-05-24 04:04:42 -04:00
},
LoadBalancingRules: []*armnetwork.LoadBalancingRule{
{
Name: to.Ptr("kubeLoadBalancerRule"),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/frontendIPConfigurations/" + frontEndIPConfigName),
2022-05-24 04:04:42 -04:00
},
2022-08-01 10:51:34 -04:00
FrontendPort: to.Ptr[int32](constants.KubernetesPort),
BackendPort: to.Ptr[int32](constants.KubernetesPort),
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
2022-05-24 04:04:42 -04:00
Probe: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/probes/" + kubeHealthProbeName),
2022-05-24 04:04:42 -04:00
},
DisableOutboundSnat: to.Ptr(true),
2022-05-24 04:04:42 -04:00
BackendAddressPools: []*armnetwork.SubResource{
{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/backendAddressPools/" + backEndAddressPoolControlPlaneName),
2022-05-24 04:04:42 -04:00
},
},
},
},
{
Name: to.Ptr("verifyLoadBalancerRule"),
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/frontendIPConfigurations/" + frontEndIPConfigName),
},
FrontendPort: to.Ptr[int32](constants.VerifyServiceNodePortGRPC),
BackendPort: to.Ptr[int32](constants.VerifyServiceNodePortGRPC),
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
Probe: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/probes/" + verifyHealthProbeName),
},
DisableOutboundSnat: to.Ptr(true),
BackendAddressPools: []*armnetwork.SubResource{
{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/backendAddressPools/" + backEndAddressPoolControlPlaneName),
},
},
},
},
2022-05-24 04:04:42 -04:00
{
Name: to.Ptr("coordLoadBalancerRule"),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/frontendIPConfigurations/" + frontEndIPConfigName),
2022-05-24 04:04:42 -04:00
},
FrontendPort: to.Ptr[int32](constants.BootstrapperPort),
BackendPort: to.Ptr[int32](constants.BootstrapperPort),
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
2022-05-24 04:04:42 -04:00
Probe: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/probes/" + coordHealthProbeName),
2022-05-24 04:04:42 -04:00
},
DisableOutboundSnat: to.Ptr(true),
2022-05-24 04:04:42 -04:00
BackendAddressPools: []*armnetwork.SubResource{
{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/backendAddressPools/" + backEndAddressPoolControlPlaneName),
2022-05-24 04:04:42 -04:00
},
},
},
},
2022-08-31 21:40:29 -04:00
{
Name: to.Ptr("konnectivityLoadBalancerRule"),
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/frontendIPConfigurations/" + frontEndIPConfigName),
},
FrontendPort: to.Ptr[int32](constants.KonnectivityPort),
BackendPort: to.Ptr[int32](constants.KonnectivityPort),
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
Probe: &armnetwork.SubResource{
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/probes/" + konnectivityHealthProbeName),
},
DisableOutboundSnat: to.Ptr(true),
BackendAddressPools: []*armnetwork.SubResource{
{
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/backendAddressPools/" + backEndAddressPoolControlPlaneName),
},
},
},
},
2022-05-24 04:04:42 -04:00
},
OutboundRules: []*armnetwork.OutboundRule{
{
Name: to.Ptr("outboundRuleControlPlane"),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.OutboundRulePropertiesFormat{
FrontendIPConfigurations: []*armnetwork.SubResource{
{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/frontendIPConfigurations/" + frontEndIPConfigName),
2022-05-24 04:04:42 -04:00
},
},
BackendAddressPool: &armnetwork.SubResource{
2022-08-29 05:55:46 -04:00
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/backendAddressPools/all"),
2022-05-24 04:04:42 -04:00
},
Protocol: to.Ptr(armnetwork.LoadBalancerOutboundRuleProtocolAll),
2022-05-24 04:04:42 -04:00
},
},
},
},
}
}
func (l *LoadBalancer) AppendDebugRules(armLoadBalancer armnetwork.LoadBalancer) armnetwork.LoadBalancer {
backEndAddressPoolControlPlaneName := BackendAddressPoolControlPlaneName + "-" + l.UID
if armLoadBalancer.Properties == nil {
armLoadBalancer.Properties = &armnetwork.LoadBalancerPropertiesFormat{}
}
if armLoadBalancer.Properties.LoadBalancingRules == nil {
armLoadBalancer.Properties.LoadBalancingRules = []*armnetwork.LoadBalancingRule{}
}
debugdRule := armnetwork.LoadBalancingRule{
Name: to.Ptr("debugdLoadBalancerRule"),
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/frontendIPConfigurations/" + frontEndIPConfigName),
},
FrontendPort: to.Ptr[int32](constants.DebugdPort),
BackendPort: to.Ptr[int32](constants.DebugdPort),
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
Probe: &armnetwork.SubResource{
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/probes/" + debugdHealthProbeName),
},
DisableOutboundSnat: to.Ptr(true),
BackendAddressPools: []*armnetwork.SubResource{
{
ID: to.Ptr("/subscriptions/" + l.Subscription +
"/resourceGroups/" + l.ResourceGroup +
"/providers/Microsoft.Network/loadBalancers/" + l.Name +
"/backendAddressPools/" + backEndAddressPoolControlPlaneName),
},
},
},
}
armLoadBalancer.Properties.LoadBalancingRules = append(armLoadBalancer.Properties.LoadBalancingRules, &debugdRule)
return armLoadBalancer
}