Skip to content

Commit

Permalink
feat(.golangci.yml): enable dupl and remediate
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Sep 11, 2021
1 parent d1686e7 commit c5f4c00
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 380 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- gofmt
Expand Down
158 changes: 67 additions & 91 deletions pkg/controllers/netpol/policy.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions pkg/controllers/netpol/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"regexp"
"strconv"

"github.com/cloudnativelabs/kube-router/pkg/utils"
api "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -61,3 +62,41 @@ func validateNodePortRange(nodePortOption string) (string, error) {
}
return fmt.Sprintf("%d:%d", port1, port2), nil
}

func getIPsFromPods(pods []podInfo) []string {
ips := make([]string, len(pods))
for idx, pod := range pods {
ips[idx] = pod.ip
}
return ips
}

func (npc *NetworkPolicyController) createGenericHashIPSet(ipsetName, hashType string, ips []string) {
setEntries := make([][]string, 0)
for _, ip := range ips {
setEntries = append(setEntries, []string{ip, utils.OptionTimeout, "0"})
}
npc.ipSetHandler.RefreshSet(ipsetName, setEntries, hashType)
}

// createPolicyIndexedIPSet creates a policy based ipset and indexes it as an active ipset
func (npc *NetworkPolicyController) createPolicyIndexedIPSet(
activePolicyIPSets map[string]bool, ipsetName, hashType string, ips []string) {
activePolicyIPSets[ipsetName] = true
npc.createGenericHashIPSet(ipsetName, hashType, ips)
}

// createPodWithPortPolicyRule handles the case where port details are provided by the ingress/egress rule and creates
// an iptables rule that matches on both the source/dest IPs and the port
func (npc *NetworkPolicyController) createPodWithPortPolicyRule(
ports []protocolAndPort, policy networkPolicyInfo, policyName string, srcSetName string, dstSetName string) error {
for _, portProtocol := range ports {
comment := "rule to ACCEPT traffic from source pods to dest pods selected by policy name " +
policy.name + " namespace " + policy.namespace
if err := npc.appendRuleToPolicyChain(policyName, comment, srcSetName, dstSetName, portProtocol.protocol,
portProtocol.port, portProtocol.endport); err != nil {
return err
}
}
return nil
}
Loading

0 comments on commit c5f4c00

Please sign in to comment.