Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
tanyaveksler committed Nov 11, 2024
1 parent 58266f0 commit 52d3235
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/netpol/connlist/conns_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func getRepresentativePodString(podLabels v1.LabelSelector, txtOutFlag bool) str

// getConnlistAsSortedSingleConnFieldsArray returns a sorted singleConnFields list from Peer2PeerConnection list.
// creates ipMaps object if the format requires it (to be used for exposure results later)
func getConnlistAsSortedSingleConnFieldsArray(conns []Peer2PeerConnection, ipMaps ipMaps, saveToIPMaps bool, explain bool) []singleConnFields {
func getConnlistAsSortedSingleConnFieldsArray(conns []Peer2PeerConnection, ipMaps ipMaps, saveToIPMaps, explain bool) []singleConnFields {
connItems := make([]singleConnFields, len(conns))
for i := range conns {
if saveToIPMaps {
Expand Down
4 changes: 2 additions & 2 deletions pkg/netpol/connlist/conns_formatter_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type formatCSV struct {

// writeOutput returns a CSV string form of connections from list of Peer2PeerConnection objects
// and exposure analysis results from list ExposedPeer if exists
func (cs *formatCSV) writeOutput(conns []Peer2PeerConnection, exposureConns []ExposedPeer, exposureFlag bool, explain bool) (string, error) {
func (cs *formatCSV) writeOutput(conns []Peer2PeerConnection, exposureConns []ExposedPeer, exposureFlag, explain bool) (string, error) {
// Tanya TODO - handle explain flag
// writing csv rows into a buffer
buf := new(bytes.Buffer)
Expand Down Expand Up @@ -62,7 +62,7 @@ func writeTableRows(conns []singleConnFields, writer *csv.Writer, srcFirst bool)
}

// writeCsvConnlistTable writes csv table for the Peer2PeerConnection list
func (cs *formatCSV) writeCsvConnlistTable(conns []Peer2PeerConnection, writer *csv.Writer, saveIPConns bool, explain bool) error {
func (cs *formatCSV) writeCsvConnlistTable(conns []Peer2PeerConnection, writer *csv.Writer, saveIPConns, explain bool) error {
err := writeCsvColumnsHeader(writer, true)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/netpol/connlist/conns_formatter_dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func getPeerLine(peer Peer) (string, bool) {

// returns a dot string form of connections from list of Peer2PeerConnection objects
// and from exposure-analysis results if exists
func (d *formatDOT) writeOutput(conns []Peer2PeerConnection, exposureConns []ExposedPeer, exposureFlag bool, explain bool) (string, error) {
func (d *formatDOT) writeOutput(conns []Peer2PeerConnection, exposureConns []ExposedPeer, exposureFlag, explain bool) (string, error) {
// 1. declaration of maps and slices to be used for forming the graph lines
nsPeers := make(map[string][]string) // map from namespace to its peers (grouping peers by namespaces)
nsRepPeers := make(map[string][]string) // map from representative namespace to its representative peers
Expand Down
2 changes: 1 addition & 1 deletion pkg/netpol/connlist/conns_formatter_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type exposureFields struct {

// writeOutput returns a json string form of connections from list of Peer2PeerConnection objects
// and exposure analysis results from list ExposedPeer if exists
func (j *formatJSON) writeOutput(conns []Peer2PeerConnection, exposureConns []ExposedPeer, exposureFlag bool, explain bool) (string, error) {
func (j *formatJSON) writeOutput(conns []Peer2PeerConnection, exposureConns []ExposedPeer, exposureFlag, explain bool) (string, error) {
// Tanya TODO - handle explain flag
j.ipMaps = createIPMaps(exposureFlag)
// output variables
Expand Down
2 changes: 1 addition & 1 deletion pkg/netpol/connlist/conns_formatter_md.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func writeMdLines(conns []singleConnFields, srcFirst bool) []string {
}

// writeMdConnlistLines returns md lines from the list of Peer2PeerConnection
func (md *formatMD) writeMdConnlistLines(conns []Peer2PeerConnection, saveIPConns bool, explain bool) []string {
func (md *formatMD) writeMdConnlistLines(conns []Peer2PeerConnection, saveIPConns, explain bool) []string {
md.ipMaps = createIPMaps(saveIPConns)
sortedConns := getConnlistAsSortedSingleConnFieldsArray(conns, md.ipMaps, saveIPConns, explain)
connlistLines := []string{getMDHeader(true)} // connlist results are formatted: src | dst | conn
Expand Down
2 changes: 1 addition & 1 deletion pkg/netpol/connlist/conns_formatter_txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (t *formatText) writeOutput(conns []Peer2PeerConnection, exposureConns []Ex
}

// writeConnlistOutput writes the section of the connlist result of the output
func (t *formatText) writeConnlistOutput(conns []Peer2PeerConnection, saveIPConns bool, explain bool) string {
func (t *formatText) writeConnlistOutput(conns []Peer2PeerConnection, saveIPConns, explain bool) string {
connLines := make([]singleConnFields, 0, len(conns))
t.ipMaps = createIPMaps(saveIPConns)
for i := range conns {
Expand Down
3 changes: 2 additions & 1 deletion pkg/netpol/eval/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ func GetPeerExposedTCPConnections(peer Peer) *common.ConnectionSet {
// admin-network-policies, network-policies and baseline-admin-network-policies;
// considering the precedence of each policy
func (pe *PolicyEngine) allAllowedXgressConnections(src, dst k8s.Peer, isIngress bool) (allowedConns *common.ConnectionSet, err error) {
// Tanya TODO: think about the implicitly denied protocols/port ranges (due to NPs capturing this src/dst, but defining only some of protocols/ports)
// Tanya TODO: think about the implicitly denied protocols/port ranges
// (due to NPs capturing this src/dst, but defining only some of protocols/ports)
// How to update implying rules in this case?

// first get allowed xgress conn between the src and dst from the ANPs
Expand Down
6 changes: 4 additions & 2 deletions pkg/netpol/eval/internal/k8s/adminnetpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ func (anp *AdminNetworkPolicy) GetIngressPolicyConns(src, dst Peer) (*PolicyConn
for _, rule := range anp.Spec.Ingress { // rule is apisv1a.AdminNetworkPolicyIngressRule
rulePeers := rule.From
rulePorts := rule.Ports
if err := updateConnsIfIngressRuleSelectsPeer(rulePeers, rulePorts, ruleFullName("ANP "+anp.fullName(), rule.Name, string(rule.Action), true),
if err := updateConnsIfIngressRuleSelectsPeer(rulePeers, rulePorts,
ruleFullName("ANP "+anp.fullName(), rule.Name, string(rule.Action), true),
src, dst, res, string(rule.Action), false); err != nil {
return nil, anp.anpRuleErr(rule.Name, err.Error())
}
Expand All @@ -313,7 +314,8 @@ func (anp *AdminNetworkPolicy) GetEgressPolicyConns(dst Peer) (*PolicyConnection
for _, rule := range anp.Spec.Egress { // rule is apisv1a.AdminNetworkPolicyEgressRule
rulePeers := rule.To
rulePorts := rule.Ports
if err := updateConnsIfEgressRuleSelectsPeer(rulePeers, rulePorts, ruleFullName("ANP "+anp.fullName(), rule.Name, string(rule.Action), false),
if err := updateConnsIfEgressRuleSelectsPeer(rulePeers, rulePorts,
ruleFullName("ANP "+anp.fullName(), rule.Name, string(rule.Action), false),
dst, res, string(rule.Action), false); err != nil {
return nil, anp.anpRuleErr(rule.Name, err.Error())
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/netpol/eval/internal/k8s/baseline_admin_netpol.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func (banp *BaselineAdminNetworkPolicy) GetEgressPolicyConns(dst Peer) (*PolicyC
for _, rule := range banp.Spec.Egress { // rule is apisv1a.BaselineAdminNetworkPolicyEgressRule
rulePeers := rule.To
rulePorts := rule.Ports
if err := updateConnsIfEgressRuleSelectsPeer(rulePeers, rulePorts, ruleFullName("BANP "+banp.fullName(), rule.Name, string(rule.Action), false),
if err := updateConnsIfEgressRuleSelectsPeer(rulePeers, rulePorts,
ruleFullName("BANP "+banp.fullName(), rule.Name, string(rule.Action), false),
dst, res, string(rule.Action), true); err != nil {
return nil, banpRuleErr(rule.Name, err.Error())
}
Expand All @@ -70,7 +71,8 @@ func (banp *BaselineAdminNetworkPolicy) GetIngressPolicyConns(src, dst Peer) (*P
for _, rule := range banp.Spec.Ingress { // rule is apisv1a.BaselineAdminNetworkPolicyIngressRule
rulePeers := rule.From
rulePorts := rule.Ports
if err := updateConnsIfIngressRuleSelectsPeer(rulePeers, rulePorts, ruleFullName("BANP "+banp.fullName(), rule.Name, string(rule.Action), true),
if err := updateConnsIfIngressRuleSelectsPeer(rulePeers, rulePorts,
ruleFullName("BANP "+banp.fullName(), rule.Name, string(rule.Action), true),
src, dst, res, string(rule.Action), true); err != nil {
return nil, banpRuleErr(rule.Name, err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/netpol/internal/common/augmented_intervalset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (rules *ImplyingRulesType) String() string {
if rules.Empty() {
return ""
}
// print the rules according to thier order
var formattedRules []string
// print the rules according to their order
formattedRules := make([]string, 0, len(*rules))
for name, order := range *rules {
formattedRules = append(formattedRules, fmt.Sprintf("%d) %s", order+1, name))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/netpol/internal/common/connectionset.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,14 @@ func protocolAndPortsStr(protocol v1.Protocol, ports string) string {
return string(protocol) + " " + ports
}

func ExplanationFromConnProperties(allProtocolsAndPorts bool, commonImplyingRules *ImplyingRulesType, protocolsAndPorts map[v1.Protocol][]PortRange) string {
func ExplanationFromConnProperties(allProtocolsAndPorts bool, commonImplyingRules *ImplyingRulesType,
protocolsAndPorts map[v1.Protocol][]PortRange) string {
if allProtocolsAndPorts || len(protocolsAndPorts) == 0 {
connStr := noConnsStr
if allProtocolsAndPorts {
connStr = allConnsStr
}
return connStr + commonImplyingRules.String()

}
var connStr string
// connStrings will contain the string of given conns protocols and ports as is
Expand Down

0 comments on commit 52d3235

Please sign in to comment.