Skip to content

Commit

Permalink
feat(.golangci.yml): enable stylecheck linter and remediate
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Sep 11, 2021
1 parent 86c2229 commit 1d90e21
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 25 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- nakedret
- noctx
- nolintlint
- stylecheck
issues:
exclude-rules:
# Excluding single digits from magic number detector because it produces too many obvious results (like klog)
Expand Down
10 changes: 5 additions & 5 deletions cmd/kube-router/kube-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func Main() error {
// https://github.com/kubernetes/kubernetes/issues/17162
err := flag.CommandLine.Parse([]string{})
if err != nil {
return fmt.Errorf("Failed to parse flags: %s", err)
return fmt.Errorf("failed to parse flags: %s", err)
}
err = flag.Set("logtostderr", "true")
if err != nil {
return fmt.Errorf("Failed to set flag: %s", err)
return fmt.Errorf("failed to set flag: %s", err)
}
err = flag.Set("v", config.VLevel)
if err != nil {
return fmt.Errorf("Failed to set flag: %s", err)
return fmt.Errorf("failed to set flag: %s", err)
}

if config.HelpRequested {
Expand All @@ -67,7 +67,7 @@ func Main() error {

kubeRouter, err := cmd.NewKubeRouterDefault(config)
if err != nil {
return fmt.Errorf("Failed to parse kube-router config: %v", err)
return fmt.Errorf("failed to parse kube-router config: %v", err)
}

if config.EnablePprof {
Expand All @@ -78,7 +78,7 @@ func Main() error {

err = kubeRouter.Run()
if err != nil {
return fmt.Errorf("Failed to run kube-router: %v", err)
return fmt.Errorf("failed to run kube-router: %v", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/netpol/network_policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() {
hash := sha256.Sum256([]byte(chain + strings.Join(*ruleSpec, "")))
encoded := base32.StdEncoding.EncodeToString(hash[:])[:16]
for idx, part := range *ruleSpec {
if "--comment" == part {
if part == "--comment" {
(*ruleSpec)[idx+1] = (*ruleSpec)[idx+1] + " - " + encoded
return encoded, nil
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,9 +1374,8 @@ func (nsc *NetworkServicesController) deleteBadMasqueradeIptablesRules() error {
if exists {
err = iptablesCmdHandler.Delete("nat", "POSTROUTING", args...)
if err != nil {
return fmt.Errorf("Failed to delete old/bad iptables rule to "+
"masquerade outbound IVPS traffic: %s.\n"+
"Masquerade all might still work, or bugs may persist after upgrade...",
return fmt.Errorf("failed to delete old/bad iptables rule to masquerade outbound IVPS "+
"traffic: %s. Masquerade all might still work, or bugs may persist after upgrade",
err)
}
klog.Infof("Deleted old/bad iptables rule to masquerade outbound traffic.")
Expand Down
15 changes: 6 additions & 9 deletions pkg/controllers/routing/bgp_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,15 @@ func newGlobalPeers(ips []net.IP, ports []uint32, asns []uint32, passwords []str
}

if len(ips) != len(passwords) && len(passwords) != 0 {
return nil, errors.New("Invalid peer router config. " +
"The number of passwords should either be zero, or one per peer router." +
" Use blank items if a router doesn't expect a password.\n" +
"Example: \"pass,,pass\" OR [\"pass\",\"\",\"pass\"].")
return nil, errors.New("invalid peer router config. The number of passwords should either be zero, or " +
"one per peer router. Use blank items if a router doesn't expect a password. Example: \"pass,,pass\" " +
"OR [\"pass\",\"\",\"pass\"]")
}

if len(ips) != len(ports) && len(ports) != 0 {
return nil, errors.New("Invalid peer router config. " +
"The number of ports should either be zero, or one per peer router." +
" If blank items are used, it will default to standard BGP port, " +
strconv.Itoa(options.DefaultBgpPort) + "\n" +
"Example: \"port,,port\" OR [\"port\",\"\",\"port\"].")
return nil, fmt.Errorf("invalid peer router config. The number of ports should either be zero, or "+
"one per peer router. If blank items are used, it will default to standard BGP port, %s. "+
"Example: \"port,,port\" OR [\"port\",\"\",\"port\"]", strconv.Itoa(options.DefaultBgpPort))
}

for i := 0; i < len(ips); i++ {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const (
asnMaxBitSize = 32
bgpCommunityMaxSize = 32
bgpCommunityMaxPartSize = 16
routeReflectorMaxId = 32
routeReflectorMaxID = 32
// Taken from: https://github.com/torvalds/linux/blob/master/include/uapi/linux/rtnetlink.h#L284
zebraRouteOriginator = 0x11
)
Expand Down Expand Up @@ -916,7 +916,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {

if clusterid, ok := node.ObjectMeta.Annotations[rrServerAnnotation]; ok {
klog.Infof("Found rr.server for the node to be %s from the node annotation", clusterid)
_, err := strconv.ParseUint(clusterid, 0, routeReflectorMaxId)
_, err := strconv.ParseUint(clusterid, 0, routeReflectorMaxID)
if err != nil {
if ip := net.ParseIP(clusterid).To4(); ip == nil {
return errors.New("failed to parse rr.server clusterId specified for the node")
Expand All @@ -926,7 +926,7 @@ func (nrc *NetworkRoutingController) startBgpServer(grpcServer bool) error {
nrc.bgpRRServer = true
} else if clusterid, ok := node.ObjectMeta.Annotations[rrClientAnnotation]; ok {
klog.Infof("Found rr.client for the node to be %s from the node annotation", clusterid)
_, err := strconv.ParseUint(clusterid, 0, routeReflectorMaxId)
_, err := strconv.ParseUint(clusterid, 0, routeReflectorMaxID)
if err != nil {
if ip := net.ParseIP(clusterid).To4(); ip == nil {
return errors.New("failed to parse rr.client clusterId specified for the node")
Expand Down
6 changes: 2 additions & 4 deletions pkg/controllers/routing/pod_egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ func (nrc *NetworkRoutingController) deleteBadPodEgressRules() error {
if exists {
err = iptablesCmdHandler.Delete("nat", "POSTROUTING", args...)
if err != nil {
return fmt.Errorf("Failed to delete old/bad iptables rule to "+
"masquerade outbound traffic from pods: %s.\n"+
"Pod egress might still work, or bugs may persist after upgrade...",
err)
return fmt.Errorf("failed to delete old/bad iptables rule to masquerade outbound traffic "+
"from pods: %s. Pod egress might still work, or bugs may persist after upgrade", err)
}
klog.Infof("Deleted old/bad iptables rule to masquerade outbound traffic from pods.")
}
Expand Down

0 comments on commit 1d90e21

Please sign in to comment.