Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid ingress-controller name and ns duplication #260

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/netpol/common/netpol_commands_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ type NetpolError interface {
Location() string
}

// Ingress Controller const - the name and namespace of an ingress-controller pod
const (
// The actual ingress controller pod is usually unknown and not available in the input resources for the analysis.
// IngressPodName and IngressPodNamespace are used to represent that pod with those placeholder values for name and namespace.
IngressPodName = "ingress-controller"
IngressPodNamespace = "ingress-controller-ns"
)

// formats supported for output of various commands
const (
DefaultFormat = "txt"
Expand Down
4 changes: 2 additions & 2 deletions pkg/netpol/connlist/connlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (ca *ConnlistAnalyzer) getConnectionsList(pe *eval.PolicyEngine, ia *ingres
// or if it exists in the peers list from the parsed resources
// if not returns a suitable warning message
func (ca *ConnlistAnalyzer) existsFocusWorkload(peers []Peer, excludeIngressAnalysis bool) (existFocusWorkload bool, warning string) {
if ca.focusWorkload == ingressanalyzer.IngressPodName {
if ca.focusWorkload == common.IngressPodName {
if excludeIngressAnalysis { // if the ingress-analyzer is empty,
// then no routes/k8s-ingress objects -> ingrss-controller pod will not be added
return false, "The ingress-controller workload was not added to the analysis, since Ingress/Route resources were not found." +
Expand Down Expand Up @@ -464,7 +464,7 @@ func (ca *ConnlistAnalyzer) getIngressAllowedConnections(ia *ingressanalyzer.Ing
return nil, err
}
// adding the ingress controller pod to the policy engine,
ingressControllerPod, err := pe.AddPodByNameAndNamespace(ingressanalyzer.IngressPodName, ingressanalyzer.IngressPodNamespace)
ingressControllerPod, err := pe.AddPodByNameAndNamespace(common.IngressPodName, common.IngressPodNamespace)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ import (
"github.com/np-guard/netpol-analyzer/pkg/netpol/manifests/parser"
)

const (
// The actual ingress controller pod is usually unknown and not available in the input resources for the analysis.
// IngressPodName and IngressPodNamespace are used to represent that pod with those placeholder values for name and namespace.
IngressPodName = "ingress-controller"
IngressPodNamespace = "ingress-controller-ns"
)

type serviceInfo struct {
// used to populate routesToServicesMap and k8sIngressToServicesMap with their target services info
serviceName string
Expand Down
5 changes: 1 addition & 4 deletions pkg/netpol/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,8 @@ func (c *connsPair) isSrcOrDstPeerIPType(checkSrc bool) bool {
return (checkSrc && src.IsPeerIPType()) || (!checkSrc && dst.IsPeerIPType())
}

// helpers to check if a peer is ingress-controller (a peer created while ingress analysis)
const ingressControllerPodName = "{ingress-controller}"

func isIngressControllerPeer(peer eval.Peer) bool {
return peer.String() == ingressControllerPodName
return peer.Name() == common.IngressPodName
}

// updateNewOrLostFields updates ConnsPair's newOrLostSrc and newOrLostDst values
Expand Down