Skip to content

Commit 6887ce7

Browse files
authored
add proper message when reading pod CIDR from cni conf file (#450)
1 parent d63c23a commit 6887ce7

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

pkg/controllers/routing/network_routes_controller.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net"
88
"os"
99
"os/exec"
10+
"reflect"
1011
"strconv"
1112
"strings"
1213
"sync"
@@ -101,18 +102,21 @@ func (nrc *NetworkRoutingController) Run(healthChan chan<- *healthcheck.Controll
101102
if err != nil {
102103
glog.Errorf("Failed to get pod CIDR from CNI conf file: %s", err.Error())
103104
}
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+
}
104108
cidrlen, _ := cidr.Mask.Size()
105109
oldCidr := cidr.IP.String() + "/" + strconv.Itoa(cidrlen)
106110

107111
currentCidr, err := utils.GetPodCidrFromNodeSpec(nrc.clientset, nrc.hostnameOverride)
108112
if err != nil {
109-
glog.Errorf("Failed to get pod CIDR from node spec: %s", err.Error())
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())
110114
}
111115

112116
if len(cidr.IP) == 0 || strings.Compare(oldCidr, currentCidr) != 0 {
113117
err = utils.InsertPodCidrInCniSpec(nrc.cniConfFile, currentCidr)
114118
if err != nil {
115-
glog.Errorf("Failed to insert pod CIDR into CNI conf file: %s", err.Error())
119+
glog.Fatalf("Failed to insert `subnet`(pod CIDR) into CNI conf file: %s", err.Error())
116120
}
117121
}
118122

pkg/utils/pod_cidr.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package utils
22

33
import (
44
"encoding/json"
5-
"errors"
65
"fmt"
76
"io/ioutil"
87
"net"
9-
"reflect"
108
"strings"
119

1210
"github.com/containernetworking/cni/libcni"
@@ -50,9 +48,6 @@ func GetPodCidrFromCniSpec(cniConfFilePath string) (net.IPNet, error) {
5048
}
5149
}
5250
podCidr = net.IPNet(ipamConfig.Subnet)
53-
if reflect.DeepEqual(podCidr, net.IPNet{}) {
54-
return net.IPNet{}, errors.New("subnet missing from CNI IPAM")
55-
}
5651
return podCidr, nil
5752
}
5853

pkg/utils/pod_cidr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Test_GetPodCidrFromCniSpec(t *testing.T) {
3636
"CNI config file missing subnet",
3737
`{"bridge":"kube-bridge","ipam":{"type":"host-local"},"isDefaultGateway":true,"name":"kubernetes","type":"bridge"}`,
3838
net.IPNet{},
39-
errors.New("subnet missing from CNI IPAM"),
39+
nil,
4040
"10-kuberouter.conf",
4141
},
4242
}

0 commit comments

Comments
 (0)