mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Adding windows implementation for sessionaffinity
This commit is contained in:
parent
0891f69f5e
commit
44096b8f71
@ -232,16 +232,37 @@ func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
||||
lbFlags |= hcn.LoadBalancerFlagsDSR
|
||||
}
|
||||
|
||||
lb, err := hcn.AddLoadBalancer(
|
||||
hnsEndpoints,
|
||||
lbFlags,
|
||||
lbPortMappingFlags,
|
||||
sourceVip,
|
||||
vips,
|
||||
protocol,
|
||||
internalPort,
|
||||
externalPort,
|
||||
)
|
||||
lbDistributionType := hcn.LoadBalancerDistributionNone
|
||||
|
||||
if flags.sessionAffinity {
|
||||
lbDistributionType = hcn.LoadBalancerDistributionSourceIP
|
||||
}
|
||||
|
||||
loadBalancer := &hcn.HostComputeLoadBalancer{
|
||||
SourceVIP: sourceVip,
|
||||
PortMappings: []hcn.LoadBalancerPortMapping{
|
||||
{
|
||||
Protocol: uint32(protocol),
|
||||
InternalPort: internalPort,
|
||||
ExternalPort: externalPort,
|
||||
DistributionType: lbDistributionType,
|
||||
Flags: lbPortMappingFlags,
|
||||
},
|
||||
},
|
||||
FrontendVIPs: vips,
|
||||
SchemaVersion: hcn.SchemaVersion{
|
||||
Major: 2,
|
||||
Minor: 0,
|
||||
},
|
||||
Flags: lbFlags,
|
||||
}
|
||||
|
||||
for _, endpoint := range hnsEndpoints {
|
||||
loadBalancer.HostComputeEndpoints = append(loadBalancer.HostComputeEndpoints, endpoint.Id)
|
||||
}
|
||||
|
||||
lb, err := loadBalancer.Create()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -95,11 +95,12 @@ type loadBalancerInfo struct {
|
||||
}
|
||||
|
||||
type loadBalancerFlags struct {
|
||||
isILB bool
|
||||
isDSR bool
|
||||
localRoutedVIP bool
|
||||
useMUX bool
|
||||
preserveDIP bool
|
||||
isILB bool
|
||||
isDSR bool
|
||||
localRoutedVIP bool
|
||||
useMUX bool
|
||||
preserveDIP bool
|
||||
sessionAffinity bool
|
||||
}
|
||||
|
||||
// internal struct for string service information
|
||||
@ -488,11 +489,12 @@ type Proxier struct {
|
||||
// precomputing some number of those and cache for future reuse.
|
||||
precomputedProbabilities []string
|
||||
|
||||
hns HostNetworkService
|
||||
network hnsNetworkInfo
|
||||
sourceVip string
|
||||
hostMac string
|
||||
isDSR bool
|
||||
hns HostNetworkService
|
||||
network hnsNetworkInfo
|
||||
sourceVip string
|
||||
hostMac string
|
||||
isDSR bool
|
||||
supportedFeatures hcn.SupportedFeatures
|
||||
}
|
||||
|
||||
type localPort struct {
|
||||
@ -649,6 +651,7 @@ func NewProxier(
|
||||
sourceVip: sourceVip,
|
||||
hostMac: hostMac,
|
||||
isDSR: isDSR,
|
||||
supportedFeatures: supportedFeatures,
|
||||
}
|
||||
|
||||
burstSyncs := 2
|
||||
@ -1226,9 +1229,15 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
if containsPublicIP || containsNodeIP {
|
||||
sourceVip = proxier.nodeIP.String()
|
||||
}
|
||||
|
||||
sessionAffinityClientIP := svcInfo.sessionAffinityType == v1.ServiceAffinityClientIP
|
||||
if sessionAffinityClientIP && !proxier.supportedFeatures.SessionAffinity {
|
||||
klog.Warningf("Session Affinity is not supported on this version of Windows.")
|
||||
}
|
||||
|
||||
hnsLoadBalancer, err := hns.getLoadBalancer(
|
||||
hnsEndpoints,
|
||||
loadBalancerFlags{isDSR: proxier.isDSR},
|
||||
loadBalancerFlags{isDSR: proxier.isDSR, sessionAffinity: sessionAffinityClientIP},
|
||||
sourceVip,
|
||||
svcInfo.clusterIP.String(),
|
||||
Enum(svcInfo.protocol),
|
||||
@ -1253,7 +1262,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
}
|
||||
hnsLoadBalancer, err := hns.getLoadBalancer(
|
||||
nodePortEndpoints,
|
||||
loadBalancerFlags{localRoutedVIP: true},
|
||||
loadBalancerFlags{localRoutedVIP: true, sessionAffinity: sessionAffinityClientIP},
|
||||
sourceVip,
|
||||
"",
|
||||
Enum(svcInfo.protocol),
|
||||
@ -1274,7 +1283,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
// Try loading existing policies, if already available
|
||||
hnsLoadBalancer, err = hns.getLoadBalancer(
|
||||
hnsEndpoints,
|
||||
loadBalancerFlags{},
|
||||
loadBalancerFlags{sessionAffinity: sessionAffinityClientIP},
|
||||
sourceVip,
|
||||
externalIP.ip,
|
||||
Enum(svcInfo.protocol),
|
||||
@ -1297,7 +1306,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
}
|
||||
hnsLoadBalancer, err := hns.getLoadBalancer(
|
||||
lbIngressEndpoints,
|
||||
loadBalancerFlags{isDSR: svcInfo.preserveDIP || proxier.isDSR, useMUX: svcInfo.preserveDIP, preserveDIP: svcInfo.preserveDIP},
|
||||
loadBalancerFlags{isDSR: svcInfo.preserveDIP || proxier.isDSR, useMUX: svcInfo.preserveDIP, preserveDIP: svcInfo.preserveDIP, sessionAffinity: sessionAffinityClientIP},
|
||||
sourceVip,
|
||||
lbIngressIP.ip,
|
||||
Enum(svcInfo.protocol),
|
||||
|
Loading…
Reference in New Issue
Block a user