ovn 有些 nbctl 配置的请求体可能包含三个数据库操作,比如 lb 健康检查的操作过程
1. lb 健康检查操作
(.venv) root@empty:~/feat/kube-ovn# cat /root/test/kube-ovn/health-check/04.add-hc-to-lb.sh
# lb 是基于 slr 触发维护的,已经绑定到 subnet,只需要配置 健康检查 即可
kubectl ko nbctl ls-lb-list vpc1-subnet1
lb=vpc-vpc1-tcp-sess-load
lb_uuid=`kubectl ko nbctl --bare --columns _uuid find Load_Balancer name=$lb`
echo "uuid $lb_uuid"
vip=10.1.0.100
#gw=10.1.0.254
gw=10.1.0.100
kubectl ko nbctl --wait=sb set load_balancer $lb_uuid ip_port_mappings:10.1.0.5=netshoot-1.ns1:$gw
# 使用同一个 同网段 vip
kubectl ko nbctl --wait=sb set load_balancer $lb_uuid ip_port_mappings:10.1.0.6=netshoot-2.ns1:$gw
health_check_id=`kubectl ko nbctl -v --id=@hc create Load_Balancer_Health_Check vip="$vip\:80" -- add Load_Balancer $lb_uuid health_check @hc`
echo "health_check_id $health_check_id"
kubectl ko nbctl set Load_Balancer_Health_Check $health_check_id options:interval=5 options:timeout=20 options:success_count=3 options:failure_count=3
kubectl ko nbctl -v 详情
++ kubectl ko nbctl -v --id=@hc create Load_Balancer_Health_Check 'vip=10.1.0.100\:80' -- add Load_Balancer f009248c-a43d-4c8b-8c44-11fbbfa8adb9 health_check @hc
2023-09-01T11:26:41Z|00001|reconnect|DBG|unix:/var/run/ovn/ovnnb_db.sock: entering BACKOFF
2023-09-01T11:26:41Z|00002|ovn_dbctl|INFO|Called as ovn-nbctl -v --id=@hc create Load_Balancer_Health_Check "vip=10.1.0.100\\:80" -- add Load_Balancer f009248c-a43d-4c8b-8c44-11fbbfa8adb9 health_check @hc
2023-09-01T11:26:41Z|00003|reconnect|INFO|unix:/var/run/ovn/ovnnb_db.sock: connecting...
2023-09-01T11:26:41Z|00004|reconnect|DBG|unix:/var/run/ovn/ovnnb_db.sock: entering CONNECTING
2023-09-01T11:26:41Z|00005|ovsdb_cs|DBG|unix:/var/run/ovn/ovnnb_db.sock: SERVER_SCHEMA_REQUESTED -> SERVER_SCHEMA_REQUESTED at ../lib/ovsdb-cs.c:423
2023-09-01T11:26:41Z|00006|poll_loop|DBG|wakeup due to [POLLOUT] on fd 3 (<->/var/run/ovn/ovnnb_db.sock) at ../lib/stream-fd.c:153
2023-09-01T11:26:41Z|00007|reconnect|INFO|unix:/var/run/ovn/ovnnb_db.sock: connected
2023-09-01T11:26:41Z|00008|reconnect|DBG|unix:/var/run/ovn/ovnnb_db.sock: entering ACTIVE
2023-09-01T11:26:41Z|00009|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: send request, method="get_schema", params=["_Server"], id=1
2023-09-01T11:26:41Z|00010|ovsdb_cs|DBG|unix:/var/run/ovn/ovnnb_db.sock: SERVER_SCHEMA_REQUESTED -> SERVER_SCHEMA_REQUESTED at ../lib/ovsdb-cs.c:423
2023-09-01T11:26:41Z|00011|poll_loop|DBG|wakeup due to [POLLIN] on fd 3 (<->/var/run/ovn/ovnnb_db.sock) at ../lib/stream-fd.c:157
2023-09-01T11:26:41Z|00012|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received reply, result={"name":"_Server","tables":{"Database":{"columns":{"schema":{"type":{"key":"string","min":0}},"model":{"type":{"key":{"type":"string","enum":["set",["clustered","relay","standalone"]]}}},"cid":{"type":{"key":"uuid","min":0}},"sid":{"type":{"key":"uuid","min":0}},"index":{"type":{"key":"integer","min":0}},"connected":{"type":"boolean"},"name":{"type":"string"},"leader":{"type":"boolean"}}}},"version":"1.2.0","cksum":"3009684573 744"}, id=1
2023-09-01T11:26:41Z|00013|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: send request, method="monitor_cond", params=["_Server",["monid","_Server"],{"Database":[{"columns":["name","model","connected","leader","schema","cid","index"]}]}], id=2
2023-09-01T11:26:41Z|00014|ovsdb_cs|DBG|unix:/var/run/ovn/ovnnb_db.sock: SERVER_SCHEMA_REQUESTED -> SERVER_MONITOR_REQUESTED at ../lib/ovsdb-cs.c:456
2023-09-01T11:26:41Z|00015|poll_loop|DBG|wakeup due to [POLLIN] on fd 3 (<->/var/run/ovn/ovnnb_db.sock) at ../lib/stream-fd.c:157
2023-09-01T11:26:41Z|00016|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received reply, result={"Database":{"5d8bc848-944a-4f7a-8998-dbe7afd122ef":{"initial":{"name":"Local_Config","connected":true,"schema":"{\"cksum\":\"2048726482 1858\",\"name\":\"Local_Config\",\"tables\":{\"Config\":{\"columns\":{\"connections\":{\"type\":{\"key\":{\"refTable\":\"Connection\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}}},\"isRoot\":true,\"maxRows\":1},\"Connection\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"inactivity_probe\":{\"type\":{\"key\":\"integer\",\"min\":0}},\"is_connected\":{\"ephemeral\":true,\"type\":\"boolean\"},\"max_backoff\":{\"type\":{\"key\":{\"minInteger\":1000,\"type\":\"integer\"},\"min\":0}},\"other_config\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"read_only\":{\"type\":\"boolean\"},\"role\":{\"type\":\"string\"},\"status\":{\"ephemeral\":true,\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"target\":{\"type\":\"string\"}},\"indexes\":[[\"target\"]]}},\"version\":\"1.0.0\"}","model":"standalone","leader":true}},"22a390dd-62b0-4486-99fd-d3262eefeeda":{"initial":{"name":"_Server","connected":true,"schema":"{\"cksum\":\"3009684573 744\",\"name\":\"_Server\",\"tables\":{\"Database\":{\"columns\":{\"cid\":{\"type\":{\"key\":\"uuid\",\"min\":0}},\"connected\":{\"type\":\"boolean\"},\"index\":{\"type\":{\"key\":\"integer\",\"min\":0}},\"leader\":{\"type\":\"boolean\"},\"model\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"clustered\",\"relay\",\"standalone\"]],\"type\":\"string\"}}},\"name\":{\"type\":\"string\"},\"schema\":{\"type\":{\"key\":\"string\",\"min\":0}},\"sid\":{\"type\":{\"key\":\"uuid\",\"min\":0}}}}},\"version\":\"1.2.0\"}","model":"standalone","leader":true}},"47814892-c603-4410-bec1-a0929fe4da5f":{"initial":{"index":138,"name":"OVN_Northbound","connected":true,"schema":"{\"cksum\":\"94023179 33468\",\"name\":\"OVN_Northbound\",\"tables\":{\"ACL\":{\"columns\":{\"action\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"allow\",\"allow-related\",\"allow-stateless\",\"drop\",\"reject\"]],\"type\":\"string\"}}},\"direction\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"from-lport\",\"to-lport\"]],\"type\":\"string\"}}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"label\":{\"type\":{\"key\":{\"maxInteger\":4294967295,\"minInteger\":0,\"type\":\"integer\"}}},\"log\":{\"type\":\"boolean\"},\"match\":{\"type\":\"string\"},\"meter\":{\"type\":{\"key\":\"string\",\"min\":0}},\"name\":{\"type\":{\"key\":{\"maxLength\":63,\"type\":\"string\"},\"min\":0}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"priority\":{\"type\":{\"key\":{\"maxInteger\":32767,\"minInteger\":0,\"type\":\"integer\"}}},\"severity\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"alert\",\"debug\",\"info\",\"notice\",\"warning\"]],\"type\":\"string\"},\"min\":0}}}},\"Address_Set\":{\"columns\":{\"addresses\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"name\":{\"type\":\"string\"}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"BFD\":{\"columns\":{\"detect_mult\":{\"type\":{\"key\":{\"minInteger\":1,\"type\":\"integer\"},\"min\":0}},\"dst_ip\":{\"type\":\"string\"},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"logical_port\":{\"type\":\"string\"},\"min_rx\":{\"type\":{\"key\":\"integer\",\"min\":0}},\"min_tx\":{\"type\":{\"key\":{\"minInteger\":1,\"type\":\"integer\"},\"min\":0}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"status\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"admin_down\",\"down\",\"init\",\"up\"]],\"type\":\"string\"},\"min\":0}}},\"indexes\":[[\"logical_port\",\"dst_ip\"]],\"isRoot\":true},\"Chassis_Template_Var\":{\"columns\":{\"chassis\":{\"type\":\"string\"},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"variables\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}}},\"indexes\":[[\"chassis\"]],\"isRoot\":true},\"Connection\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"inactivity_probe\":{\"type\":{\"key\":\"integer\",\"min\":0}},\"is_connected\":{\"type\":\"boolean\"},\"max_backoff\":{\"type\":{\"key\":{\"minInteger\":1000,\"type\":\"integer\"},\"min\":0}},\"other_config\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"status\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"target\":{\"type\":\"string\"}},\"indexes\":[[\"target\"]]},\"Copp\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"meters\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"name\":{\"type\":\"string\"}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"DHCP_Options\":{\"columns\":{\"cidr\":{\"type\":\"string\"},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}}},\"isRoot\":true},\"DNS\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"records\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}}},\"isRoot\":true},\"Forwarding_Group\":{\"columns\":{\"child_port\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\"}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"liveness\":{\"type\":\"boolean\"},\"name\":{\"type\":\"string\"},\"vip\":{\"type\":\"string\"},\"vmac\":{\"type\":\"string\"}}},\"Gateway_Chassis\":{\"columns\":{\"chassis_name\":{\"type\":\"string\"},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"name\":{\"type\":\"string\"},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"priority\":{\"type\":{\"key\":{\"maxInteger\":32767,\"minInteger\":0,\"type\":\"integer\"}}}},\"indexes\":[[\"name\"]]},\"HA_Chassis\":{\"columns\":{\"chassis_name\":{\"type\":\"string\"},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"priority\":{\"type\":{\"key\":{\"maxInteger\":32767,\"minInteger\":0,\"type\":\"integer\"}}}}},\"HA_Chassis_Group\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"ha_chassis\":{\"type\":{\"key\":{\"refTable\":\"HA_Chassis\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"name\":{\"type\":\"string\"}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"Load_Balancer\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"health_check\":{\"type\":{\"key\":{\"refTable\":\"Load_Balancer_Health_Check\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"ip_port_mappings\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"name\":{\"type\":\"string\"},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"protocol\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"sctp\",\"tcp\",\"udp\"]],\"type\":\"string\"},\"min\":0}},\"selection_fields\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"eth_dst\",\"eth_src\",\"ip_dst\",\"ip_src\",\"tp_dst\",\"tp_src\"]],\"type\":\"string\"},\"max\":\"unlimited\",\"min\":0}},\"vips\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}}},\"isRoot\":true},\"Load_Balancer_Group\":{\"columns\":{\"load_balancer\":{\"type\":{\"key\":{\"refTable\":\"Load_Balancer\",\"refType\":\"weak\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"name\":{\"type\":\"string\"}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"Load_Balancer_Health_Check\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"vip\":{\"type\":\"string\"}}},\"Logical_Router\":{\"columns\":{\"copp\":{\"type\":{\"key\":{\"refTable\":\"Copp\",\"refType\":\"weak\",\"type\":\"uuid\"},\"min\":0}},\"enabled\":{\"type\":{\"key\":\"boolean\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"load_balancer\":{\"type\":{\"key\":{\"refTable\":\"Load_Balancer\",\"refType\":\"weak\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"load_balancer_group\":{\"type\":{\"key\":{\"refTable\":\"Load_Balancer_Group\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"name\":{\"type\":\"string\"},\"nat\":{\"type\":{\"key\":{\"refTable\":\"NAT\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"policies\":{\"type\":{\"key\":{\"refTable\":\"Logical_Router_Policy\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"ports\":{\"type\":{\"key\":{\"refTable\":\"Logical_Router_Port\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"static_routes\":{\"type\":{\"key\":{\"refTable\":\"Logical_Router_Static_Route\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}}},\"isRoot\":true},\"Logical_Router_Policy\":{\"columns\":{\"action\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"allow\",\"drop\",\"reroute\"]],\"type\":\"string\"}}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"match\":{\"type\":\"string\"},\"nexthop\":{\"type\":{\"key\":\"string\",\"min\":0}},\"nexthops\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"priority\":{\"type\":{\"key\":{\"maxInteger\":32767,\"minInteger\":0,\"type\":\"integer\"}}}}},\"Logical_Router_Port\":{\"columns\":{\"enabled\":{\"type\":{\"key\":\"boolean\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"gateway_chassis\":{\"type\":{\"key\":{\"refTable\":\"Gateway_Chassis\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"ha_chassis_group\":{\"type\":{\"key\":{\"refTable\":\"HA_Chassis_Group\",\"type\":\"uuid\"},\"min\":0}},\"ipv6_prefix\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0}},\"ipv6_ra_configs\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"mac\":{\"type\":\"string\"},\"name\":{\"type\":\"string\"},\"networks\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\"}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"peer\":{\"type\":{\"key\":\"string\",\"min\":0}}},\"indexes\":[[\"name\"]]},\"Logical_Router_Static_Route\":{\"columns\":{\"bfd\":{\"type\":{\"key\":{\"refTable\":\"BFD\",\"refType\":\"weak\",\"type\":\"uuid\"},\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"ip_prefix\":{\"type\":\"string\"},\"nexthop\":{\"type\":\"string\"},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"output_port\":{\"type\":{\"key\":\"string\",\"min\":0}},\"policy\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"dst-ip\",\"src-ip\"]],\"type\":\"string\"},\"min\":0}},\"route_table\":{\"type\":\"string\"}}},\"Logical_Switch\":{\"columns\":{\"acls\":{\"type\":{\"key\":{\"refTable\":\"ACL\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"copp\":{\"type\":{\"key\":{\"refTable\":\"Copp\",\"refType\":\"weak\",\"type\":\"uuid\"},\"min\":0}},\"dns_records\":{\"type\":{\"key\":{\"refTable\":\"DNS\",\"refType\":\"weak\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"forwarding_groups\":{\"type\":{\"key\":{\"refTable\":\"Forwarding_Group\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"load_balancer\":{\"type\":{\"key\":{\"refTable\":\"Load_Balancer\",\"refType\":\"weak\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"load_balancer_group\":{\"type\":{\"key\":{\"refTable\":\"Load_Balancer_Group\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"name\":{\"type\":\"string\"},\"other_config\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"ports\":{\"type\":{\"key\":{\"refTable\":\"Logical_Switch_Port\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"qos_rules\":{\"type\":{\"key\":{\"refTable\":\"QoS\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}}},\"isRoot\":true},\"Logical_Switch_Port\":{\"columns\":{\"addresses\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0}},\"dhcpv4_options\":{\"type\":{\"key\":{\"refTable\":\"DHCP_Options\",\"refType\":\"weak\",\"type\":\"uuid\"},\"min\":0}},\"dhcpv6_options\":{\"type\":{\"key\":{\"refTable\":\"DHCP_Options\",\"refType\":\"weak\",\"type\":\"uuid\"},\"min\":0}},\"dynamic_addresses\":{\"type\":{\"key\":\"string\",\"min\":0}},\"enabled\":{\"type\":{\"key\":\"boolean\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"ha_chassis_group\":{\"type\":{\"key\":{\"refTable\":\"HA_Chassis_Group\",\"type\":\"uuid\"},\"min\":0}},\"mirror_rules\":{\"type\":{\"key\":{\"refTable\":\"Mirror\",\"refType\":\"weak\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"name\":{\"type\":\"string\"},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"parent_name\":{\"type\":{\"key\":\"string\",\"min\":0}},\"port_security\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0}},\"tag\":{\"type\":{\"key\":{\"maxInteger\":4095,\"minInteger\":1,\"type\":\"integer\"},\"min\":0}},\"tag_request\":{\"type\":{\"key\":{\"maxInteger\":4095,\"minInteger\":0,\"type\":\"integer\"},\"min\":0}},\"type\":{\"type\":\"string\"},\"up\":{\"type\":{\"key\":\"boolean\",\"min\":0}}},\"indexes\":[[\"name\"]]},\"Meter\":{\"columns\":{\"bands\":{\"type\":{\"key\":{\"refTable\":\"Meter_Band\",\"type\":\"uuid\"},\"max\":\"unlimited\"}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"fair\":{\"type\":{\"key\":\"boolean\",\"min\":0}},\"name\":{\"type\":\"string\"},\"unit\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"kbps\",\"pktps\"]],\"type\":\"string\"}}}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"Meter_Band\":{\"columns\":{\"action\":{\"type\":{\"key\":{\"enum\":\"drop\",\"type\":\"string\"}}},\"burst_size\":{\"type\":{\"key\":{\"maxInteger\":4294967295,\"minInteger\":0,\"type\":\"integer\"}}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"rate\":{\"type\":{\"key\":{\"maxInteger\":4294967295,\"minInteger\":1,\"type\":\"integer\"}}}}},\"Mirror\":{\"columns\":{\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"filter\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"from-lport\",\"to-lport\"]],\"type\":\"string\"}}},\"index\":{\"type\":\"integer\"},\"name\":{\"type\":\"string\"},\"sink\":{\"type\":\"string\"},\"type\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"erspan\",\"gre\"]],\"type\":\"string\"}}}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"NAT\":{\"columns\":{\"allowed_ext_ips\":{\"type\":{\"key\":{\"refTable\":\"Address_Set\",\"type\":\"uuid\"},\"min\":0}},\"exempted_ext_ips\":{\"type\":{\"key\":{\"refTable\":\"Address_Set\",\"type\":\"uuid\"},\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"external_ip\":{\"type\":\"string\"},\"external_mac\":{\"type\":{\"key\":\"string\",\"min\":0}},\"external_port_range\":{\"type\":\"string\"},\"gateway_port\":{\"type\":{\"key\":{\"refTable\":\"Logical_Router_Port\",\"refType\":\"weak\",\"type\":\"uuid\"},\"min\":0}},\"logical_ip\":{\"type\":\"string\"},\"logical_port\":{\"type\":{\"key\":\"string\",\"min\":0}},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"type\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"dnat\",\"dnat_and_snat\",\"snat\"]],\"type\":\"string\"}}}}},\"NB_Global\":{\"columns\":{\"connections\":{\"type\":{\"key\":{\"refTable\":\"Connection\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"hv_cfg\":{\"type\":\"integer\"},\"hv_cfg_timestamp\":{\"type\":\"integer\"},\"ipsec\":{\"type\":\"boolean\"},\"name\":{\"type\":\"string\"},\"nb_cfg\":{\"type\":\"integer\"},\"nb_cfg_timestamp\":{\"type\":\"integer\"},\"options\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"sb_cfg\":{\"type\":\"integer\"},\"sb_cfg_timestamp\":{\"type\":\"integer\"},\"ssl\":{\"type\":{\"key\":{\"refTable\":\"SSL\",\"type\":\"uuid\"},\"min\":0}}},\"isRoot\":true,\"maxRows\":1},\"Port_Group\":{\"columns\":{\"acls\":{\"type\":{\"key\":{\"refTable\":\"ACL\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"name\":{\"type\":\"string\"},\"ports\":{\"type\":{\"key\":{\"refTable\":\"Logical_Switch_Port\",\"refType\":\"weak\",\"type\":\"uuid\"},\"max\":\"unlimited\",\"min\":0}}},\"indexes\":[[\"name\"]],\"isRoot\":true},\"QoS\":{\"columns\":{\"action\":{\"type\":{\"key\":{\"enum\":\"dscp\",\"type\":\"string\"},\"max\":\"unlimited\",\"min\":0,\"value\":{\"maxInteger\":63,\"minInteger\":0,\"type\":\"integer\"}}},\"bandwidth\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"burst\",\"rate\"]],\"type\":\"string\"},\"max\":\"unlimited\",\"min\":0,\"value\":{\"maxInteger\":4294967295,\"minInteger\":1,\"type\":\"integer\"}}},\"direction\":{\"type\":{\"key\":{\"enum\":[\"set\",[\"from-lport\",\"to-lport\"]],\"type\":\"string\"}}},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"match\":{\"type\":\"string\"},\"priority\":{\"type\":{\"key\":{\"maxInteger\":32767,\"minInteger\":0,\"type\":\"integer\"}}}}},\"SSL\":{\"columns\":{\"bootstrap_ca_cert\":{\"type\":\"boolean\"},\"ca_cert\":{\"type\":\"string\"},\"certificate\":{\"type\":\"string\"},\"external_ids\":{\"type\":{\"key\":\"string\",\"max\":\"unlimited\",\"min\":0,\"value\":\"string\"}},\"private_key\":{\"type\":\"string\"},\"ssl_ciphers\":{\"type\":\"string\"},\"ssl_protocols\":{\"type\":\"string\"}},\"maxRows\":1},\"Static_MAC_Binding\":{\"columns\":{\"ip\":{\"type\":\"string\"},\"logical_port\":{\"type\":\"string\"},\"mac\":{\"type\":\"string\"},\"override_dynamic_mac\":{\"type\":\"boolean\"}},\"indexes\":[[\"logical_port\",\"ip\"]],\"isRoot\":true}},\"version\":\"7.0.0\"}","model":"clustered","leader":true,"cid":["uuid","5b79aeaf-6f0d-4ce5-bb50-42a8af9f441a"]}}}}, id=2
2023-09-01T11:26:41Z|00017|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: send request, method="monitor_cond_since", params=["OVN_Northbound",["monid","OVN_Northbound"],{"NB_Global":[{"columns":[]}],"Load_Balancer_Health_Check":[{"columns":[]}],"Load_Balancer":[{"columns":["health_check","name"]}]},"00000000-0000-0000-0000-000000000000"], id=3
2023-09-01T11:26:41Z|00018|ovsdb_cs|DBG|unix:/var/run/ovn/ovnnb_db.sock: SERVER_MONITOR_REQUESTED -> DATA_MONITOR_COND_SINCE_REQUESTED at ../lib/ovsdb-cs.c:2014
2023-09-01T11:26:41Z|00019|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: send request, method="set_db_change_aware", params=[true], id=4
2023-09-01T11:26:41Z|00020|poll_loop|DBG|wakeup due to [POLLIN] on fd 3 (<->/var/run/ovn/ovnnb_db.sock) at ../lib/stream-fd.c:157
2023-09-01T11:26:41Z|00021|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received reply, result=[false,"c1d44c77-a138-4896-a92a-7c2733e4445e",{"NB_Global":{"1a2e24e4-8342-4bd9-866b-7f436cb56b72":{"initial":{}}},"Load_Balancer":{"cb2bc414-3fae-4072-9e20-b89ca1495650":{"initial":{"name":"vpc-vpc1-tcp-load"}},"21156c9b-b392-4db2-a1c6-7f388491add7":{"initial":{"name":"cluster-udp-session-loadbalancer"}},"c0c59fcd-9a5e-46e1-9468-2afdd5662b88":{"initial":{"name":"cluster-udp-loadbalancer"}},"7774f23a-150b-41a0-ad77-7a9a1b7c2c75":{"initial":{"name":"cluster-sctp-session-loadbalancer"}},"e3841e3a-0066-4df8-8fb6-a670f68adaaf":{"initial":{"name":"cluster-sctp-loadbalancer"}},"e1c7afb1-fa6a-4f19-8ad9-c122ba51ad30":{"initial":{"name":"vpc-vpc1-udp-load"}},"d277edaf-3fc2-47b3-92fa-4a7dce19050c":{"initial":{"name":"vpc-vpc1-sctp-sess-load"}},"38829365-b3a6-4e96-8e15-e9e873aed105":{"initial":{"name":"cluster-tcp-loadbalancer"}},"258e0370-ef82-4ea2-8227-68554ff74104":{"initial":{"name":"vpc-vpc1-udp-sess-load"}},"9db78d80-7213-4f0c-918e-4886460462ab":{"initial":{"name":"cluster-tcp-session-loadbalancer"}},"c84b2828-43b0-4a1a-9c2c-f18329dc63d4":{"initial":{"name":"vpc-vpc1-sctp-load"}},"f009248c-a43d-4c8b-8c44-11fbbfa8adb9":{"initial":{"name":"vpc-vpc1-tcp-sess-load"}}}}], id=3
2023-09-01T11:26:41Z|00022|ovsdb_cs|DBG|unix:/var/run/ovn/ovnnb_db.sock: DATA_MONITOR_COND_SINCE_REQUESTED -> MONITORING at ../lib/ovsdb-cs.c:496
2023-09-01T11:26:41Z|00023|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received reply, result={}, id=4
2023-09-01T11:26:41Z|00024|ovsdb_cs|DBG|unix:/var/run/ovn/ovnnb_db.sock: received unexpected reply message: {"error":null,"id":4,"result":{}}
2023-09-01T11:26:41Z|00025|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: send request, method="transact", params=["OVN_Northbound",{"where":[["_uuid","==",["uuid","f009248c-a43d-4c8b-8c44-11fbbfa8adb9"]]],"table":"Load_Balancer","timeout":0,"op":"wait","rows":[{"health_check":["set",[]]}],"columns":["health_check"],"until":"=="},{"row":{"health_check":["named-uuid","rowd43e3f59_1cc5_468c_8286_b2a9a785012c"]},"where":[["_uuid","==",["uuid","f009248c-a43d-4c8b-8c44-11fbbfa8adb9"]]],"table":"Load_Balancer","op":"update"},{"row":{"vip":"10.1.0.100:80"},"table":"Load_Balancer_Health_Check","op":"insert","uuid-name":"rowd43e3f59_1cc5_468c_8286_b2a9a785012c"},{"op":"comment","comment":"ovn-nbctl: ovn-nbctl -v --id=@hc create Load_Balancer_Health_Check \"vip=10.1.0.100\\\\:80\" -- add Load_Balancer f009248c-a43d-4c8b-8c44-11fbbfa8adb9 health_check @hc"}], id=5
2023-09-01T11:26:41Z|00026|poll_loop|DBG|wakeup due to [POLLIN] on fd 3 (<->/var/run/ovn/ovnnb_db.sock) at ../lib/stream-fd.c:157
2023-09-01T11:26:41Z|00027|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received notification, method="update3", params=[["monid","OVN_Northbound"],"12381c9a-3de2-414d-8f1d-d1d15bf7f557",{"Load_Balancer_Health_Check":{"7fe2382a-9569-439a-916c-cc28436a2cf8":{"insert":{}}},"Load_Balancer":{"f009248c-a43d-4c8b-8c44-11fbbfa8adb9":{"modify":{"health_check":["uuid","7fe2382a-9569-439a-916c-cc28436a2cf8"]}}}}]
2023-09-01T11:26:41Z|00028|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received notification, method="update2", params=[["monid","_Server"],{"Database":{"47814892-c603-4410-bec1-a0929fe4da5f":{"modify":{"index":139}}}}]
2023-09-01T11:26:41Z|00029|jsonrpc|DBG|unix:/var/run/ovn/ovnnb_db.sock: received reply, result=[{},{"count":1},{"uuid":["uuid","7fe2382a-9569-439a-916c-cc28436a2cf8"]},{}], id=5
2023-09-01T11:26:41Z|00030|poll_loop|DBG|wakeup due to 0-ms timeout at ../lib/ovsdb-idl.c:2818
+ health_check_id=7fe2382a-9569-439a-916c-cc28436a2cf8
注意关注 request 部分
json 解析后
["OVN_Northbound", {
"where": [
["_uuid", "==", ["uuid", "f009248c-a43d-4c8b-8c44-11fbbfa8adb9"]]
],
"table": "Load_Balancer",
"timeout": 0,
"op": "wait", # 1. wait 条件操作
"rows": [{
"health_check": ["set", []]
}],
"columns": ["health_check"],
"until": "=="
}, {
"row": {
"health_check": ["named-uuid", "rowd43e3f59_1cc5_468c_8286_b2a9a785012c"]
},
"where": [
["_uuid", "==", ["uuid", "f009248c-a43d-4c8b-8c44-11fbbfa8adb9"]]
],
"table": "Load_Balancer",
"op": "update" # 2. 更新资源操作: 更新已有的一个 LB(数据库中的一行)资源的 health_check 键的值
}, {
"row": {
"vip": "10.1.0.100:80"
},
"table": "Load_Balancer_Health_Check",
"op": "insert",
"uuid-name": "rowd43e3f59_1cc5_468c_8286_b2a9a785012c"
}, {
"op": "comment", # 3. 新增资源操作: 新增一个 lb 健康检查
"comment": "ovn-nbctl: ovn-nbctl -v --id=@hc create Load_Balancer_Health_Check \"vip=10.1.0.100\\\\:80\" -- add Load_Balancer f009248c-a43d-4c8b-8c44-11fbbfa8adb9 health_check @hc"
}]
可以看到 已经存在的资源 lb,用的是 uuid, 而 未将要创建的资源 lbhc 是一个 "named-uuid", "rowd43e3f59_1cc5_468c_8286_b2a9a785012c" 的东西 这个值在创建时和被 lb 引用更新时都有用到
(.venv) root@empty:~/test/kube-ovn/health-check# ./show
kubectl ko nbctl find Load_Balancer name=vpc-vpc1-tcp-sess-load
_uuid : f009248c-a43d-4c8b-8c44-11fbbfa8adb9
external_ids : {}
health_check : [7fe2382a-9569-439a-916c-cc28436a2cf8]
ip_port_mappings : {"10.1.0.5"="netshoot-1.ns1:10.1.0.100", "10.1.0.6"="netshoot-2.ns1:10.1.0.100"}
name : vpc-vpc1-tcp-sess-load
options : {affinity_timeout="10800"}
protocol : tcp
selection_fields : [ip_src]
vips : {"10.1.0.100:80"="10.1.0.5:8000,10.1.0.6:8000"}
kubectl ko nbctl list Load_Balancer_Health_Check
# 可以看到这里的值并不是上面的临时值 rowd43e3f59_1cc5_468c_8286_b2a9a785012c
_uuid : 7fe2382a-9569-439a-916c-cc28436a2cf8
external_ids : {}
options : {failure_count="3", interval="5", success_count="3", timeout="20"}
vip : "10.1.0.100:80"
kubectl ko sbctl list Service_Monitor
_uuid : 80809354-721c-4d78-8678-fea9c9b7a312
external_ids : {}
ip : "10.1.0.5"
logical_port : netshoot-1.ns1
options : {failure_count="3", interval="5", success_count="3", timeout="20"}
port : 8000
protocol : tcp
src_ip : "10.1.0.100"
src_mac : "22:5b:cb:01:d5:e0"
status : online
_uuid : c332ff5f-1221-40d2-89f0-d413ead46559
external_ids : {}
ip : "10.1.0.6"
logical_port : netshoot-2.ns1
options : {failure_count="3", interval="5", success_count="3", timeout="20"}
port : 8000
protocol : tcp
src_ip : "10.1.0.100"
src_mac : "22:5b:cb:01:d5:e0"
status : online
所以这个创建过程 没有提前用 指定的 uuid, 反而用过程中的 临时 row+uuid 值
关于如何使用 Wait 条件
# /root/mst/libovsdb/client/api.go
func (a api) Wait(untilConFun ovsdb.WaitCondition, timeout *int, model model.Model, fields ...interface{}) ([]ovsdb.Operation, error) {
var operations []ovsdb.Operation
/*
Ref: https://datatracker.ietf.org/doc/html/rfc7047.txt#section-5.2.6
lb := &nbdb.LoadBalancer{}
condition := model.Condition{
Field: &lb.Name,
Function: ovsdb.ConditionEqual,
Value: "lbName",
}
timeout0 := 0
client.Where(lb, condition).Wait(
// 这个示例是有问题的,目前 Where 仅支持一个参数
ovsdb.WaitConditionNotEqual, // Until
&timeout0, // Timeout
&lb, // Row (and Table)
&lb.Name, // Cols (aka fields)
)
*/
5.2.6. Wait
The "wait" object contains the following members:
`wait` 对象包含以下成员参数:
"op": "wait" required
"timeout": <integer> optional
"table": <table> required
"where": [<condition>*] required
"columns": [<column>*] required
"until": "==" or "!=" required
"rows": [<row>*] required
There is no corresponding result object.
The operation waits until a condition becomes true.
没有对应的结果对象。 该操作会等待,直到条件变为真。
lb := &nbdb.LoadBalancer{}
condition := model.Condition{
Field: &lb.Name,
Function: ovsdb.ConditionEqual,
Value: "lbName",
}
timeout0 := 0
client.Where(lb, condition).Wait(
ovsdb.WaitConditionNotEqual, // Until
&timeout0, // Timeout
&lb, // Row (and Table)
&lb.Name, // Cols (aka fields)
)
If "until" is "==", it checks whether the query on "table" specified by "where" and "columns", which is evaluated in the same way as specified for "select", returns the result set specified by "rows".
如果“until”为“==”,则检查“where”和“columns”指定的“table”查询是否返回“select”指定的结果集,该查询的计算方式与“select”指定的相同行”。
比如这个例子: client.Where 中指定 table 相当于 select 语句,select 的判断条件为 “==”,select 到“行记录” 之后,可以在client.Where.Wait之后调用Update函数,即 client.Where.Wait.Update
If it does, then the operation completes successfully. Otherwise, the entire transaction rolls back. It is automatically restarted later, after a change in the database makes it possible for the operation to succeed. The client will not receive a response until the operation permanently succeeds or fails.
如果select 条件有匹配到,则操作最终可成功完成。否则,整个事务将回滚。
当数据库中的更改使得操作成功后,它会在稍后自动重新启动。
在操作永久成功或失败之前,客户端不会收到响应。
If "until" is "!=", the sense of the test is negated. That is, as
long as the query on "table" specified by "where" and "columns"
returns "rows", the transaction will be rolled back and restarted
later.
如果“until”是“!=”,则测试的意义被否定。
也就是说,只要对“where”和“columns”指定的“表”进行查询返回“行”,事务就会回滚并稍后重新启动。
If "timeout" is specified, then the transaction aborts after the
specified number of milliseconds. The transaction is guaranteed to
be attempted at least once before it aborts. A "timeout" of 0 will
abort the transaction on the first mismatch.
如果指定“超时”,则事务将在指定的毫秒数后中止。
保证事务在中止之前至少尝试一次。 “超时”为 0 将在第一次不匹配时中止事务。
如果超时了,会返回如下错误。
The error that may be returned is:
"error": "timed out"
The "timeout" was reached before the transaction was able to
complete.
2. nat 操作
k ko nbctl -v -- --id=@nat create nat type="snat" logical_ip=10.1.0.0/24 external_ip=10.2.0.100 -- add logical_router vpc1 nat @nat
["OVN_Northbound", {
"where": [
["_uuid", "==", ["uuid", "db2048f4-213e-4f6f-aa16-67135d169935"]]
],
"table": "Logical_Router",
"timeout": 0,
"op": "wait",
"rows": [{
"nat": ["uuid", "5ae55c30-9735-4ca4-8d78-4f4abb7759e5"]
}],
"columns": ["nat"],
"until": "=="
}, {
"row": {
"nat": ["set", [
["uuid", "5ae55c30-9735-4ca4-8d78-4f4abb7759e5"],
["named-uuid", "rowa8b54e5d_b042_4577_b950_6c03b46777c6"]
]]
},
"where": [
["_uuid", "==", ["uuid", "db2048f4-213e-4f6f-aa16-67135d169935"]]
],
"table": "Logical_Router",
"op": "update"
}, {
"row": {
"type": "snat",
"external_ip": "10.2.0.100",
"logical_ip": "10.1.0.0/24"
},
"table": "NAT",
"op": "insert",
"uuid-name": "rowa8b54e5d_b042_4577_b950_6c03b46777c6"
}, {
"op": "comment",
"comment": "ovn-nbctl: ovn-nbctl -v -- --id=@nat create nat type=snat logical_ip=10.1.0.0/24 external_ip=10.2.0.100 -- add logical_router vpc1 nat @nat"
}]
目前认为 wait 这个 op 根本就不需要做,因为 kube-ovn 的 NAT 是没有的,而且配置完毕后,网络是通的。。