From 3b992e4c45293bb1f9aab13360ccae41fb6cd146 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Fri, 4 Sep 2020 00:04:22 +0530 Subject: [PATCH] fix build break due to go linter errros --- .../netpol/network_policy_controller.go | 14 +++++++------- .../netpol/network_policy_controller_test.go | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/controllers/netpol/network_policy_controller.go b/pkg/controllers/netpol/network_policy_controller.go index abb21c9d94..2184298600 100644 --- a/pkg/controllers/netpol/network_policy_controller.go +++ b/pkg/controllers/netpol/network_policy_controller.go @@ -201,7 +201,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { glog.Fatalf("Failed to initialize iptables executor due to %s", err.Error()) } - addUuidForRuleSpec := func(chain string, ruleSpec *[]string) (string, error) { + addUUIDForRuleSpec := func(chain string, ruleSpec *[]string) (string, error) { hash := sha256.Sum256([]byte(chain + strings.Join(*ruleSpec, ""))) encoded := base32.StdEncoding.EncodeToString(hash[:])[:16] for idx, part := range *ruleSpec { @@ -236,7 +236,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { if strings.HasPrefix(rule, "-P") || strings.HasPrefix(rule, "-N") { // if this chain has a default policy, then it will show as rule #1 from iptablesCmdHandler.List so we // need to account for this offset - ruleIndexOffset += 1 + ruleIndexOffset++ continue } if strings.Contains(rule, uuid) { @@ -265,7 +265,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { glog.Fatalf("Failed to run iptables command to create %s chain due to %s", customChain, err.Error()) } args := []string{"-m", "comment", "--comment", "kube-router netpol", "-j", customChain} - uuid, err := addUuidForRuleSpec(builtinChain, &args) + uuid, err := addUUIDForRuleSpec(builtinChain, &args) if err != nil { glog.Fatalf("Failed to get uuid for rule: %s", err.Error()) } @@ -273,7 +273,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { } whitelistServiceVips := []string{"-m", "comment", "--comment", "allow traffic to cluster IP", "-d", npc.serviceClusterIPRange.String(), "-j", "RETURN"} - uuid, err := addUuidForRuleSpec(kubeInputChainName, &whitelistServiceVips) + uuid, err := addUUIDForRuleSpec(kubeInputChainName, &whitelistServiceVips) if err != nil { glog.Fatalf("Failed to get uuid for rule: %s", err.Error()) } @@ -281,7 +281,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { whitelistTCPNodeports := []string{"-p", "tcp", "-m", "comment", "--comment", "allow LOCAL TCP traffic to node ports", "-m", "addrtype", "--dst-type", "LOCAL", "-m", "multiport", "--dports", npc.serviceNodePortRange, "-j", "RETURN"} - uuid, err = addUuidForRuleSpec(kubeInputChainName, &whitelistTCPNodeports) + uuid, err = addUUIDForRuleSpec(kubeInputChainName, &whitelistTCPNodeports) if err != nil { glog.Fatalf("Failed to get uuid for rule: %s", err.Error()) } @@ -289,7 +289,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { whitelistUDPNodeports := []string{"-p", "udp", "-m", "comment", "--comment", "allow LOCAL UDP traffic to node ports", "-m", "addrtype", "--dst-type", "LOCAL", "-m", "multiport", "--dports", npc.serviceNodePortRange, "-j", "RETURN"} - uuid, err = addUuidForRuleSpec(kubeInputChainName, &whitelistUDPNodeports) + uuid, err = addUUIDForRuleSpec(kubeInputChainName, &whitelistUDPNodeports) if err != nil { glog.Fatalf("Failed to get uuid for rule: %s", err.Error()) } @@ -297,7 +297,7 @@ func (npc *NetworkPolicyController) ensureTopLevelChains() { for externalIPIndex, externalIPRange := range npc.serviceExternalIPRanges { whitelistServiceVips := []string{"-m", "comment", "--comment", "allow traffic to external IP range: " + externalIPRange.String(), "-d", externalIPRange.String(), "-j", "RETURN"} - uuid, err = addUuidForRuleSpec(kubeInputChainName, &whitelistServiceVips) + uuid, err = addUUIDForRuleSpec(kubeInputChainName, &whitelistServiceVips) if err != nil { glog.Fatalf("Failed to get uuid for rule: %s", err.Error()) } diff --git a/pkg/controllers/netpol/network_policy_controller_test.go b/pkg/controllers/netpol/network_policy_controller_test.go index ae483c243e..fe545dcff6 100644 --- a/pkg/controllers/netpol/network_policy_controller_test.go +++ b/pkg/controllers/netpol/network_policy_controller_test.go @@ -2,7 +2,6 @@ package netpol import ( "context" - "github.com/cloudnativelabs/kube-router/pkg/options" "net" "strings" "testing" @@ -18,6 +17,8 @@ import ( "k8s.io/client-go/informers" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/fake" + + "github.com/cloudnativelabs/kube-router/pkg/options" ) // newFakeInformersFromClient creates the different informers used in the uneventful network policy controller