一、前言
Openshift基于OVS SDN的CNI网络方案具有一个以etcd key-value store为中心master节点和若干worker节点,Openshift SDN master在etcd维护一个worker节点和SDN网络相关的数据库。
master主要的责任如下:
- 当Openshift加入或者删除一个worker节点,master会监听到这个事件,为这个节点分配或者收回子网段,将子网信息存储到etcd该node对应的entry下面。
- 在ovs-multitenant模式下,master还会监听project的建立和删除事件,为project分配VxLAN VNID,并且存储到etcd里面。
载自https://blog.csdn.net/cloudvtech
二、代码分析(Openshift origin v1.5)
1. Openshift master启动SDN master
- Start() @ origin/pkg/cmd/server/start/start_master.go
- startControllers() @ origin/pkg/cmd/server/start/start_master.go
- oc.RunSDNController() @ origin/pkg/cmd/server/start/start_master.go
- RunSDNController @ origin/pkg/cmd/server/origin/run_components.go
- StartMaster @ /Users/hairchen/Desktop/origin/pkg/sdn/plugin/master.go
2.SDN master启动流程
2.1 parse network info to get clusterNetwork and serviceNetwork
2.2 create clusterNetwork
cn, err := master.osClient.ClusterNetwork().Create(cn)
2.3 start subnet manager
2.3.1 get host subnet from Openshift
2.3.2 initialize a SubnetAllocator
2.3.3 start node change handling loop
2.3.3.1
2.3.3.2 handling node add event from K8S
2.3.3.2.1 Validate node IP before proceeding
2.3.3.2.2 Check if subnet needs to be created or updated
2.3.3.2.3 Create new subnet in K8S
![](https://i-blog.csdnimg.cn/blog_migrate/139c881ffdfc79c9ceae9d2e8322138a.png)
2.3.3.3 handling node delete event from K8S
2.3.4 start subnet change handling loop
2.3.4.1
![](https://i-blog.csdnimg.cn/blog_migrate/2f6a891540e4a7e1ff6a6fd8337f21a7.png)
2.3.4.2 handling host subnet add event from K8S
2.3.4.2.1 delete old subnet first
2.3.4.2.2 go through add node action as (3.3.2.1~3.3.2.3)
2.3.4.2 handling host subnet delete event from K8S
载自https://blog.csdn.net/cloudvtech