Skip to content

Commit

Permalink
feat(lint): update golangci-lint and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Mar 2, 2024
1 parent 9a136c1 commit 47fe189
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 9 deletions.
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ linters:
- stylecheck
- unconvert
- unparam
linters-settings:
goconst:
# Exclude few word constants
min-len: 20
# Don't use goconst to check test files
ignore-tests: true
issues:
exclude-rules:
# Excluding single digits from magic number detector because it produces too many obvious results (like klog)
Expand Down Expand Up @@ -57,7 +63,7 @@ issues:
path: _test\.go
# Exclude tests from duplicate linter
- linters:
- dupl
- dupl
path: _test\.go
# always show all issues rather than only showing 50 at a time
max-issues-per-linter: 0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GO_CACHE?=$(shell go env GOCACHE)
GO_MOD_CACHE?=$(shell go env GOMODCACHE)
BUILDTIME_BASE?=$(DOCKER_BUILD_IMAGE)
RUNTIME_BASE?=alpine:3.18
DOCKER_LINT_IMAGE?=golangci/golangci-lint:v1.54.2
DOCKER_LINT_IMAGE?=golangci/golangci-lint:v1.56.2
DOCKER_MARKDOWNLINT_IMAGE?=tmknom/markdownlint:0.37.0
GOBGP_VERSION=v3.23.0
QEMU_IMAGE?=multiarch/qemu-user-static
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/netpol/network_policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ func NewNetworkPolicyController(clientset kubernetes.Interface,
// Validate that ClusterIP service range type matches the configuration
if config.EnableIPv4 && !config.EnableIPv6 {
if !netutils.IsIPv4CIDR(&npc.serviceClusterIPRanges[0]) {
//nolint:goconst // we don't care about abstracting an error message
return nil, fmt.Errorf("failed to get parse --service-cluster-ip-range parameter: " +
"IPv4 is enabled but only IPv6 address is provided")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/netpol/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (npc *NetworkPolicyController) syncPodFirewallChains(networkPoliciesInfo []
for ipFamily, filterTableRules := range npc.filterTableRules {
_, err := getPodIPForFamily(pod, ipFamily)
if err != nil {
//nolint:goconst // don't need to make error messages a constant
klog.V(2).Infof("unable to get address for pod: %s -- skipping drop rules for pod "+
"(this is normal for pods that are not dual-stack)", err.Error())
continue
Expand Down
4 changes: 4 additions & 0 deletions pkg/controllers/netpol/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (npc *NetworkPolicyController) processIngressRules(policy networkPolicyInfo
}
npc.ipSetHandlers[ipFamily].RefreshSet(namedPortIPSetName, setEntries, utils.TypeHashIP)

//nolint:goconst // don't need to make error messages a constant
comment := "rule to ACCEPT traffic from source pods to dest pods selected by policy name " +
policy.name + " namespace " + policy.namespace
if err := npc.appendRuleToPolicyChain(policyChainName, comment, srcPodIPSetName, namedPortIPSetName,
Expand All @@ -248,6 +249,7 @@ func (npc *NetworkPolicyController) processIngressRules(policy networkPolicyInfo
// with specified port (if any) and protocol
if ingressRule.matchAllSource && !ingressRule.matchAllPorts {
for _, portProtocol := range ingressRule.ports {
//nolint:goconst // don't need to make error messages a constant
comment := "rule to ACCEPT traffic from all sources to dest pods selected by policy name: " +
policy.name + " namespace " + policy.namespace
if err := npc.appendRuleToPolicyChain(policyChainName, comment, "", targetDestPodIPSetName,
Expand Down Expand Up @@ -293,6 +295,7 @@ func (npc *NetworkPolicyController) processIngressRules(policy networkPolicyInfo

if !ingressRule.matchAllPorts {
for _, portProtocol := range ingressRule.ports {
//nolint:goconst // don't need to make error messages a constant
comment := "rule to ACCEPT traffic from specified ipBlocks to dest pods selected by policy name: " +
policy.name + " namespace " + policy.namespace
if err := npc.appendRuleToPolicyChain(policyChainName, comment, srcIPBlockIPSetName,
Expand Down Expand Up @@ -403,6 +406,7 @@ func (npc *NetworkPolicyController) processEgressRules(policy networkPolicyInfo,
// with specified port (if any) and protocol
if egressRule.matchAllDestinations && !egressRule.matchAllPorts {
for _, portProtocol := range egressRule.ports {
//nolint:goconst // don't need to make error messages a constant
comment := "rule to ACCEPT traffic from source pods to all destinations selected by policy name: " +
policy.name + " namespace " + policy.namespace
if err := npc.appendRuleToPolicyChain(policyChainName, comment, targetSourcePodIPSetName,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ func (nsc *NetworkServicesController) syncIpvsFirewall() error {
}
address = net.ParseIP(ipString)
if address == nil {
klog.Warning("failed to parse IP %s returned from FWMark %s - this may not be a kube-router" +
"controlled service, but if it is then something's gone wrong")
klog.Warningf("failed to parse IP %s returned from FWMark %d - this may not be a kube-router"+
"controlled service, but if it is then something's gone wrong", ipString, ipvsService.FWMark)
}
}
var family v1.IPFamily
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/proxy/service_endpoints_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (nsc *NetworkServicesController) addEndpointsToIPVSService(endpoints []endp
switch family {
case v1.IPv4Protocol:
if endpoint.isIPv6 {
//nolint:goconst // don't need to make error messages a constant
klog.V(3).Infof("not adding endpoint %s to service %s with VIP %s because families don't "+
"match", endpoint.ip, svc.name, vip)
continue
Expand Down
5 changes: 1 addition & 4 deletions pkg/controllers/routing/network_routes_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ func (nrc *NetworkRoutingController) setupOverlayTunnel(tunnelName string, nextH
fouArgs = append(fouArgs, "fou", "add", "port", strFormattedEncapPort, "gue")
out, err := exec.Command("ip", fouArgs...).CombinedOutput()
if err != nil {
//nolint:goconst // don't need to make error messages a constant
return nil, fmt.Errorf("route not injected for the route advertised by the node %s "+
"Failed to set FoU tunnel port - error: %s, output: %s", tunnelName, err, string(out))
}
Expand Down Expand Up @@ -983,10 +984,6 @@ func (nrc *NetworkRoutingController) syncNodeIPSets() error {

var ipv4Addrs, ipv6Addrs [][]string
intExtNodeIPsv4, intExtNodeIPsv6 := utils.GetAllNodeIPs(node)
if err != nil {
klog.Errorf("Failed to find a node IP, cannot add to node ipset which could affect routing: %v", err)
continue
}
for _, nodeIPv4s := range intExtNodeIPsv4 {
for _, nodeIPv4 := range nodeIPv4s {
ipv4Addrs = append(ipv4Addrs, []string{nodeIPv4.String(), utils.OptionTimeout, "0"})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/routing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func linkFOUEnabled(linkName string) bool {
out, err := exec.Command("ip", cmdArgs...).CombinedOutput()

if err != nil {
klog.Warning("recevied an error while trying to look at the link details of %s, this shouldn't have happened",
klog.Warningf("recevied an error while trying to look at the link details of %s, this shouldn't have happened",
linkName)
return false
}
Expand Down

0 comments on commit 47fe189

Please sign in to comment.