Skip to content

Commit

Permalink
Merge pull request #114468 from princepereira/automated-cherry-pick-o…
Browse files Browse the repository at this point in the history
…f-#114407-upstream-release-1.26

Automated cherry pick of #114407: Windows Kube-Proxy implementation for internal traffic
  • Loading branch information
k8s-ci-robot committed Dec 16, 2022
2 parents c7118d9 + 0b0eee5 commit 5bef9f4
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/proxy/winkernel/proxier.go
Expand Up @@ -129,6 +129,7 @@ type serviceInfo struct {
preserveDIP bool
localTrafficDSR bool
winProxyOptimization bool
internalTrafficLocal bool
}

type hnsNetworkInfo struct {
Expand Down Expand Up @@ -531,6 +532,10 @@ func (proxier *Proxier) newServiceInfo(port *v1.ServicePort, service *v1.Service
// Annotation introduced to enable optimized loadbalancing
winProxyOptimization := !(strings.ToUpper(service.Annotations["winProxyOptimization"]) == "DISABLED")
localTrafficDSR := service.Spec.ExternalTrafficPolicy == v1.ServiceExternalTrafficPolicyTypeLocal
var internalTrafficLocal bool
if service.Spec.InternalTrafficPolicy != nil {
internalTrafficLocal = *service.Spec.InternalTrafficPolicy == v1.ServiceInternalTrafficPolicyLocal
}
err := hcn.DSRSupported()
if err != nil {
preserveDIP = false
Expand All @@ -548,8 +553,8 @@ func (proxier *Proxier) newServiceInfo(port *v1.ServicePort, service *v1.Service
info.hns = proxier.hns
info.localTrafficDSR = localTrafficDSR
info.winProxyOptimization = winProxyOptimization

klog.V(3).InfoS("Flags enabled for service", "service", service.Name, "localTrafficDSR", localTrafficDSR, "preserveDIP", preserveDIP, "winProxyOptimization", winProxyOptimization)
info.internalTrafficLocal = internalTrafficLocal
klog.V(3).InfoS("Flags enabled for service", "service", service.Name, "localTrafficDSR", localTrafficDSR, "winProxyOptimization", winProxyOptimization, "internalTrafficLocal", internalTrafficLocal, "preserveDIP", preserveDIP)

for _, eip := range service.Spec.ExternalIPs {
info.externalIPs = append(info.externalIPs, &externalIPInfo{ip: eip})
Expand Down Expand Up @@ -1296,6 +1301,12 @@ func (proxier *Proxier) syncProxyRules() {
continue
}

if svcInfo.internalTrafficLocal && svcInfo.localTrafficDSR && !ep.GetIsLocal() {
// No need to use or create remote endpoint when internal and external traffic policy is remote
klog.V(3).InfoS("Skipping the endpoint. Both internalTraffic and external traffic policies are local", "EpIP", ep.ip, " EpPort", ep.port)
continue
}

if someEndpointsServing {

if !allEndpointsTerminating && !ep.IsReady() {
Expand Down Expand Up @@ -1457,10 +1468,18 @@ func (proxier *Proxier) syncProxyRules() {
proxier.deleteExistingLoadBalancer(hns, svcInfo.winProxyOptimization, &svcInfo.hnsID, sourceVip, Enum(svcInfo.Protocol()), uint16(svcInfo.targetPort), uint16(svcInfo.Port()), hnsEndpoints, queriedLoadBalancers)

if endpointsAvailableForLB {

// clusterIPEndpoints is the endpoint list used for creating ClusterIP loadbalancer.
clusterIPEndpoints := hnsEndpoints
if svcInfo.internalTrafficLocal {
// Take local endpoints for clusterip loadbalancer when internal traffic policy is local.
clusterIPEndpoints = hnsLocalEndpoints
}

// If all endpoints are terminating, then no need to create Cluster IP LoadBalancer
// Cluster IP LoadBalancer creation
hnsLoadBalancer, err := hns.getLoadBalancer(
hnsEndpoints,
clusterIPEndpoints,
loadBalancerFlags{isDSR: proxier.isDSR, isIPv6: proxier.isIPv6Mode, sessionAffinity: sessionAffinityClientIP},
sourceVip,
svcInfo.ClusterIP().String(),
Expand Down

0 comments on commit 5bef9f4

Please sign in to comment.