constellation/cli/internal/azure/loadbalancer.go

191 lines
8.1 KiB
Go
Raw Normal View History

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"
)
// Azure returns a Azure representation of LoadBalancer.
func (l LoadBalancer) Azure() armnetwork.LoadBalancer {
frontEndIPConfigName := "frontEndIPConfig"
kubeHealthProbeName := "kubeHealthProbe"
verifyHealthProbeName := "verifyHealthProbe"
2022-05-24 04:04:42 -04:00
coordHealthProbeName := "coordHealthProbe"
debugdHealthProbeName := "debugdHealthProbe"
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{
{
Name: to.Ptr(backEndAddressPoolNodeName),
2022-05-24 04:04:42 -04:00
},
{
Name: to.Ptr(backEndAddressPoolControlPlaneName),
2022-05-24 04:04:42 -04:00
},
{
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
},
},
},
LoadBalancingRules: []*armnetwork.LoadBalancingRule{
{
Name: to.Ptr("kubeLoadBalancerRule"),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
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{
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{
{
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{
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{
ID: to.Ptr("/subscriptions/" + l.Subscription + "/resourceGroups/" + l.ResourceGroup + "/providers/Microsoft.Network/loadBalancers/" + l.Name + "/probes/" + verifyHealthProbeName),
},
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
{
Name: to.Ptr("coordLoadBalancerRule"),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
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{
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{
{
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("debudLoadBalancerRule"),
2022-05-24 04:04:42 -04:00
Properties: &armnetwork.LoadBalancingRulePropertiesFormat{
FrontendIPConfiguration: &armnetwork.SubResource{
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.DebugdPort),
BackendPort: to.Ptr[int32](constants.DebugdPort),
Protocol: to.Ptr(armnetwork.TransportProtocolTCP),
2022-05-24 04:04:42 -04:00
Probe: &armnetwork.SubResource{
ID: to.Ptr("/subscriptions/" + l.Subscription + "/resourceGroups/" + l.ResourceGroup + "/providers/Microsoft.Network/loadBalancers/" + l.Name + "/probes/" + debugdHealthProbeName),
2022-05-24 04:04:42 -04:00
},
DisableOutboundSnat: to.Ptr(true),
2022-05-24 04:04:42 -04:00
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{
{
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{
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
},
},
},
},
}
}