mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
add mixed protocol support for azure load balancer
This commit is contained in:
parent
cdbc9d8567
commit
4e4684662d
@ -879,74 +879,85 @@ func (az *Cloud) reconcileLoadBalancerRule(
|
|||||||
var expectedProbes []network.Probe
|
var expectedProbes []network.Probe
|
||||||
var expectedRules []network.LoadBalancingRule
|
var expectedRules []network.LoadBalancingRule
|
||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
lbRuleName := az.getLoadBalancerRuleName(service, port, subnet(service))
|
protocols := []v1.Protocol{port.Protocol}
|
||||||
|
if v, ok := service.Annotations[ServiceAnnotationLoadBalancerMixedProtocols]; ok && v == "true" {
|
||||||
klog.V(2).Infof("reconcileLoadBalancerRule lb name (%s) rule name (%s)", lbName, lbRuleName)
|
klog.V(2).Infof("reconcileLoadBalancerRule lb name (%s) flag(%s) is set", lbName, ServiceAnnotationLoadBalancerMixedProtocols)
|
||||||
|
if port.Protocol == v1.ProtocolTCP {
|
||||||
transportProto, _, probeProto, err := getProtocolsFromKubernetesProtocol(port.Protocol)
|
protocols = append(protocols, v1.ProtocolUDP)
|
||||||
if err != nil {
|
} else if port.Protocol == v1.ProtocolUDP {
|
||||||
return expectedProbes, expectedRules, err
|
protocols = append(protocols, v1.ProtocolTCP)
|
||||||
}
|
|
||||||
|
|
||||||
if servicehelpers.NeedsHealthCheck(service) {
|
|
||||||
podPresencePath, podPresencePort := servicehelpers.GetServiceHealthCheckPathPort(service)
|
|
||||||
|
|
||||||
expectedProbes = append(expectedProbes, network.Probe{
|
|
||||||
Name: &lbRuleName,
|
|
||||||
ProbePropertiesFormat: &network.ProbePropertiesFormat{
|
|
||||||
RequestPath: to.StringPtr(podPresencePath),
|
|
||||||
Protocol: network.ProbeProtocolHTTP,
|
|
||||||
Port: to.Int32Ptr(podPresencePort),
|
|
||||||
IntervalInSeconds: to.Int32Ptr(5),
|
|
||||||
NumberOfProbes: to.Int32Ptr(2),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} else if port.Protocol != v1.ProtocolUDP && port.Protocol != v1.ProtocolSCTP {
|
|
||||||
// we only add the expected probe if we're doing TCP
|
|
||||||
expectedProbes = append(expectedProbes, network.Probe{
|
|
||||||
Name: &lbRuleName,
|
|
||||||
ProbePropertiesFormat: &network.ProbePropertiesFormat{
|
|
||||||
Protocol: *probeProto,
|
|
||||||
Port: to.Int32Ptr(port.NodePort),
|
|
||||||
IntervalInSeconds: to.Int32Ptr(5),
|
|
||||||
NumberOfProbes: to.Int32Ptr(2),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
loadDistribution := network.Default
|
|
||||||
if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
|
|
||||||
loadDistribution = network.SourceIP
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedRule := network.LoadBalancingRule{
|
|
||||||
Name: &lbRuleName,
|
|
||||||
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
|
||||||
Protocol: *transportProto,
|
|
||||||
FrontendIPConfiguration: &network.SubResource{
|
|
||||||
ID: to.StringPtr(lbFrontendIPConfigID),
|
|
||||||
},
|
|
||||||
BackendAddressPool: &network.SubResource{
|
|
||||||
ID: to.StringPtr(lbBackendPoolID),
|
|
||||||
},
|
|
||||||
LoadDistribution: loadDistribution,
|
|
||||||
FrontendPort: to.Int32Ptr(port.Port),
|
|
||||||
BackendPort: to.Int32Ptr(port.Port),
|
|
||||||
EnableFloatingIP: to.BoolPtr(true),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if port.Protocol == v1.ProtocolTCP {
|
|
||||||
expectedRule.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes = lbIdleTimeout
|
|
||||||
}
|
|
||||||
|
|
||||||
// we didn't construct the probe objects for UDP or SCTP because they're not used/needed/allowed
|
|
||||||
if port.Protocol != v1.ProtocolUDP && port.Protocol != v1.ProtocolSCTP {
|
|
||||||
expectedRule.Probe = &network.SubResource{
|
|
||||||
ID: to.StringPtr(az.getLoadBalancerProbeID(lbName, lbRuleName)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedRules = append(expectedRules, expectedRule)
|
for _, protocol := range protocols {
|
||||||
|
lbRuleName := az.getLoadBalancerRuleName(service, protocol, port.Port, subnet(service))
|
||||||
|
klog.V(2).Infof("reconcileLoadBalancerRule lb name (%s) rule name (%s)", lbName, lbRuleName)
|
||||||
|
|
||||||
|
transportProto, _, probeProto, err := getProtocolsFromKubernetesProtocol(protocol)
|
||||||
|
if err != nil {
|
||||||
|
return expectedProbes, expectedRules, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if servicehelpers.NeedsHealthCheck(service) {
|
||||||
|
podPresencePath, podPresencePort := servicehelpers.GetServiceHealthCheckPathPort(service)
|
||||||
|
|
||||||
|
expectedProbes = append(expectedProbes, network.Probe{
|
||||||
|
Name: &lbRuleName,
|
||||||
|
ProbePropertiesFormat: &network.ProbePropertiesFormat{
|
||||||
|
RequestPath: to.StringPtr(podPresencePath),
|
||||||
|
Protocol: network.ProbeProtocolHTTP,
|
||||||
|
Port: to.Int32Ptr(podPresencePort),
|
||||||
|
IntervalInSeconds: to.Int32Ptr(5),
|
||||||
|
NumberOfProbes: to.Int32Ptr(2),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else if protocol != v1.ProtocolUDP && protocol != v1.ProtocolSCTP {
|
||||||
|
// we only add the expected probe if we're doing TCP
|
||||||
|
expectedProbes = append(expectedProbes, network.Probe{
|
||||||
|
Name: &lbRuleName,
|
||||||
|
ProbePropertiesFormat: &network.ProbePropertiesFormat{
|
||||||
|
Protocol: *probeProto,
|
||||||
|
Port: to.Int32Ptr(port.NodePort),
|
||||||
|
IntervalInSeconds: to.Int32Ptr(5),
|
||||||
|
NumberOfProbes: to.Int32Ptr(2),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
loadDistribution := network.Default
|
||||||
|
if service.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
|
||||||
|
loadDistribution = network.SourceIP
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedRule := network.LoadBalancingRule{
|
||||||
|
Name: &lbRuleName,
|
||||||
|
LoadBalancingRulePropertiesFormat: &network.LoadBalancingRulePropertiesFormat{
|
||||||
|
Protocol: *transportProto,
|
||||||
|
FrontendIPConfiguration: &network.SubResource{
|
||||||
|
ID: to.StringPtr(lbFrontendIPConfigID),
|
||||||
|
},
|
||||||
|
BackendAddressPool: &network.SubResource{
|
||||||
|
ID: to.StringPtr(lbBackendPoolID),
|
||||||
|
},
|
||||||
|
LoadDistribution: loadDistribution,
|
||||||
|
FrontendPort: to.Int32Ptr(port.Port),
|
||||||
|
BackendPort: to.Int32Ptr(port.Port),
|
||||||
|
EnableFloatingIP: to.BoolPtr(true),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if protocol == v1.ProtocolTCP {
|
||||||
|
expectedRule.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes = lbIdleTimeout
|
||||||
|
}
|
||||||
|
|
||||||
|
// we didn't construct the probe objects for UDP or SCTP because they're not used/needed/allowed
|
||||||
|
if protocol != v1.ProtocolUDP && protocol != v1.ProtocolSCTP {
|
||||||
|
expectedRule.Probe = &network.SubResource{
|
||||||
|
ID: to.StringPtr(az.getLoadBalancerProbeID(lbName, lbRuleName)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedRules = append(expectedRules, expectedRule)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return expectedProbes, expectedRules, nil
|
return expectedProbes, expectedRules, nil
|
||||||
|
@ -223,12 +223,12 @@ func getBackendPoolName(clusterName string) string {
|
|||||||
return clusterName
|
return clusterName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (az *Cloud) getLoadBalancerRuleName(service *v1.Service, port v1.ServicePort, subnetName *string) string {
|
func (az *Cloud) getLoadBalancerRuleName(service *v1.Service, protocol v1.Protocol, port int32, subnetName *string) string {
|
||||||
prefix := az.getRulePrefix(service)
|
prefix := az.getRulePrefix(service)
|
||||||
if subnetName == nil {
|
if subnetName == nil {
|
||||||
return fmt.Sprintf("%s-%s-%d", prefix, port.Protocol, port.Port)
|
return fmt.Sprintf("%s-%s-%d", prefix, protocol, port)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s-%s-%s-%d", prefix, *subnetName, port.Protocol, port.Port)
|
return fmt.Sprintf("%s-%s-%s-%d", prefix, *subnetName, protocol, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (az *Cloud) getSecurityRuleName(service *v1.Service, port v1.ServicePort, sourceAddrPrefix string) string {
|
func (az *Cloud) getSecurityRuleName(service *v1.Service, port v1.ServicePort, sourceAddrPrefix string) string {
|
||||||
|
@ -1209,7 +1209,7 @@ func validateLoadBalancer(t *testing.T, loadBalancer *network.LoadBalancer, serv
|
|||||||
}
|
}
|
||||||
for _, wantedRule := range svc.Spec.Ports {
|
for _, wantedRule := range svc.Spec.Ports {
|
||||||
expectedRuleCount++
|
expectedRuleCount++
|
||||||
wantedRuleName := az.getLoadBalancerRuleName(&svc, wantedRule, subnet(&svc))
|
wantedRuleName := az.getLoadBalancerRuleName(&svc, wantedRule.Protocol, wantedRule.Port, subnet(&svc))
|
||||||
foundRule := false
|
foundRule := false
|
||||||
for _, actualRule := range *loadBalancer.LoadBalancingRules {
|
for _, actualRule := range *loadBalancer.LoadBalancingRules {
|
||||||
if strings.EqualFold(*actualRule.Name, wantedRuleName) &&
|
if strings.EqualFold(*actualRule.Name, wantedRuleName) &&
|
||||||
|
Loading…
Reference in New Issue
Block a user