Commit cd0ddf10 authored by Yan Zhu's avatar Yan Zhu
Browse files

ipset exclude cluster service ip range

parent 5de6ceb5
master 1.1-dev acl acl-doc add_unknown_to_lsp allow-subnet arm bandwidth base/enable-dbg centralized-policy-route centralized_nat chore/build-ovs chore/bump-release chore/coc-roadmap chore/crd-to-v1 chore/gomod chore/merge-image chore/ovs-vsctl-log chore/remove-networks-crd chore/render-kind-yaml chore/show-gw-error chore/size chore/update-ovn ci/arm-pr ci/base ci/base-update ci/improvement ci/ipv6 ci/no-pr-push ci/retry ci/trivy ci/ubuntu-version ci/update-kind cni core/ovn-update crd-print db-monitor debug delete-qos delete-qos-queue delete_ip dev/2.13 doc/custom-kubeconfig doc/optimization doc/vip docs/1.0-pre docs/corigine docs/dpdk-pod-name docs/iface-ic docs/internal-port-vlan docs/namespace docs/optimize docs/optimize-cilium docs/prequest docs/prerequest docs/update-readme dualstack dualstack_merge ecmp ecmp_static_route encap-ip env-check fdb feat/add-lint feat/admission-controller1 feat/auto-gw feat/bgp feat/clean-build feat/controller-metrics feat/dev-image feat/disable-ping-check feat/distribute-eip feat/format-subnet feat/github-action feat/grafana feat/gw feat/gw-ha feat/ip-crd feat/ipv6 feat/keep-chassis-name feat/ko feat/kubectl-plugin feat/log feat/mcast feat/mirror feat/multi-nic feat/multicast feat/namespace-annotation feat/network-policy feat/ovn-ic feat/pinger feat/remove-cluster-ip feat/select-leader-by-label feat/session-lb feat/set-kernel-args feat/sfc feat/ssl feat/subnet-crd feat/subnet-status feat/update-ovn feat/vlan-geneve feat/vlan-regex feat/vpc-lb fix-base fix-dnat fix-resubmit-limit fix/acl fix/acl-issues fix/avx512 fix/bad-prefix-error fix/check-crd fix/check-special-subnet fix/cleanup fix/controller-keepalive fix/dns-delay fix/duplicate-ifaceid fix/ecmp-hash fix/error-log fix/forward-accept fix/gc-resource fix/gw-del fix/host-missing-cluster-ip-router fix/ic-restart fix/init-bugs fix/init-ping fix/iptables fix/ipv6-connection fix/ipv6-svc fix/ko-tcpdump fix/metrics-name fix/missing-condition fix/missing-date fix/nbctl-timeout fix/node-acl fix/np-log fix/offline-remove fix/ovn-cluster fix/ovn-healthcheck fix/ovn-northd-flipflop fix/pod-del fix/provider-check fix/recycle-evicted-pod fix/remove-clusteradmin fix/remove-privillege fix/reset-ovn0 fix/service-name-port fix/src-priority fix/sriov-issues fix/subnet-not-exists fix/subnet-without-protocol fix/udp-checksum fix/uninstall fix/update-lost fix/vlan-del fix_make_kind_reload gc-vm-lsp internal-port internal_port internal_tcpdump ip ipam join klog/v2 log/rotate ls-dnat-mod-dl-dst lsp-address lsp-ipam mahz-master merge-vlan monitor/metrics monitor/pinger-metrics monitor_db_con multus multus-cni-update namespace nat-gw nbctl networkpolicy nodeport np_master ns-subnet ovn-controller ovn-db-recover ovs-nonstop ovs-win64-ci perf/4.18 perf/alias perf/libovsdb perf/optimization perf/policy-route perf/recycle-pod-early perf/route-port-address perf/skip-evicted-pod perf/stt perf/tuning-guide poc policy-route policy-route-1.8 port-group push-img qos qos-e2e qos-query refactor/controller refactor/other_config refactor/pod-control refactor/pod-controller reflactor_note release-0.10 release-0.9 release-0.9.0 release-1.0 release-1.10 release-1.2 release-1.3 release-1.4 release-1.5 release-1.5-vpc release-1.5.2 release-1.6 release-1.7 release-1.8 release-1.8-kubevirt release-1.8-lint release-1.8-monitor release-1.9 release-1.9-monitor release/0.7.0 release/1.1 release/prepare-1.9 remove_no_need_parms_svcAsName restore revert-1094-vpc-lb revert-1264-yd-master revert-1309-fixcni revert-395-perf/policy-route revert-397-fix/ipv6-route revert-399-fix/as-inconsist security/ubuntu-update security/update-ubuntu sg-acl stspod subnet subnet_ips svc sync-ovn-db test/fix-flaky testing update-ovs update/1.7-1.8 update/1.8.2 update_version upgrade-ovs vlan vm-migrate vm-static-ip vpc-nat-gw webhook v1.10.7 v1.10.6 v1.10.5 v1.10.4 v1.10.3 v1.10.2 v1.10.1 v1.10.0 v1.9.14 v1.9.13 v1.9.12 v1.9.10 v1.9.9 v1.9.8 v1.9.7 v1.9.6 v1.9.5 v1.9.4 v1.9.3 v1.9.2 v1.9.1 v1.9.0 v1.8.14 v1.8.12 v1.8.11 v1.8.9 v1.8.8 v1.8.7 v1.8.6 v1.8.5 v1.8.4 v1.8.3 v1.8.2 v1.8.1 v1.8.0 v1.7.3 v1.7.2 v1.7.1 v1.7.0 v1.6.3 v1.6.2 v1.6.1 v1.6.0 v1.5.2 v1.5.1 v1.5.0 v1.4.0 v1.3.0 v1.2.1 v1.2.0 v1.1.1 v1.1.0 v1.0.1 v1.0.0 v0.10.2 v0.10.1 v0.10.0 v0.9.1 v0.9.0 v0.8.0 v0.7.0 v0.6.0 v0.5.0 v0.4.1 v0.4.0 v0.3.0 v0.2.0 v
No related merge requests found
Showing with 51 additions and 37 deletions
+51 -37
......@@ -13,31 +13,33 @@ import (
)
type Configuration struct {
BindSocket string
OvsSocket string
KubeConfigFile string
KubeClient kubernetes.Interface
NodeName string
OvnNbHost string
OvnNbPort int
OvnSbHost string
OvnSbPort int
ClusterRouter string
NodeSwitch string
BindSocket string
OvsSocket string
KubeConfigFile string
KubeClient kubernetes.Interface
NodeName string
OvnNbHost string
OvnNbPort int
OvnSbHost string
OvnSbPort int
ClusterRouter string
NodeSwitch string
ServiceClusterIPRange string
}
// TODO: validate configuration
func ParseFlags() (*Configuration, error) {
var (
argBindSocket = pflag.String("bind-socket", "/var/run/cniserver.sock", "The socket daemon bind to.")
argOvsSocket = pflag.String("ovs-socket", "", "The socket to local ovs-server")
argKubeConfigFile = pflag.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information. If not set use the inCluster token.")
argOvnNbHost = pflag.String("ovn-nb-host", "", "")
argOvnNbPort = pflag.Int("ovn-nb-port", 6641, "")
argOvnSbHost = pflag.String("ovn-sb-host", "", "")
argOvnSbPort = pflag.Int("ovn-sb-port", 6642, "")
argClusterRouter = pflag.String("cluster-router", "ovn-cluster", "The router name for cluster router.Default: cluster-router")
argNodeSwitch = pflag.String("node-switch", "join", "The name of node gateway switch which help node to access pod network. Default: join")
argBindSocket = pflag.String("bind-socket", "/var/run/cniserver.sock", "The socket daemon bind to.")
argOvsSocket = pflag.String("ovs-socket", "", "The socket to local ovs-server")
argKubeConfigFile = pflag.String("kubeconfig", "", "Path to kubeconfig file with authorization and master location information. If not set use the inCluster token.")
argOvnNbHost = pflag.String("ovn-nb-host", "", "")
argOvnNbPort = pflag.Int("ovn-nb-port", 6641, "")
argOvnSbHost = pflag.String("ovn-sb-host", "", "")
argOvnSbPort = pflag.Int("ovn-sb-port", 6642, "")
argClusterRouter = pflag.String("cluster-router", "ovn-cluster", "The router name for cluster router.Default: cluster-router")
argNodeSwitch = pflag.String("node-switch", "join", "The name of node gateway switch which help node to access pod network. Default: join")
argServiceClusterIPRange = pflag.String("service-cluster-ip-range", "10.96.0.0/12", "The kubernetes service cluster ip range")
)
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
......@@ -62,16 +64,17 @@ func ParseFlags() (*Configuration, error) {
}
config := &Configuration{
BindSocket: *argBindSocket,
OvsSocket: *argOvsSocket,
KubeConfigFile: *argKubeConfigFile,
NodeName: nodeName,
OvnNbHost: *argOvnNbHost,
OvnNbPort: *argOvnNbPort,
OvnSbHost: *argOvnSbHost,
OvnSbPort: *argOvnSbPort,
ClusterRouter: *argClusterRouter,
NodeSwitch: *argNodeSwitch,
BindSocket: *argBindSocket,
OvsSocket: *argOvsSocket,
KubeConfigFile: *argKubeConfigFile,
NodeName: nodeName,
OvnNbHost: *argOvnNbHost,
OvnNbPort: *argOvnNbPort,
OvnSbHost: *argOvnSbHost,
OvnSbPort: *argOvnSbPort,
ClusterRouter: *argClusterRouter,
NodeSwitch: *argNodeSwitch,
ServiceClusterIPRange: *argServiceClusterIPRange,
}
err := config.initKubeClient()
if err != nil {
......
......@@ -13,9 +13,9 @@ import (
const (
SubnetSet = "subnets"
LocalPodSet = "local-pod-ip"
LocalPodSet = "local-pod-ip-nat"
IPSetPrefix = "ovn"
NATRule = "-m set --match-set ovn40local-pod-ip src -m set ! --match-set ovn40subnets dst -j MASQUERADE"
NATRule = "-m set --match-set ovn40local-pod-ip-nat src -m set ! --match-set ovn40subnets dst -j MASQUERADE"
)
func (c *Controller) runGateway(stopCh <-chan struct{}) error {
......@@ -25,7 +25,7 @@ func (c *Controller) runGateway(stopCh <-chan struct{}) error {
klog.Errorf("get subnets failed, %+v", err)
return err
}
localPodIPs, err := c.getLocalPodIPs()
localPodIPs, err := c.getLocalPodIPsNeedNAT()
if err != nil {
klog.Errorf("get local pod ips failed, %+v", err)
return err
......@@ -70,7 +70,7 @@ LOOP:
klog.Errorf("get subnets failed, %+v", err)
continue
}
localPodIPs, err := c.getLocalPodIPs()
localPodIPs, err := c.getLocalPodIPsNeedNAT()
if err != nil {
klog.Errorf("get local pod ips failed, %+v", err)
continue
......@@ -91,7 +91,7 @@ LOOP:
return nil
}
func (c *Controller) getLocalPodIPs() ([]string, error) {
func (c *Controller) getLocalPodIPsNeedNAT() ([]string, error) {
var localPodIPs []string
hostname, _ := os.Hostname()
allPods, err := c.podsLister.List(labels.Everything())
......@@ -101,7 +101,18 @@ func (c *Controller) getLocalPodIPs() ([]string, error) {
}
for _, pod := range allPods {
if pod.Spec.NodeName == hostname && pod.Spec.HostNetwork != true && pod.Status.PodIP != "" {
localPodIPs = append(localPodIPs, pod.Status.PodIP)
ns, err := c.namespacesLister.Get(pod.Namespace)
if err != nil {
klog.Errorf("get ns %s failed, %+v", pod.Namespace, err)
continue
}
nsGWType := ns.Annotations[util.GWTypeAnnotation]
switch nsGWType {
case "", util.GWDistributedMode:
localPodIPs = append(localPodIPs, pod.Status.PodIP)
case util.GWCentralizedMode:
// TODO:
}
}
}
klog.V(5).Infof("local pod ips %v", localPodIPs)
......@@ -109,7 +120,7 @@ func (c *Controller) getLocalPodIPs() ([]string, error) {
}
func (c *Controller) getSubnets() ([]string, error) {
var subnets []string
var subnets = []string{c.config.ServiceClusterIPRange}
allNamespaces, err := c.namespacesLister.List(labels.Everything())
if err != nil {
klog.Errorf("list namespaces failed, %+v", err)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment