Skip to content

Commit

Permalink
feat: support default service session stickiness timeout (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Feb 10, 2023
1 parent 83685b5 commit 40b5890
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Makefile.e2e
Expand Up @@ -3,10 +3,19 @@ E2E_IP_FAMILY := $(shell echo $${E2E_IP_FAMILY:-ipv4})
E2E_NETWORK_MODE := $(shell echo $${E2E_NETWORK_MODE:-overlay})

K8S_CONFORMANCE_E2E_FOCUS = "sig-network.*Conformance" "sig-network.*Feature:NoSNAT"
K8S_CONFORMANCE_E2E_SKIP = "sig-network.*Services.*session affinity"
K8S_CONFORMANCE_E2E_SKIP =
K8S_NETPOL_E2E_FOCUS = "sig-network.*Feature:NetworkPolicy"
K8S_NETPOL_E2E_SKIP = "sig-network.*NetworkPolicyLegacy"

ifeq ($(shell echo $(E2E_BRANCH) | grep -o ^release-),release-)
VERSION_NUM = $(subst release-,,$(E2E_BRANCH))
VER_MAJOR = $(shell echo $(VERSION_NUM) | cut -f1 -d.)
VER_MINOR = $(shell echo $(VERSION_NUM) | cut -f2 -d.)
ifeq ($(shell test $(VER_MAJOR) -lt 1 -o \( $(VER_MAJOR) -eq 1 -a $(VER_MINOR) -lt 12 \) && echo true),true)
K8S_CONFORMANCE_E2E_SKIP += "sig-network.*Services.*session affinity"
endif
endif

ifeq ($(shell test $(E2E_IP_FAMILY) != ipv6 && echo true),true)
K8S_CONFORMANCE_E2E_FOCUS += \
"sig-network.*Feature:Networking-IPv4" \
Expand Down
21 changes: 14 additions & 7 deletions pkg/controller/endpoint.go
Expand Up @@ -176,8 +176,9 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
}

tcpLb, udpLb := vpc.Status.TcpLoadBalancer, vpc.Status.UdpLoadBalancer
oldTcpLb, oldUdpLb := vpc.Status.TcpSessionLoadBalancer, vpc.Status.UdpSessionLoadBalancer
if svc.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
tcpLb, udpLb = vpc.Status.TcpSessionLoadBalancer, vpc.Status.UdpSessionLoadBalancer
tcpLb, udpLb, oldTcpLb, oldUdpLb = oldTcpLb, oldUdpLb, tcpLb, udpLb
}

for _, settingIP := range LbIPs {
Expand All @@ -193,9 +194,12 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
return err
}
} else {
err = c.ovnLegacyClient.DeleteLoadBalancerVip(vip, tcpLb)
if err != nil {
klog.Errorf("failed to delete vip %s at tcp lb, %v", vip, err)
if err = c.ovnLegacyClient.DeleteLoadBalancerVip(vip, tcpLb); err != nil {
klog.Errorf("failed to delete vip %s from tcp lb %s: %v", vip, tcpLb, err)
return err
}
if err = c.ovnLegacyClient.DeleteLoadBalancerVip(vip, oldTcpLb); err != nil {
klog.Errorf("failed to delete vip %s from tcp lb %s: %v", vip, oldTcpLb, err)
return err
}
}
Expand All @@ -207,9 +211,12 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
return err
}
} else {
err = c.ovnLegacyClient.DeleteLoadBalancerVip(vip, udpLb)
if err != nil {
klog.Errorf("failed to delete vip %s at udp lb, %v", vip, err)
if err = c.ovnLegacyClient.DeleteLoadBalancerVip(vip, udpLb); err != nil {
klog.Errorf("failed to delete vip %s from udp lb %s: %v", vip, udpLb, err)
return err
}
if err = c.ovnLegacyClient.DeleteLoadBalancerVip(vip, oldUdpLb); err != nil {
klog.Errorf("failed to delete vip %s from udp lb %s: %v", vip, oldUdpLb, err)
return err
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/init.go
Expand Up @@ -249,6 +249,11 @@ func (c *Controller) initLoadBalancer() error {
klog.Infof("tcp session load balancer %s exists", vpcLb.TcpSessLoadBalancer)
}

if err = c.ovnLegacyClient.SetLoadBalancerAffinityTimeout(vpcLb.TcpSessLoadBalancer, util.DefaultServiceSessionStickinessTimeout); err != nil {
klog.Errorf("failed to set service session stickiness timeout of cluster tcp session load balancer: %v", err)
return err
}

udpLb, err := c.ovnLegacyClient.FindLoadbalancer(vpcLb.UdpLoadBalancer)
if err != nil {
return fmt.Errorf("failed to find udp lb: %v", err)
Expand Down Expand Up @@ -279,6 +284,11 @@ func (c *Controller) initLoadBalancer() error {
klog.Infof("udp session load balancer %s exists", vpcLb.UdpSessLoadBalancer)
}

if err = c.ovnLegacyClient.SetLoadBalancerAffinityTimeout(vpcLb.UdpSessLoadBalancer, util.DefaultServiceSessionStickinessTimeout); err != nil {
klog.Errorf("failed to set service session stickiness timeout of cluster udp session load balancer: %v", err)
return err
}

vpc.Status.TcpLoadBalancer = vpcLb.TcpLoadBalancer
vpc.Status.TcpSessionLoadBalancer = vpcLb.TcpSessLoadBalancer
vpc.Status.UdpLoadBalancer = vpcLb.UdpLoadBalancer
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/vpc.go
Expand Up @@ -297,6 +297,11 @@ func (c *Controller) addLoadBalancer(vpc string) (*VpcLoadBalancer, error) {
klog.Infof("tcp session load balancer %s exists", tcpSessionLb)
}

if err = c.ovnLegacyClient.SetLoadBalancerAffinityTimeout(vpcLbConfig.TcpSessLoadBalancer, util.DefaultServiceSessionStickinessTimeout); err != nil {
klog.Errorf("failed to set service session stickiness timeout of cluster tcp session load balancer: %v", err)
return nil, err
}

udpLb, err := c.ovnLegacyClient.FindLoadbalancer(vpcLbConfig.UdpLoadBalancer)
if err != nil {
return nil, fmt.Errorf("failed to find udp lb %v", err)
Expand Down Expand Up @@ -327,6 +332,11 @@ func (c *Controller) addLoadBalancer(vpc string) (*VpcLoadBalancer, error) {
klog.Infof("udp session load balancer %s exists", udpSessionLb)
}

if err = c.ovnLegacyClient.SetLoadBalancerAffinityTimeout(vpcLbConfig.UdpSessLoadBalancer, util.DefaultServiceSessionStickinessTimeout); err != nil {
klog.Errorf("failed to set service session stickiness timeout of cluster udp session load balancer: %v", err)
return nil, err
}

return vpcLbConfig, nil
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/ovs/ovn-nbctl-legacy.go
Expand Up @@ -1479,6 +1479,16 @@ func (c LegacyClient) CreateLoadBalancer(lb, protocol, selectFields string) erro
return err
}

// SetLoadBalancerAffinityTimeout sets the LB's affinity timeout in seconds
func (c LegacyClient) SetLoadBalancerAffinityTimeout(lb string, timeout int) error {
output, err := c.ovnNbCommand("set", "load_balancer", lb, fmt.Sprintf("options:affinity_timeout=%d", timeout))
if err != nil {
klog.Errorf("failed to set affinity timeout of LB %s to %d, error: %v, output: %s", lb, timeout, err, output)
return err
}
return nil
}

// CreateLoadBalancerRule create loadbalancer rul in ovn
func (c LegacyClient) CreateLoadBalancerRule(lb, vip, ips, protocol string) error {
_, err := c.ovnNbCommand(MayExist, "lb-add", lb, vip, ips, strings.ToLower(protocol))
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/const.go
Expand Up @@ -202,4 +202,6 @@ const (

U2OInterconnName = "u2o-interconnection.%s.%s"
U2OExcludeIPAg = "%s.u2o_exclude_ip.%s"

DefaultServiceSessionStickinessTimeout = 10800
)
2 changes: 1 addition & 1 deletion test/e2e/framework/image.go
Expand Up @@ -3,5 +3,5 @@ package framework
const (
PauseImage = "kubeovn/pause:3.2"
BusyBoxImage = "busybox:stable"
AgnhostImage = "kubeovn/agnhost:2.40"
AgnhostImage = "kubeovn/agnhost:2.43"
)

0 comments on commit 40b5890

Please sign in to comment.