mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +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
|
lbFlags |= hcn.LoadBalancerFlagsDSR
|
||||||
}
|
}
|
||||||
|
|
||||||
lb, err := hcn.AddLoadBalancer(
|
lbDistributionType := hcn.LoadBalancerDistributionNone
|
||||||
hnsEndpoints,
|
|
||||||
lbFlags,
|
if flags.sessionAffinity {
|
||||||
lbPortMappingFlags,
|
lbDistributionType = hcn.LoadBalancerDistributionSourceIP
|
||||||
sourceVip,
|
}
|
||||||
vips,
|
|
||||||
protocol,
|
loadBalancer := &hcn.HostComputeLoadBalancer{
|
||||||
internalPort,
|
SourceVIP: sourceVip,
|
||||||
externalPort,
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -95,11 +95,12 @@ type loadBalancerInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type loadBalancerFlags struct {
|
type loadBalancerFlags struct {
|
||||||
isILB bool
|
isILB bool
|
||||||
isDSR bool
|
isDSR bool
|
||||||
localRoutedVIP bool
|
localRoutedVIP bool
|
||||||
useMUX bool
|
useMUX bool
|
||||||
preserveDIP bool
|
preserveDIP bool
|
||||||
|
sessionAffinity bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal struct for string service information
|
// internal struct for string service information
|
||||||
@ -488,11 +489,12 @@ type Proxier struct {
|
|||||||
// precomputing some number of those and cache for future reuse.
|
// precomputing some number of those and cache for future reuse.
|
||||||
precomputedProbabilities []string
|
precomputedProbabilities []string
|
||||||
|
|
||||||
hns HostNetworkService
|
hns HostNetworkService
|
||||||
network hnsNetworkInfo
|
network hnsNetworkInfo
|
||||||
sourceVip string
|
sourceVip string
|
||||||
hostMac string
|
hostMac string
|
||||||
isDSR bool
|
isDSR bool
|
||||||
|
supportedFeatures hcn.SupportedFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
type localPort struct {
|
type localPort struct {
|
||||||
@ -649,6 +651,7 @@ func NewProxier(
|
|||||||
sourceVip: sourceVip,
|
sourceVip: sourceVip,
|
||||||
hostMac: hostMac,
|
hostMac: hostMac,
|
||||||
isDSR: isDSR,
|
isDSR: isDSR,
|
||||||
|
supportedFeatures: supportedFeatures,
|
||||||
}
|
}
|
||||||
|
|
||||||
burstSyncs := 2
|
burstSyncs := 2
|
||||||
@ -1226,9 +1229,15 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
if containsPublicIP || containsNodeIP {
|
if containsPublicIP || containsNodeIP {
|
||||||
sourceVip = proxier.nodeIP.String()
|
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(
|
hnsLoadBalancer, err := hns.getLoadBalancer(
|
||||||
hnsEndpoints,
|
hnsEndpoints,
|
||||||
loadBalancerFlags{isDSR: proxier.isDSR},
|
loadBalancerFlags{isDSR: proxier.isDSR, sessionAffinity: sessionAffinityClientIP},
|
||||||
sourceVip,
|
sourceVip,
|
||||||
svcInfo.clusterIP.String(),
|
svcInfo.clusterIP.String(),
|
||||||
Enum(svcInfo.protocol),
|
Enum(svcInfo.protocol),
|
||||||
@ -1253,7 +1262,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
hnsLoadBalancer, err := hns.getLoadBalancer(
|
hnsLoadBalancer, err := hns.getLoadBalancer(
|
||||||
nodePortEndpoints,
|
nodePortEndpoints,
|
||||||
loadBalancerFlags{localRoutedVIP: true},
|
loadBalancerFlags{localRoutedVIP: true, sessionAffinity: sessionAffinityClientIP},
|
||||||
sourceVip,
|
sourceVip,
|
||||||
"",
|
"",
|
||||||
Enum(svcInfo.protocol),
|
Enum(svcInfo.protocol),
|
||||||
@ -1274,7 +1283,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
// Try loading existing policies, if already available
|
// Try loading existing policies, if already available
|
||||||
hnsLoadBalancer, err = hns.getLoadBalancer(
|
hnsLoadBalancer, err = hns.getLoadBalancer(
|
||||||
hnsEndpoints,
|
hnsEndpoints,
|
||||||
loadBalancerFlags{},
|
loadBalancerFlags{sessionAffinity: sessionAffinityClientIP},
|
||||||
sourceVip,
|
sourceVip,
|
||||||
externalIP.ip,
|
externalIP.ip,
|
||||||
Enum(svcInfo.protocol),
|
Enum(svcInfo.protocol),
|
||||||
@ -1297,7 +1306,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
hnsLoadBalancer, err := hns.getLoadBalancer(
|
hnsLoadBalancer, err := hns.getLoadBalancer(
|
||||||
lbIngressEndpoints,
|
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,
|
sourceVip,
|
||||||
lbIngressIP.ip,
|
lbIngressIP.ip,
|
||||||
Enum(svcInfo.protocol),
|
Enum(svcInfo.protocol),
|
||||||
|
Loading…
Reference in New Issue
Block a user