Commit 96675e62 authored by Aaron U'Ren's avatar Aaron U'Ren
Browse files

fix: don't capitalize error messages

It is standard practice in Go to not capitalize error messages:
https://github.com/golang/go/wiki/CodeReviewComments#error-strings
parent e9c77d0a
Showing with 99 additions and 100 deletions
+99 -100
......@@ -386,13 +386,13 @@ func (npc *NetworkPolicyController) cleanupStaleRules(activePolicyChains, active
// initialize tool sets for working with iptables and ipset
iptablesCmdHandler, err := iptables.New()
if err != nil {
klog.Fatalf("failed to initialize iptables command executor due to %s", err.Error())
return fmt.Errorf("failed to initialize iptables command executor due to %s", err.Error())
}
// find iptables chains and ipsets that are no longer used by comparing current to the active maps we were passed
chains, err := iptablesCmdHandler.ListChains("filter")
if err != nil {
return fmt.Errorf("Unable to list chains: %s", err)
return fmt.Errorf("unable to list chains: %s", err)
}
for _, chain := range chains {
if strings.HasPrefix(chain, kubeNetworkPolicyChainPrefix) {
......@@ -452,7 +452,7 @@ func (npc *NetworkPolicyController) cleanupStaleIPSets(activePolicyIPSets map[st
cleanupPolicyIPSets := make([]*utils.Set, 0)
ipsets, err := utils.NewIPSet(false)
if err != nil {
klog.Fatalf("failed to create ipsets command executor due to %s", err.Error())
return fmt.Errorf("failed to create ipsets command executor due to %s", err.Error())
}
err = ipsets.Save()
if err != nil {
......@@ -470,7 +470,7 @@ func (npc *NetworkPolicyController) cleanupStaleIPSets(activePolicyIPSets map[st
for _, set := range cleanupPolicyIPSets {
err = set.Destroy()
if err != nil {
return fmt.Errorf("Failed to delete ipset %s due to %s", set.Name, err)
return fmt.Errorf("failed to delete ipset %s due to %s", set.Name, err)
}
}
return nil
......
......@@ -407,7 +407,7 @@ func TestNetworkPolicyController(t *testing.T) {
"Missing nodename fails appropriately",
newMinimalKubeRouterConfig("", "", "", nil),
true,
"Failed to identify the node by NODE_NAME, hostname or --hostname-override",
"failed to identify the node by NODE_NAME, hostname or --hostname-override",
},
{
"Test bad cluster CIDR (not properly formatting ip address)",
......
......@@ -444,7 +444,7 @@ func (npc *NetworkPolicyController) buildNetworkPoliciesInfo() ([]networkPolicyI
policy, ok := policyObj.(*networking.NetworkPolicy)
podSelector, _ := v1.LabelSelectorAsSelector(&policy.Spec.PodSelector)
if !ok {
return nil, fmt.Errorf("Failed to convert")
return nil, fmt.Errorf("failed to convert")
}
newPolicy := networkPolicyInfo{
name: policy.Name,
......
......@@ -149,7 +149,7 @@ func (nsc *NetworkServicesController) flushConntrackUDP(svc *ipvs.Service) error
out, err := exec.Command("conntrack", "-D", "--orig-dst", svc.Address.String(), "-p", "udp", "--dport", strconv.Itoa(int(svc.Port))).CombinedOutput()
if err != nil {
if matched := re.MatchString(string(out)); !matched {
return fmt.Errorf("Failed to delete conntrack entry for endpoint: %s:%d due to %s", svc.Address.String(), svc.Port, err.Error())
return fmt.Errorf("failed to delete conntrack entry for endpoint: %s:%d due to %s", svc.Address.String(), svc.Port, err.Error())
}
}
klog.V(1).Infof("Deleted conntrack entry for endpoint: %s:%d", svc.Address.String(), svc.Port)
......
......@@ -530,13 +530,13 @@ func (nsc *NetworkServicesController) setupIpvsFirewall() error {
// ipvs services only.
iptablesCmdHandler, err := iptables.New()
if err != nil {
return errors.New("Failed to initialize iptables executor" + err.Error())
return errors.New("failed to initialize iptables executor" + err.Error())
}
// ClearChain either clears an existing chain or creates a new one.
err = iptablesCmdHandler.ClearChain("filter", ipvsFirewallChainName)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
// config.IpvsPermitAll: true then create INPUT/KUBE-ROUTER-SERVICE Chain creation else return
......@@ -554,12 +554,12 @@ func (nsc *NetworkServicesController) setupIpvsFirewall() error {
"-j", "ACCEPT"}
exists, err = iptablesCmdHandler.Exists("filter", ipvsFirewallChainName, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
if !exists {
err := iptablesCmdHandler.Insert("filter", ipvsFirewallChainName, 1, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
}
......@@ -569,7 +569,7 @@ func (nsc *NetworkServicesController) setupIpvsFirewall() error {
"-j", "ACCEPT"}
err = iptablesCmdHandler.AppendUnique("filter", ipvsFirewallChainName, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
comment = "allow icmp destination unreachable messages to service IPs"
......@@ -578,7 +578,7 @@ func (nsc *NetworkServicesController) setupIpvsFirewall() error {
"-j", "ACCEPT"}
err = iptablesCmdHandler.AppendUnique("filter", ipvsFirewallChainName, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
comment = "allow icmp ttl exceeded messages to service IPs"
......@@ -587,7 +587,7 @@ func (nsc *NetworkServicesController) setupIpvsFirewall() error {
"-j", "ACCEPT"}
err = iptablesCmdHandler.AppendUnique("filter", ipvsFirewallChainName, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
// We exclude the local addresses here as that would otherwise block all
......@@ -598,19 +598,19 @@ func (nsc *NetworkServicesController) setupIpvsFirewall() error {
"-j", "REJECT", "--reject-with", "icmp-port-unreachable"}
err = iptablesCmdHandler.AppendUnique("filter", ipvsFirewallChainName, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
// Pass incomming traffic into our custom chain.
// Pass incoming traffic into our custom chain.
ipvsFirewallInputChainRule := getIpvsFirewallInputChainRule()
exists, err = iptablesCmdHandler.Exists("filter", "INPUT", ipvsFirewallInputChainRule...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
if !exists {
err = iptablesCmdHandler.Insert("filter", "INPUT", 1, ipvsFirewallInputChainRule...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
}
......@@ -1190,7 +1190,7 @@ func (ln *linuxNetworking) prepareEndpointForDsrWithCRI(runtimeEndpoint, contain
activeNetworkNamespaceHandle, err := netns.Get()
if err != nil {
return errors.New("Failed to get activeNetworkNamespace due to " + err.Error())
return errors.New("failed to get activeNetworkNamespace due to " + err.Error())
}
klog.V(2).Infof("Current network namespace after netns. Set to container network namespace: " + activeNetworkNamespaceHandle.String())
activeNetworkNamespaceHandle.Close()
......@@ -1557,7 +1557,7 @@ func (nsc *NetworkServicesController) deleteBadMasqueradeIptablesRules() error {
for _, args := range argsBad {
exists, err := iptablesCmdHandler.Exists("nat", "POSTROUTING", args...)
if err != nil {
return fmt.Errorf("Failed to lookup iptables rule: %s", err.Error())
return fmt.Errorf("failed to lookup iptables rule: %s", err.Error())
}
if exists {
......@@ -2076,14 +2076,14 @@ func (ln *linuxNetworking) ipvsAddServer(service *ipvs.Service, dest *ipvs.Desti
if strings.Contains(err.Error(), IpvsServerExists) {
err = ln.ipvsUpdateDestination(service, dest)
if err != nil {
return fmt.Errorf("Failed to update ipvs destination %s to the ipvs service %s due to : %s",
return fmt.Errorf("failed to update ipvs destination %s to the ipvs service %s due to : %s",
ipvsDestinationString(dest), ipvsServiceString(service), err.Error())
}
// TODO: Make this debug output when we get log levels
// klog.Infof("ipvs destination %s already exists in the ipvs service %s so not adding destination",
// ipvsDestinationString(dest), ipvsServiceString(service))
} else {
return fmt.Errorf("Failed to add ipvs destination %s to the ipvs service %s due to : %s",
return fmt.Errorf("failed to add ipvs destination %s to the ipvs service %s due to : %s",
ipvsDestinationString(dest), ipvsServiceString(service), err.Error())
}
return nil
......@@ -2546,7 +2546,7 @@ func NewNetworkServicesController(clientset kubernetes.Interface,
if config.RunRouter {
cidr, err := utils.GetPodCidrFromNodeSpec(nsc.client, config.HostnameOverride)
if err != nil {
return nil, fmt.Errorf("Failed to get pod CIDR details from Node.spec: %s", err.Error())
return nil, fmt.Errorf("failed to get pod CIDR details from Node.spec: %s", err.Error())
}
nsc.podCidr = cidr
}
......@@ -2555,7 +2555,7 @@ func NewNetworkServicesController(clientset kubernetes.Interface,
for i, excludedCidr := range config.ExcludedCidrs {
_, ipnet, err := net.ParseCIDR(excludedCidr)
if err != nil {
return nil, fmt.Errorf("Failed to get excluded CIDR details: %s", err.Error())
return nil, fmt.Errorf("failed to get excluded CIDR details: %s", err.Error())
}
nsc.excludedCidrs[i] = *ipnet
}
......
......@@ -500,7 +500,7 @@ func (nsc *NetworkServicesController) cleanupStaleVIPs(activeServiceEndpointMap
func (nsc *NetworkServicesController) cleanupStaleIPVSConfig(activeServiceEndpointMap map[string][]string) error {
ipvsSvcs, err := nsc.ln.ipvsGetServices()
if err != nil {
return errors.New("Failed get list of IPVS services due to: " + err.Error())
return errors.New("failed get list of IPVS services due to: " + err.Error())
}
// cleanup stale ipvs service and servers
......
......@@ -228,7 +228,7 @@ func connectToExternalBGPPeers(server *gobgp.BgpServer, peerNeighbors []*gobgpap
}
err := server.AddPeer(context.Background(), &gobgpapi.AddPeerRequest{Peer: n})
if err != nil {
return fmt.Errorf("Error peering with peer router "+
return fmt.Errorf("error peering with peer router "+
"%q due to: %s", n.Conf.NeighborAddress, err)
}
klog.V(2).Infof("Successfully configured %s in ASN %v as BGP peer to the node",
......@@ -244,8 +244,7 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
// Validations
if len(ips) != len(asns) {
return nil, errors.New("Invalid peer router config. " +
"The number of IPs and ASN numbers must be equal.")
return nil, errors.New("invalid peer router config, the number of IPs and ASN numbers must be equal")
}
if len(ips) != len(passwords) && len(passwords) != 0 {
......@@ -269,7 +268,7 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
(asns[i] >= 64512 && asns[i] <= 65534) ||
(asns[i] >= 131072 && asns[i] <= 4199999999) ||
(asns[i] >= 4200000000 && asns[i] <= 4294967294)) {
return nil, fmt.Errorf("Reserved ASN number \"%d\" for global BGP peer",
return nil, fmt.Errorf("reserved ASN number \"%d\" for global BGP peer",
asns[i])
}
......
......@@ -527,11 +527,11 @@ out:
var prefix gobgpapi.IPAddressPrefix
err := ptypes.UnmarshalAny(nlri, &prefix)
if err != nil {
return fmt.Errorf("Invalid nlri in advertised path")
return fmt.Errorf("invalid nlri in advertised path")
}
dst, err := netlink.ParseIPNet(prefix.Prefix + "/" + fmt.Sprint(prefix.PrefixLen))
if err != nil {
return fmt.Errorf("Invalid nlri in advertised path")
return fmt.Errorf("invalid nlri in advertised path")
}
var route *netlink.Route
......@@ -573,14 +573,14 @@ out:
out, err := exec.Command("ip", "tunnel", "add", tunnelName, "mode", "ipip", "local", nrc.nodeIP.String(),
"remote", nextHop.String(), "dev", nrc.nodeInterface).CombinedOutput()
if err != nil {
return fmt.Errorf("Route not injected for the route advertised by the node %s "+
return fmt.Errorf("route not injected for the route advertised by the node %s "+
"Failed to create tunnel interface %s. error: %s, output: %s",
nextHop, tunnelName, err, string(out))
}
link, err = netlink.LinkByName(tunnelName)
if err != nil {
return fmt.Errorf("Route not injected for the route advertised by the node %s "+
return fmt.Errorf("route not injected for the route advertised by the node %s "+
"Failed to get tunnel interface by name error: %s", tunnelName, err)
}
if err := netlink.LinkSetUp(link); err != nil {
......@@ -699,7 +699,7 @@ func (nrc *NetworkRoutingController) syncNodeIPSets() error {
}
err = psSet.Refresh(currentPodCidrs)
if err != nil {
return fmt.Errorf("Failed to sync Pod Subnets ipset: %s", err)
return fmt.Errorf("failed to sync Pod Subnets ipset: %s", err)
}
// Syncing Node Addresses ipset entries
......@@ -714,7 +714,7 @@ func (nrc *NetworkRoutingController) syncNodeIPSets() error {
}
err = naSet.Refresh(currentNodeIPs)
if err != nil {
return fmt.Errorf("Failed to sync Node Addresses ipset: %s", err)
return fmt.Errorf("failed to sync Node Addresses ipset: %s", err)
}
return nil
......@@ -738,12 +738,12 @@ func (nrc *NetworkRoutingController) enableForwarding() error {
args := []string{"-m", "comment", "--comment", comment, "-i", "kube-bridge", "-j", "ACCEPT"}
exists, err := iptablesCmdHandler.Exists("filter", "FORWARD", args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
if !exists {
err := iptablesCmdHandler.Insert("filter", "FORWARD", 1, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
}
......@@ -751,12 +751,12 @@ func (nrc *NetworkRoutingController) enableForwarding() error {
args = []string{"-m", "comment", "--comment", comment, "-o", "kube-bridge", "-j", "ACCEPT"}
exists, err = iptablesCmdHandler.Exists("filter", "FORWARD", args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
if !exists {
err = iptablesCmdHandler.Insert("filter", "FORWARD", 1, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
}
......@@ -764,12 +764,12 @@ func (nrc *NetworkRoutingController) enableForwarding() error {
args = []string{"-m", "comment", "--comment", comment, "-o", nrc.nodeInterface, "-j", "ACCEPT"}
exists, err = iptablesCmdHandler.Exists("filter", "FORWARD", args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
if !exists {
err = iptablesCmdHandler.Insert("filter", "FORWARD", 1, args...)
if err != nil {
return fmt.Errorf("Failed to run iptables command: %s", err.Error())
return fmt.Errorf("failed to run iptables command: %s", err.Error())
}
}
......@@ -780,7 +780,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
var nodeAsnNumber uint32
node, err := utils.GetNodeObject(nrc.clientset, nrc.hostnameOverride)
if err != nil {
return errors.New("Failed to get node object from api server: " + err.Error())
return errors.New("failed to get node object from api server: " + err.Error())
}
if nrc.bgpFullMeshMode {
......@@ -788,13 +788,13 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
} else {
nodeasn, ok := node.ObjectMeta.Annotations[nodeASNAnnotation]
if !ok {
return errors.New("Could not find ASN number for the node. " +
"Node needs to be annotated with ASN number details to start BGP server.")
return errors.New("could not find ASN number for the node. " +
"Node needs to be annotated with ASN number details to start BGP server")
}
klog.Infof("Found ASN for the node to be %s from the node annotations", nodeasn)
asnNo, err := strconv.ParseUint(nodeasn, 0, 32)
if err != nil {
return errors.New("Failed to parse ASN number specified for the the node")
return errors.New("failed to parse ASN number specified for the the node")
}
nodeAsnNumber = uint32(asnNo)
nrc.nodeAsnNumber = nodeAsnNumber
......@@ -805,7 +805,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
_, err := strconv.ParseUint(clusterid, 0, 32)
if err != nil {
if ip := net.ParseIP(clusterid).To4(); ip == nil {
return errors.New("Failed to parse rr.server clusterId specified for the node")
return errors.New("failed to parse rr.server clusterId specified for the node")
}
}
nrc.bgpClusterID = clusterid
......@@ -815,7 +815,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
_, err := strconv.ParseUint(clusterid, 0, 32)
if err != nil {
if ip := net.ParseIP(clusterid).To4(); ip == nil {
return errors.New("Failed to parse rr.client clusterId specified for the node")
return errors.New("failed to parse rr.client clusterId specified for the node")
}
}
nrc.bgpClusterID = clusterid
......@@ -826,17 +826,17 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
prependRepeatN, okRepeatN := node.ObjectMeta.Annotations[pathPrependRepeatNAnnotation]
if !okRepeatN {
return fmt.Errorf("Both %s and %s must be set", pathPrependASNAnnotation, pathPrependRepeatNAnnotation)
return fmt.Errorf("both %s and %s must be set", pathPrependASNAnnotation, pathPrependRepeatNAnnotation)
}
_, err := strconv.ParseUint(prependASN, 0, 32)
if err != nil {
return errors.New("Failed to parse ASN number specified to prepend")
return errors.New("failed to parse ASN number specified to prepend")
}
repeatN, err := strconv.ParseUint(prependRepeatN, 0, 8)
if err != nil {
return errors.New("Failed to parse number of times ASN should be repeated")
return errors.New("failed to parse number of times ASN should be repeated")
}
nrc.pathPrepend = true
......@@ -869,7 +869,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
}
if err := nrc.bgpServer.StartBgp(context.Background(), &gobgpapi.StartBgpRequest{Global: global}); err != nil {
return errors.New("Failed to start BGP server due to : " + err.Error())
return errors.New("failed to start BGP server due to : " + err.Error())
}
go nrc.watchBgpUpdates()
......@@ -891,7 +891,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
if err2 != nil {
klog.Errorf("Failed to stop bgpServer: %s", err2)
}
return fmt.Errorf("Failed to parse node's Peer ASN Numbers Annotation: %s", err)
return fmt.Errorf("failed to parse node's Peer ASN Numbers Annotation: %s", err)
}
// Get Global Peer Router IP Address configs
......@@ -908,7 +908,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
klog.Errorf("Failed to stop bgpServer: %s", err2)
}
return fmt.Errorf("Failed to parse node's Peer Addresses Annotation: %s", err)
return fmt.Errorf("failed to parse node's Peer Addresses Annotation: %s", err)
}
// Get Global Peer Router ASN configs
......@@ -923,7 +923,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
if err2 != nil {
klog.Errorf("Failed to stop bgpServer: %s", err2)
}
return fmt.Errorf("Failed to parse node's Peer Port Numbers Annotation: %s", err)
return fmt.Errorf("failed to parse node's Peer Port Numbers Annotation: %s", err)
}
}
......@@ -940,7 +940,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
if err2 != nil {
klog.Errorf("Failed to stop bgpServer: %s", err2)
}
return fmt.Errorf("Failed to parse node's Peer Passwords Annotation: %s", err)
return fmt.Errorf("failed to parse node's Peer Passwords Annotation: %s", err)
}
}
......@@ -952,7 +952,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
klog.Errorf("Failed to stop bgpServer: %s", err2)
}
return fmt.Errorf("Failed to process Global Peer Router configs: %s", err)
return fmt.Errorf("failed to process Global Peer Router configs: %s", err)
}
nrc.nodePeerRouters = ipStrings
......@@ -967,7 +967,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
klog.Errorf("Failed to stop bgpServer: %s", err2)
}
return fmt.Errorf("Failed to peer with Global Peer Router(s): %s",
return fmt.Errorf("failed to peer with Global Peer Router(s): %s",
err)
}
} else {
......@@ -1023,14 +1023,14 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
nrc.hostnameOverride = kubeRouterConfig.HostnameOverride
node, err := utils.GetNodeObject(clientset, nrc.hostnameOverride)
if err != nil {
return nil, errors.New("Failed getting node object from API server: " + err.Error())
return nil, errors.New("failed getting node object from API server: " + err.Error())
}
nrc.nodeName = node.Name
nodeIP, err := utils.GetNodeIP(node)
if err != nil {
return nil, errors.New("Failed getting IP address from node object: " + err.Error())
return nil, errors.New("failed getting IP address from node object: " + err.Error())
}
nrc.nodeIP = nodeIP
nrc.isIpv6 = nodeIP.To4() == nil
......@@ -1039,7 +1039,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
nrc.routerID = kubeRouterConfig.RouterID
} else {
if nrc.isIpv6 {
return nil, errors.New("Router-id must be specified in ipv6 operation")
return nil, errors.New("router-id must be specified in ipv6 operation")
}
nrc.routerID = nrc.nodeIP.String()
}
......@@ -1060,7 +1060,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
cidr, err := utils.GetPodCidrFromNodeSpec(clientset, nrc.hostnameOverride)
if err != nil {
klog.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)
return nil, fmt.Errorf("Failed to get pod CIDR details from Node.spec: %s", err.Error())
return nil, fmt.Errorf("failed to get pod CIDR details from Node.spec: %s", err.Error())
}
nrc.podCidr = cidr
......@@ -1086,7 +1086,7 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
if kubeRouterConfig.ClusterAsn != 0 {
if !((kubeRouterConfig.ClusterAsn >= 64512 && kubeRouterConfig.ClusterAsn <= 65535) ||
(kubeRouterConfig.ClusterAsn >= 4200000000 && kubeRouterConfig.ClusterAsn <= 4294967294)) {
return nil, errors.New("Invalid ASN number for cluster ASN")
return nil, errors.New("invalid ASN number for cluster ASN")
}
nrc.defaultNodeAsnNumber = uint32(kubeRouterConfig.ClusterAsn)
} else {
......@@ -1121,29 +1121,29 @@ func NewNetworkRoutingController(clientset kubernetes.Interface,
if len(kubeRouterConfig.PeerPasswords) != 0 {
peerPasswords, err = stringSliceB64Decode(kubeRouterConfig.PeerPasswords)
if err != nil {
return nil, fmt.Errorf("Failed to parse CLI Peer Passwords flag: %s", err)
return nil, fmt.Errorf("failed to parse CLI Peer Passwords flag: %s", err)
}
} else if len(kubeRouterConfig.PeerPasswordsFile) != 0 {
// Contents of the pw file should be in the same format as pw from CLI arg
pwFileBytes, err := ioutil.ReadFile(kubeRouterConfig.PeerPasswordsFile)
if err != nil {
return nil, fmt.Errorf("Error loading Peer Passwords File : %s", err)
return nil, fmt.Errorf("error loading Peer Passwords File : %s", err)
}
pws := strings.Split(string(pwFileBytes), ",")
peerPasswords, err = stringSliceB64Decode(pws)
if err != nil {
return nil, fmt.Errorf("Failed to decode CLI Peer Passwords file: %s", err)
return nil, fmt.Errorf("failed to decode CLI Peer Passwords file: %s", err)
}
}
nrc.globalPeerRouters, err = newGlobalPeers(kubeRouterConfig.PeerRouters, peerPorts, peerASNs, peerPasswords, nrc.bgpHoldtime)
if err != nil {
return nil, fmt.Errorf("Error processing Global Peer Router configs: %s", err)
return nil, fmt.Errorf("error processing Global Peer Router configs: %s", err)
}
nrc.nodeSubnet, nrc.nodeInterface, err = getNodeSubnet(nodeIP)
if err != nil {
return nil, errors.New("Failed find the subnet of the node IP and interface on" +
return nil, errors.New("failed find the subnet of the node IP and interface on" +
"which its configured: " + err.Error())
}
......
......@@ -13,18 +13,18 @@ import (
func (nrc *NetworkRoutingController) enablePolicyBasedRouting() error {
err := rtTablesAdd(customRouteTableID, customRouteTableName)
if err != nil {
return fmt.Errorf("Failed to update rt_tables file: %s", err)
return fmt.Errorf("failed to update rt_tables file: %s", err)
}
out, err := exec.Command("ip", "rule", "list").Output()
if err != nil {
return fmt.Errorf("Failed to verify if `ip rule` exists: %s", err.Error())
return fmt.Errorf("failed to verify if `ip rule` exists: %s", err.Error())
}
if !strings.Contains(string(out), nrc.podCidr) {
err = exec.Command("ip", "rule", "add", "from", nrc.podCidr, "lookup", customRouteTableID).Run()
if err != nil {
return fmt.Errorf("Failed to add ip rule due to: %s", err.Error())
return fmt.Errorf("failed to add ip rule due to: %s", err.Error())
}
}
......@@ -34,19 +34,19 @@ func (nrc *NetworkRoutingController) enablePolicyBasedRouting() error {
func (nrc *NetworkRoutingController) disablePolicyBasedRouting() error {
err := rtTablesAdd(customRouteTableID, customRouteTableName)
if err != nil {
return fmt.Errorf("Failed to update rt_tables file: %s", err)
return fmt.Errorf("failed to update rt_tables file: %s", err)
}
out, err := exec.Command("ip", "rule", "list").Output()
if err != nil {
return fmt.Errorf("Failed to verify if `ip rule` exists: %s",
return fmt.Errorf("failed to verify if `ip rule` exists: %s",
err.Error())
}
if strings.Contains(string(out), nrc.podCidr) {
err = exec.Command("ip", "rule", "del", "from", nrc.podCidr, "table", customRouteTableID).Run()
if err != nil {
return fmt.Errorf("Failed to delete ip rule: %s", err.Error())
return fmt.Errorf("failed to delete ip rule: %s", err.Error())
}
}
......@@ -56,17 +56,17 @@ func (nrc *NetworkRoutingController) disablePolicyBasedRouting() error {
func rtTablesAdd(tableNumber, tableName string) error {
b, err := ioutil.ReadFile("/etc/iproute2/rt_tables")
if err != nil {
return fmt.Errorf("Failed to read: %s", err.Error())
return fmt.Errorf("failed to read: %s", err.Error())
}
if !strings.Contains(string(b), tableName) {
f, err := os.OpenFile("/etc/iproute2/rt_tables", os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
return fmt.Errorf("Failed to open: %s", err.Error())
return fmt.Errorf("failed to open: %s", err.Error())
}
defer f.Close()
if _, err = f.WriteString(tableNumber + " " + tableName + "\n"); err != nil {
return fmt.Errorf("Failed to write: %s", err.Error())
return fmt.Errorf("failed to write: %s", err.Error())
}
}
......
......@@ -104,7 +104,7 @@ func (nrc *NetworkRoutingController) deleteBadPodEgressRules() error {
for _, args := range podEgressArgsBad {
exists, err := iptablesCmdHandler.Exists("nat", "POSTROUTING", args...)
if err != nil {
return fmt.Errorf("Failed to lookup iptables rule: %s", err.Error())
return fmt.Errorf("failed to lookup iptables rule: %s", err.Error())
}
if exists {
......
......@@ -28,7 +28,7 @@ func stringSliceToIPs(s []string) ([]net.IP, error) {
for _, ipString := range s {
ip := net.ParseIP(ipString)
if ip == nil {
return nil, fmt.Errorf("Could not parse \"%s\" as an IP", ipString)
return nil, fmt.Errorf("could not parse \"%s\" as an IP", ipString)
}
ips = append(ips, ip)
}
......@@ -40,7 +40,7 @@ func stringSliceToUInt32(s []string) ([]uint32, error) {
for _, intString := range s {
newInt, err := strconv.ParseUint(intString, 0, 32)
if err != nil {
return nil, fmt.Errorf("Could not parse \"%s\" as an integer", intString)
return nil, fmt.Errorf("could not parse \"%s\" as an integer", intString)
}
ints = append(ints, uint32(newInt))
}
......@@ -52,7 +52,7 @@ func stringSliceB64Decode(s []string) ([]string, error) {
for _, b64String := range s {
decoded, err := base64.StdEncoding.DecodeString(b64String)
if err != nil {
return nil, fmt.Errorf("Could not parse \"%s\" as a base64 encoded string",
return nil, fmt.Errorf("could not parse \"%s\" as a base64 encoded string",
b64String)
}
ss = append(ss, string(decoded))
......@@ -90,12 +90,12 @@ func ipv6IsEnabled() bool {
func getNodeSubnet(nodeIP net.IP) (net.IPNet, string, error) {
links, err := netlink.LinkList()
if err != nil {
return net.IPNet{}, "", errors.New("Failed to get list of links")
return net.IPNet{}, "", errors.New("failed to get list of links")
}
for _, link := range links {
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
if err != nil {
return net.IPNet{}, "", errors.New("Failed to get list of addr")
return net.IPNet{}, "", errors.New("failed to get list of addr")
}
for _, addr := range addresses {
if addr.IPNet.IP.Equal(nodeIP) {
......@@ -103,18 +103,18 @@ func getNodeSubnet(nodeIP net.IP) (net.IPNet, string, error) {
}
}
}
return net.IPNet{}, "", errors.New("Failed to find interface with specified node ip")
return net.IPNet{}, "", errors.New("failed to find interface with specified node ip")
}
func getMTUFromNodeIP(nodeIP net.IP, overlayEnabled bool) (int, error) {
links, err := netlink.LinkList()
if err != nil {
return 0, errors.New("Failed to get list of links")
return 0, errors.New("failed to get list of links")
}
for _, link := range links {
addresses, err := netlink.AddrList(link, netlink.FAMILY_ALL)
if err != nil {
return 0, errors.New("Failed to get list of addr")
return 0, errors.New("failed to get list of addr")
}
for _, addr := range addresses {
if addr.IPNet.IP.Equal(nodeIP) {
......@@ -126,7 +126,7 @@ func getMTUFromNodeIP(nodeIP net.IP, overlayEnabled bool) (int, error) {
}
}
}
return 0, errors.New("Failed to find interface with specified node ip")
return 0, errors.New("failed to find interface with specified node ip")
}
// generateTunnelName will generate a name for a tunnel interface given a node IP
......
......@@ -10,7 +10,7 @@ import (
var (
// Error returned when ipset binary is not found.
errIpsetNotFound = errors.New("Ipset utility not found")
errIpsetNotFound = errors.New("ipset utility not found")
)
const (
......@@ -176,7 +176,7 @@ func (ipset *IPSet) Create(setName string, createOptions ...string) (*Set, error
// Determine if set with the same name is already active on the system
setIsActive, err := ipset.Sets[setName].IsActive()
if err != nil {
return nil, fmt.Errorf("Failed to determine if ipset set %s exists: %s",
return nil, fmt.Errorf("failed to determine if ipset set %s exists: %s",
setName, err)
}
......@@ -188,13 +188,13 @@ func (ipset *IPSet) Create(setName string, createOptions ...string) (*Set, error
args = append(args, createOptions...)
args = append(args, "family", "inet6")
if _, err := ipset.run(args...); err != nil {
return nil, fmt.Errorf("Failed to create ipset set on system: %s", err)
return nil, fmt.Errorf("failed to create ipset set on system: %s", err)
}
} else {
_, err := ipset.run(append([]string{"create", "-exist", setName},
createOptions...)...)
if err != nil {
return nil, fmt.Errorf("Failed to create ipset set on system: %s", err)
return nil, fmt.Errorf("failed to create ipset set on system: %s", err)
}
}
}
......
......@@ -38,7 +38,7 @@ func GetNodeObject(clientset kubernetes.Interface, hostnameOverride string) (*ap
}
}
return nil, fmt.Errorf("Failed to identify the node by NODE_NAME, hostname or --hostname-override")
return nil, fmt.Errorf("failed to identify the node by NODE_NAME, hostname or --hostname-override")
}
// GetNodeIP returns the most valid external facing IP address for a node.
......
......@@ -68,7 +68,7 @@ func Test_GetNodeObject(t *testing.T) {
Name: "another-node",
},
},
errors.New("Failed to identify the node by NODE_NAME, hostname or --hostname-override"),
errors.New("failed to identify the node by NODE_NAME, hostname or --hostname-override"),
},
}
......
......@@ -26,14 +26,14 @@ func GetPodCidrFromCniSpec(cniConfFilePath string) (net.IPNet, error) {
var confList *libcni.NetworkConfigList
confList, err = libcni.ConfListFromFile(cniConfFilePath)
if err != nil {
return net.IPNet{}, fmt.Errorf("Failed to load CNI config list file: %s", err.Error())
return net.IPNet{}, fmt.Errorf("failed to load CNI config list file: %s", err.Error())
}
for _, conf := range confList.Plugins {
if conf.Network.IPAM.Type != "" {
ipamConfig, _, err = allocator.LoadIPAMConfig(conf.Bytes, "")
if err != nil {
if err.Error() != "no IP ranges specified" {
return net.IPNet{}, fmt.Errorf("Failed to get IPAM details from the CNI conf file: %s", err.Error())
return net.IPNet{}, fmt.Errorf("failed to get IPAM details from the CNI conf file: %s", err.Error())
}
}
break
......@@ -42,13 +42,13 @@ func GetPodCidrFromCniSpec(cniConfFilePath string) (net.IPNet, error) {
} else {
netconfig, err := libcni.ConfFromFile(cniConfFilePath)
if err != nil {
return net.IPNet{}, fmt.Errorf("Failed to load CNI conf file: %s", err.Error())
return net.IPNet{}, fmt.Errorf("failed to load CNI conf file: %s", err.Error())
}
ipamConfig, _, err = allocator.LoadIPAMConfig(netconfig.Bytes, "")
if err != nil {
// TODO: Handle this error properly in controllers, if no subnet is specified
if err.Error() != "no IP ranges specified" {
return net.IPNet{}, fmt.Errorf("Failed to get IPAM details from the CNI conf file: %s", err.Error())
return net.IPNet{}, fmt.Errorf("failed to get IPAM details from the CNI conf file: %s", err.Error())
}
return net.IPNet{}, nil
}
......@@ -72,13 +72,13 @@ func GetPodCidrFromCniSpec(cniConfFilePath string) (net.IPNet, error) {
func InsertPodCidrInCniSpec(cniConfFilePath string, cidr string) error {
file, err := ioutil.ReadFile(cniConfFilePath)
if err != nil {
return fmt.Errorf("Failed to load CNI conf file: %s", err.Error())
return fmt.Errorf("failed to load CNI conf file: %s", err.Error())
}
var config interface{}
if strings.HasSuffix(cniConfFilePath, ".conflist") {
err = json.Unmarshal(file, &config)
if err != nil {
return fmt.Errorf("Failed to parse JSON from CNI conf file: %s", err.Error())
return fmt.Errorf("failed to parse JSON from CNI conf file: %s", err.Error())
}
updatedCidr := false
configMap := config.(map[string]interface{})
......@@ -107,7 +107,7 @@ func InsertPodCidrInCniSpec(cniConfFilePath string, cidr string) error {
} else {
err = json.Unmarshal(file, &config)
if err != nil {
return fmt.Errorf("Failed to parse JSON from CNI conf file: %s", err.Error())
return fmt.Errorf("failed to parse JSON from CNI conf file: %s", err.Error())
}
pluginConfig := config.(map[string]interface{})
pluginConfig["ipam"].(map[string]interface{})["subnet"] = cidr
......@@ -115,7 +115,7 @@ func InsertPodCidrInCniSpec(cniConfFilePath string, cidr string) error {
configJSON, _ := json.Marshal(config)
err = ioutil.WriteFile(cniConfFilePath, configJSON, 0644)
if err != nil {
return fmt.Errorf("Failed to insert subnet cidr into CNI conf file: %s", err.Error())
return fmt.Errorf("failed to insert subnet cidr into CNI conf file: %s", err.Error())
}
return nil
}
......
Markdown is supported
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