Skip to content

Commit 1c7866c

Browse files
andrewsykimmurali-reddy
authored andcommitted
Allow CNI plugin to be disabled (#443)
1 parent 5e4ca29 commit 1c7866c

File tree

4 files changed

+159
-26
lines changed

4 files changed

+159
-26
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
apiVersion: extensions/v1beta1
3+
kind: DaemonSet
4+
metadata:
5+
labels:
6+
k8s-app: kube-router
7+
tier: node
8+
name: kube-router
9+
namespace: kube-system
10+
spec:
11+
template:
12+
metadata:
13+
labels:
14+
k8s-app: kube-router
15+
tier: node
16+
annotations:
17+
scheduler.alpha.kubernetes.io/critical-pod: ''
18+
spec:
19+
serviceAccountName: kube-router
20+
containers:
21+
- name: kube-router
22+
image: cloudnativelabs/kube-router
23+
imagePullPolicy: Always
24+
args:
25+
- "--run-router=true"
26+
- "--run-firewall=false"
27+
- "--run-service-proxy=false"
28+
- "--enable-cni=false"
29+
- "--enable-ibgp=false"
30+
- "--enable-overlay=false"
31+
- "--peer-router-ips=<CHANGE ME>"
32+
- "--peer-router-asns=<CHANGE ME>"
33+
- "--cluster-asn=<CHANGE ME>"
34+
- "--advertise-cluster-ip=true"
35+
- "--advertise-external-ip=true"
36+
- "--advertise-loadbalancer-ip=true"
37+
env:
38+
- name: NODE_NAME
39+
valueFrom:
40+
fieldRef:
41+
fieldPath: spec.nodeName
42+
livenessProbe:
43+
httpGet:
44+
path: /healthz
45+
port: 20244
46+
initialDelaySeconds: 10
47+
periodSeconds: 3
48+
resources:
49+
requests:
50+
cpu: 250m
51+
memory: 250Mi
52+
securityContext:
53+
privileged: true
54+
hostNetwork: true
55+
tolerations:
56+
- key: CriticalAddonsOnly
57+
operator: Exists
58+
- effect: NoSchedule
59+
key: node-role.kubernetes.io/master
60+
operator: Exists
61+
62+
---
63+
apiVersion: v1
64+
kind: ServiceAccount
65+
metadata:
66+
name: kube-router
67+
namespace: kube-system
68+
69+
---
70+
kind: ClusterRole
71+
apiVersion: rbac.authorization.k8s.io/v1beta1
72+
metadata:
73+
name: kube-router
74+
namespace: kube-system
75+
rules:
76+
- apiGroups:
77+
- ""
78+
resources:
79+
- namespaces
80+
- pods
81+
- services
82+
- nodes
83+
- endpoints
84+
verbs:
85+
- list
86+
- get
87+
- watch
88+
- apiGroups:
89+
- "networking.k8s.io"
90+
resources:
91+
- networkpolicies
92+
verbs:
93+
- list
94+
- get
95+
- watch
96+
- apiGroups:
97+
- extensions
98+
resources:
99+
- networkpolicies
100+
verbs:
101+
- get
102+
- list
103+
- watch
104+
105+
---
106+
kind: ClusterRoleBinding
107+
apiVersion: rbac.authorization.k8s.io/v1beta1
108+
metadata:
109+
name: kube-router
110+
roleRef:
111+
apiGroup: rbac.authorization.k8s.io
112+
kind: ClusterRole
113+
name: kube-router
114+
subjects:
115+
- kind: ServiceAccount
116+
name: kube-router
117+
namespace: kube-system

docs/user-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Usage of kube-router:
3434
--cleanup-config Cleanup iptables rules, ipvs, ipset configuration and exit.
3535
--cluster-asn uint ASN number under which cluster nodes will run iBGP.
3636
--cluster-cidr string CIDR range of pods in the cluster. It is used to identify traffic originating from and destinated to pods.
37+
--enable-cni Enable CNI plugin. Disable if you want to use kube-router features alongside another CNI plugin. (default true)
3738
--enable-ibgp Enables peering with nodes with the same ASN, if disabled will only peer with external BGP peers (default true)
3839
--enable-overlay When enable-overlay set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastrcture is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true)
3940
--enable-pod-egress SNAT traffic from Pods to destinations outside the cluster. (default true)

pkg/controllers/routing/network_routes_controller.go

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type NetworkRoutingController struct {
7272
nodeAsnNumber uint32
7373
globalPeerRouters []*config.NeighborConfig
7474
nodePeerRouters []string
75+
enableCNI bool
7576
bgpFullMeshMode bool
7677
bgpEnableInternal bool
7778
bgpGracefulRestart bool
@@ -98,26 +99,9 @@ type NetworkRoutingController struct {
9899

99100
// Run runs forever until we are notified on stop channel
100101
func (nrc *NetworkRoutingController) Run(healthChan chan<- *healthcheck.ControllerHeartbeat, stopCh <-chan struct{}, wg *sync.WaitGroup) {
101-
cidr, err := utils.GetPodCidrFromCniSpec(nrc.cniConfFile)
102-
if err != nil {
103-
glog.Errorf("Failed to get pod CIDR from CNI conf file: %s", err.Error())
104-
}
105-
if reflect.DeepEqual(cidr, net.IPNet{}) {
106-
glog.Infof("`subnet` in CNI conf file is empty so populating `subnet` in CNI conf file with pod CIDR assigned to the node obtained from node spec.")
107-
}
108-
cidrlen, _ := cidr.Mask.Size()
109-
oldCidr := cidr.IP.String() + "/" + strconv.Itoa(cidrlen)
110-
111-
currentCidr, err := utils.GetPodCidrFromNodeSpec(nrc.clientset, nrc.hostnameOverride)
112-
if err != nil {
113-
glog.Fatalf("Failed to get pod CIDR from node spec. kube-router relies on kube-controller-manager to allocate pod CIDR for the node. Error: %v", err.Error())
114-
}
115-
116-
if len(cidr.IP) == 0 || strings.Compare(oldCidr, currentCidr) != 0 {
117-
err = utils.InsertPodCidrInCniSpec(nrc.cniConfFile, currentCidr)
118-
if err != nil {
119-
glog.Fatalf("Failed to insert `subnet`(pod CIDR) into CNI conf file: %s", err.Error())
120-
}
102+
var err error
103+
if nrc.enableCNI {
104+
nrc.updateCNIConfig()
121105
}
122106

123107
glog.V(1).Info("Populating ipsets.")
@@ -284,6 +268,31 @@ func (nrc *NetworkRoutingController) Run(healthChan chan<- *healthcheck.Controll
284268
}
285269
}
286270

271+
func (nrc *NetworkRoutingController) updateCNIConfig() {
272+
cidr, err := utils.GetPodCidrFromCniSpec(nrc.cniConfFile)
273+
if err != nil {
274+
glog.Errorf("Failed to get pod CIDR from CNI conf file: %s", err)
275+
}
276+
277+
if reflect.DeepEqual(cidr, net.IPNet{}) {
278+
glog.Infof("`subnet` in CNI conf file is empty so populating `subnet` in CNI conf file with pod CIDR assigned to the node obtained from node spec.")
279+
}
280+
cidrlen, _ := cidr.Mask.Size()
281+
oldCidr := cidr.IP.String() + "/" + strconv.Itoa(cidrlen)
282+
283+
currentCidr, err := utils.GetPodCidrFromNodeSpec(nrc.clientset, nrc.hostnameOverride)
284+
if err != nil {
285+
glog.Fatalf("Failed to get pod CIDR from node spec. kube-router relies on kube-controller-manager to allocate pod CIDR for the node or an annotation `kube-router.io/pod-cidr`. Error: %v", err)
286+
}
287+
288+
if len(cidr.IP) == 0 || strings.Compare(oldCidr, currentCidr) != 0 {
289+
err = utils.InsertPodCidrInCniSpec(nrc.cniConfFile, currentCidr)
290+
if err != nil {
291+
glog.Fatalf("Failed to insert `subnet`(pod CIDR) into CNI conf file: %s", err.Error())
292+
}
293+
}
294+
}
295+
287296
func (nrc *NetworkRoutingController) watchBgpUpdates() {
288297
watcher := nrc.bgpServer.Watch(gobgp.WatchBestPath(false))
289298
for {
@@ -704,6 +713,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
704713
}
705714

706715
nrc.bgpFullMeshMode = kubeRouterConfig.FullMeshMode
716+
nrc.enableCNI = kubeRouterConfig.EnableCNI
707717
nrc.bgpEnableInternal = kubeRouterConfig.EnableiBGP
708718
nrc.bgpGracefulRestart = kubeRouterConfig.BGPGracefulRestart
709719
nrc.peerMultihopTTL = kubeRouterConfig.PeerMultihopTtl
@@ -719,12 +729,14 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
719729
// lets start with assumption we hace necessary IAM creds to access EC2 api
720730
nrc.ec2IamAuthorized = true
721731

722-
nrc.cniConfFile = os.Getenv("KUBE_ROUTER_CNI_CONF_FILE")
723-
if nrc.cniConfFile == "" {
724-
nrc.cniConfFile = "/etc/cni/net.d/10-kuberouter.conf"
725-
}
726-
if _, err := os.Stat(nrc.cniConfFile); os.IsNotExist(err) {
727-
return nil, errors.New("CNI conf file " + nrc.cniConfFile + " does not exist.")
732+
if nrc.enableCNI {
733+
nrc.cniConfFile = os.Getenv("KUBE_ROUTER_CNI_CONF_FILE")
734+
if nrc.cniConfFile == "" {
735+
nrc.cniConfFile = "/etc/cni/net.d/10-kuberouter.conf"
736+
}
737+
if _, err := os.Stat(nrc.cniConfFile); os.IsNotExist(err) {
738+
return nil, errors.New("CNI conf file " + nrc.cniConfFile + " does not exist.")
739+
}
728740
}
729741

730742
nrc.ipSetHandler, err = utils.NewIPSet()

pkg/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type KubeRouterConfig struct {
1616
CleanupConfig bool
1717
ClusterAsn uint
1818
ClusterCIDR string
19+
EnableCNI bool
1920
EnableiBGP bool
2021
EnableOverlay bool
2122
EnablePodEgress bool
@@ -105,6 +106,8 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
105106
"Each node in the cluster will setup BGP peering with rest of the nodes.")
106107
fs.BoolVar(&s.BGPGracefulRestart, "bgp-graceful-restart", false,
107108
"Enables the BGP Graceful Restart capability so that routes are preserved on unexpected restarts")
109+
fs.BoolVar(&s.EnableCNI, "enable-cni", true,
110+
"Enable CNI plugin. Disable if you want to use kube-router features alongside another CNI plugin.")
108111
fs.BoolVar(&s.EnableiBGP, "enable-ibgp", true,
109112
"Enables peering with nodes with the same ASN, if disabled will only peer with external BGP peers")
110113
fs.StringVar(&s.HostnameOverride, "hostname-override", s.HostnameOverride,

0 commit comments

Comments
 (0)