Skip to content

Commit

Permalink
add proper message when reading pod CIDR from cni conf file (cloudnat…
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-reddy authored May 25, 2018
1 parent d63c23a commit 6887ce7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 6 additions & 2 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"os"
"os/exec"
"reflect"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -101,18 +102,21 @@ func (nrc *NetworkRoutingController) Run(healthChan chan<- *healthcheck.Controll
if err != nil {
glog.Errorf("Failed to get pod CIDR from CNI conf file: %s", err.Error())
}
if reflect.DeepEqual(cidr, net.IPNet{}) {
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.")
}
cidrlen, _ := cidr.Mask.Size()
oldCidr := cidr.IP.String() + "/" + strconv.Itoa(cidrlen)

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

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

Expand Down
5 changes: 0 additions & 5 deletions pkg/utils/pod_cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package utils

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net"
"reflect"
"strings"

"github.com/containernetworking/cni/libcni"
Expand Down Expand Up @@ -50,9 +48,6 @@ func GetPodCidrFromCniSpec(cniConfFilePath string) (net.IPNet, error) {
}
}
podCidr = net.IPNet(ipamConfig.Subnet)
if reflect.DeepEqual(podCidr, net.IPNet{}) {
return net.IPNet{}, errors.New("subnet missing from CNI IPAM")
}
return podCidr, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/pod_cidr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Test_GetPodCidrFromCniSpec(t *testing.T) {
"CNI config file missing subnet",
`{"bridge":"kube-bridge","ipam":{"type":"host-local"},"isDefaultGateway":true,"name":"kubernetes","type":"bridge"}`,
net.IPNet{},
errors.New("subnet missing from CNI IPAM"),
nil,
"10-kuberouter.conf",
},
}
Expand Down

0 comments on commit 6887ce7

Please sign in to comment.