Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add load balancer health check #3216

Merged
merged 14 commits into from
Oct 19, 2023
Merged

add load balancer health check #3216

merged 14 commits into from
Oct 19, 2023

Conversation

qiutingjun
Copy link
Contributor

@qiutingjun qiutingjun commented Sep 14, 2023

What type of this PR

Examples of user facing changes:

  • Features

add health check for load balancer

[ovn-nb document](https://www.ovn.org/support/dist-docs/ovn-nb.5.html)

     Health Checks:

       OVN  supports  health checks for load balancer endpoints, for IPv4 load
       balancers only. When health checks are enabled, the load balancer  uses
       only healthy endpoints.

       Suppose      that      vips      contains      a     key-value     pair
       10.0.0.10:80=10.0.0.4:8080,20.0.0.4:8080. 
       To enable health  checks  for this  virtual’s endpoints, 
       add two key-value pairs to ip_port_mappings,
       with keys 10.0.0.4 and 20.0.0.4, 
       and add to health_check a reference to
       a Load_Balancer_Health_Check row whose vip is set to 10.0.0.10.

       health_check: set of Load_Balancer_Health_Checks
              Load balancer health checks associated with this load balancer.

       ip_port_mappings: map of string-string pairs
              Maps  from endpoint IP to a colon-separated pair of logical port
              name and source IP, e.g. port_name:sourc_ip. Health  checks  are
              sent to this port with the specified source IP.

              For  example, in the example above, IP to port mappings might be
              defined         as         10.0.0.4=sw0-p1:10.0.0.2          and
              20.0.0.4=sw1-p1:20.0.0.2,  if  the  values  given  were suitable
              ports and IP addresses.

uuid=`ovn-nbctl --bare --columns _uuid find load_balancer name=test-vpc3-tcp-lb0`

# 关联 ip_port_mappings 到loadbalancer

ovn-nbctl --wait=sb set load_balancer $uuid ip_port_mappings:192.168.4.4=vpc3-busybox03.vpc3:192.168.4.14

ovn-nbctl --wait=sb set load_balancer $uuid ip_port_mappings:192.168.4.5=vpc3-busybox04.vpc3:192.168.4.15

uuid3=`ovn-nbctl --id=@hc create Load_Balancer_Health_Check vip="10.120.31.215\:8000" -- add Load_Balancer $uuid health_check @hc`

# echo $uuid3
66117312-2b7a-4920-b903-fadb3a842b3b

ovn-nbctl set Load_Balancer_Health_Check $uuid3 options:interval=5 options:timeout=20 options:success_count=3 options:failure_count=3



# ovn-nbctl list Load_Balancer_Health_Check
_uuid               : 66117312-2b7a-4920-b903-fadb3a842b3b
external_ids        : {}
options             : {failure_count="3", interval="5", success_count="3", timeout="20"}
vip                 : "10.120.31.215:8000"

Which issue(s) this PR fixes:

Fixes #(issue-number)

WHAT

🤖 Generated by Copilot at c66e373

This pull request adds support for ip port mappings and health checks to load balancers for services and endpoints in the kube-ovn controller. It also improves the readability, consistency, and error handling of the code in various files, updates the module versions in go.mod, and adds unit tests for the new functionality. Additionally, it renames some files to follow the Go naming convention and avoid linting errors.

🤖 Generated by Copilot at c66e373

We're the crew of the OVN ship, we code with skill and pride
We manage load balancers and health checks, we keep the service alive
We follow Go conventions and we test our code with care
We heave away on the count of three, we're the best in the open air

HOW

🤖 Generated by Copilot at c66e373

  • Rename files to follow Go naming convention (link, link, link, link)
  • Update dependencies in go.mod file (link, link)
  • Add new value to exclude list of gosec tool in Makefile (link)
  • Add and modify mock interfaces and methods for the ovs package in mocks/pkg/ovs/interface.go (link, link, link, link, link, link, link, link, link)
  • Improve readability and consistency of code by declaring variables in single var blocks, simplifying if statements, removing unused code, and renaming variables in various files (link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link, link)
  • Support new functionality of adding ip port mappings and health checks to load balancers by modifying the logic of deleting or adding vips, adding new parameters and return types to existing functions, and adding new fields to existing structs in various files (link, link, link, link, link, link, link, link, link, link, link, link)
  • Add new file (pkg/ovs/ovn-nb-load_balancer_health_check.go) that implements the LoadBalancerHealthCheck interface and provides the methods for managing load balancer health checks in the OVN NB database (link)
  • Add new file (pkg/ovs/ovn-nb-load_balancer_health_check_test.go) that provides unit tests for the LoadBalancerHealthCheck interface and its methods (link)
  • Add new log message to the AddNat function in pkg/ovs/ovn-nb-nat.go to improve error handling and debugging (link)

pkg/controller/init.go Outdated Show resolved Hide resolved
@zbb88888
Copy link
Collaborator

zbb88888 commented Sep 21, 2023

lb 健康检查:

  • 仅 switch lb rule 支持健康检查
  • 仅当存在多个后端(ip port map)时,支持添加健康检查
  • 随便申请一个子网内的(type 类型为空)的 vip 作为健康检查ip,如果需要复用则可以考虑用一个 subnet 名的 vip,一个子网中只有一个,或者其他更好的唯一命名方案也可以

todo://

  • slr e2e 添加健康检查的 e2e 校验 service monitor 的状态

@qiutingjun qiutingjun marked this pull request as draft September 21, 2023 06:12
@qiutingjun qiutingjun force-pushed the health branch 3 times, most recently from a227dc0 to f6b6ee6 Compare October 9, 2023 08:23
@qiutingjun qiutingjun marked this pull request as ready for review October 12, 2023 10:01
@qiutingjun qiutingjun requested a review from zbb88888 October 12, 2023 10:02
pkg/controller/endpoint.go Outdated Show resolved Hide resolved
pkg/controller/endpoint.go Outdated Show resolved Hide resolved
pkg/controller/endpoint.go Outdated Show resolved Hide resolved
pkg/controller/endpoint.go Outdated Show resolved Hide resolved
pkg/controller/gc.go Outdated Show resolved Hide resolved
pkg/controller/switch_lb_rule.go Outdated Show resolved Hide resolved
pkg/controller/switch_lb_rule.go Outdated Show resolved Hide resolved
pkg/controller/switch_lb_rule.go Outdated Show resolved Hide resolved
pkg/controller/switch_lb_rule.go Outdated Show resolved Hide resolved
pkg/controller/switch_lb_rule.go Outdated Show resolved Hide resolved
@zbb88888
Copy link
Collaborator

please attach the docs pr

@qiutingjun qiutingjun requested a review from zbb88888 October 13, 2023 16:18
@zbb88888
Copy link
Collaborator

hi @oilbeater, could you help review?

@zbb88888 zbb88888 requested a review from oilbeater October 17, 2023 02:04
@qiutingjun
Copy link
Contributor Author

please attach the docs pr

kubeovn/docs#129

Makefile Outdated Show resolved Hide resolved
@qiutingjun qiutingjun requested a review from oilbeater October 17, 2023 09:25
Signed-off-by: 夜微澜 <[email protected]>
@oilbeater oilbeater merged commit 3fe3ec6 into kubeovn:master Oct 19, 2023
zbb88888 pushed a commit that referenced this pull request Oct 19, 2023
* add load balancer health check

Signed-off-by: 夜微澜 <[email protected]>

* reuse a VIP named by subnet to health check

Signed-off-by: 夜微澜 <[email protected]>

* clear health check while slr deleted

Signed-off-by: 夜微澜 <[email protected]>

* fix health check unit test

Signed-off-by: 夜微澜 <[email protected]>

* fix go.mod

Signed-off-by: 夜微澜 <[email protected]>

* format && clean

Signed-off-by: 夜微澜 <[email protected]>

* revert changes to makefile parameters

Signed-off-by: 夜微澜 <[email protected]>

* update format

Signed-off-by: 夜微澜 <[email protected]>

---------

Signed-off-by: 夜微澜 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants