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

handling selectors with matchexpressions (fixed) #377

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
2fef0d0
support match expression operators for generating and selecting repr…
shireenf-ibm Jun 23, 2024
361c6ab
more tests
shireenf-ibm Jun 11, 2024
f5dedf0
more tests
shireenf-ibm Jun 23, 2024
31e1ec4
updating code with label selectors
shireenf-ibm Jun 27, 2024
f975c11
merge fixes
shireenf-ibm Jun 27, 2024
63ff816
Merge branch 'new_exposure_analysis_first_branch' of github.com:np-gu…
shireenf-ibm Jun 27, 2024
b53ad1e
duplicated tests with matching pods
shireenf-ibm Jun 29, 2024
5789f65
fixing code + tests with multiple policies
shireenf-ibm Jul 3, 2024
f770e7c
update comments in exposure.go
shireenf-ibm Jul 15, 2024
9928c9c
renaming function and updating comments and doc of representative_sel…
shireenf-ibm Jul 15, 2024
cc0cbc1
move `RepresentativeNsLabelSelector` field from namespace.go to pod.go
shireenf-ibm Jul 15, 2024
4d76f6b
1. reverting changes to AddPodByNameAndNamespace and resolveSingleMis…
shireenf-ibm Jul 15, 2024
ea563f2
avoid duplicating code of generating the default namespace name map; …
shireenf-ibm Jul 15, 2024
ca9cb67
eliminate representativePeer.PotentialNamespaceLabelSelector as it du…
shireenf-ibm Jul 15, 2024
6ce26dc
renaming the func in representative_selectors.go again
shireenf-ibm Jul 16, 2024
2a76b89
a new test with handling a special case of equiv rules written in a d…
shireenf-ibm Jul 16, 2024
d9e964a
unit test for representative_selectors.go
shireenf-ibm Jul 16, 2024
99b4286
removing redundant code
shireenf-ibm Jul 17, 2024
cbc399d
updating documentation of new fields in pod.go
shireenf-ibm Jul 17, 2024
5f13394
fixes in resources.go
shireenf-ibm Jul 17, 2024
f0c25d2
fix in check.go
shireenf-ibm Jul 17, 2024
4b19196
update few comments
adisos Jul 22, 2024
e2a19f0
renaming AddObjects + updating its documentation
shireenf-ibm Jul 22, 2024
75f8659
renaming netpol funcs
shireenf-ibm Jul 22, 2024
aaf72f0
renaming connPeers
shireenf-ibm Jul 22, 2024
b8cda5a
fixing representative pods naming and updating relevant funcs
shireenf-ibm Jul 22, 2024
caf949b
renaming "GeneralConns" to "ExposedGeneralConns"
shireenf-ibm Jul 24, 2024
ebcd659
removing PolicyNsFlag
shireenf-ibm Jul 24, 2024
03e384e
no need to split namespaces with policies at first
shireenf-ibm Jul 24, 2024
659d6d0
Revert "no need to split namespaces with policies at first"
shireenf-ibm Jul 24, 2024
f2dcfd9
rename extractLabelsAndRefineRepresentativePeers and refineRepresen…
shireenf-ibm Jul 24, 2024
4f517b6
renaming checkIfP2PConnOrExposureConn
shireenf-ibm Jul 24, 2024
f1b2628
lint fix
shireenf-ibm Jul 24, 2024
eb68a3f
func allAllowedConnectionsBetweenPeers: remove ingressSet, egressSet
shireenf-ibm Jul 24, 2024
d3bd525
using new terms for general conns : ClusterWideExposure and ExternalE…
shireenf-ibm Jul 24, 2024
4df60cc
an example why should split namespaces at the beginning with the poli…
shireenf-ibm Jul 24, 2024
8d66c49
eliminate RepresentativePeer struct
shireenf-ibm Jul 25, 2024
1982e8f
fixing some typos and adding some very used words to a cspell file
shireenf-ibm Jul 25, 2024
a0ba193
more typos fixes
shireenf-ibm Jul 25, 2024
870f4e8
updating some comments
shireenf-ibm Jul 25, 2024
a5e310f
updating readme (all formats supported)
shireenf-ibm Jul 28, 2024
942f08b
getting netpols before pods for live cluster - so it works well for b…
shireenf-ibm Jul 28, 2024
204c571
Update pkg/netpol/eval/check.go
shireenf-ibm Jul 30, 2024
6fad7cf
Update pkg/netpol/eval/check.go
shireenf-ibm Jul 30, 2024
58e1a73
Update pkg/netpol/eval/exposure.go
shireenf-ibm Jul 30, 2024
7ec8f37
Update pkg/netpol/eval/exposure.go
shireenf-ibm Jul 30, 2024
9b89927
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 30, 2024
67361d7
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 30, 2024
3105bda
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 30, 2024
53e5589
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 30, 2024
5b1fb32
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 30, 2024
78e17b8
Update pkg/netpol/eval/exposure.go
shireenf-ibm Jul 30, 2024
82950bc
Update pkg/netpol/eval/exposure.go
shireenf-ibm Jul 30, 2024
31008cf
Update pkg/netpol/eval/exposure.go
shireenf-ibm Jul 30, 2024
6460edc
rename getSelectorsAndUpdateExposedGeneralConns
shireenf-ibm Jul 30, 2024
23de7f0
rename ScanPolicyRulesAndUpdateExposedWideConns
shireenf-ibm Jul 30, 2024
6f36048
rename updateNetworkPolicyWideExposureConns
shireenf-ibm Jul 30, 2024
90fdcc7
Update pkg/netpol/eval/resources.go
shireenf-ibm Jul 31, 2024
068eeac
Merge branch 'new_handling_selectors_with_matchexpressions' of github…
shireenf-ibm Jul 31, 2024
0cd741c
Update pkg/netpol/eval/internal/k8s/peer.go
shireenf-ibm Jul 31, 2024
c8a89ae
Update pkg/netpol/eval/internal/k8s/peer.go
shireenf-ibm Jul 31, 2024
9f20450
Update pkg/netpol/eval/internal/k8s/pod.go
shireenf-ibm Jul 31, 2024
b66ad0c
Update pkg/netpol/eval/internal/k8s/pod.go
shireenf-ibm Jul 31, 2024
707a742
Update pkg/netpol/eval/resources.go
shireenf-ibm Jul 31, 2024
b877bb6
Update pkg/netpol/eval/resources.go
shireenf-ibm Jul 31, 2024
d3c12ee
fixing lint
shireenf-ibm Jul 31, 2024
6e3fe48
Update pkg/netpol/eval/internal/k8s/representative_selectors.go
shireenf-ibm Jul 31, 2024
8de7c24
lint fix
shireenf-ibm Jul 31, 2024
dba327a
Update pkg/netpol/eval/internal/k8s/representative_selectors.go
shireenf-ibm Jul 31, 2024
628a592
fixing the last commit
shireenf-ibm Jul 31, 2024
7565f1f
fixing the SelectorsFullMatch doc
shireenf-ibm Jul 31, 2024
e14f7ca
removing unnecessaryDeepCopy calls
shireenf-ibm Jul 31, 2024
18f4dd4
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 31, 2024
a759598
Update pkg/netpol/eval/internal/k8s/netpol.go
shireenf-ibm Jul 31, 2024
df836b3
lint fix
shireenf-ibm Jul 31, 2024
ca95c20
some renamings in representative_selectors + document why returning f…
shireenf-ibm Jul 31, 2024
e035016
adding line to comment
shireenf-ibm Jul 31, 2024
a3f434c
split funcs in check.go for readability
shireenf-ibm Jul 31, 2024
a96bb43
rename hasRepresentativePod
shireenf-ibm Jul 31, 2024
4fe2b03
updating comment
shireenf-ibm Jul 31, 2024
3723844
updating comment of storing the named port
shireenf-ibm Jul 31, 2024
ff31b89
updating String() func of workloadpeer
shireenf-ibm Jul 31, 2024
230e942
comment update
shireenf-ibm Jul 31, 2024
b107e7e
updating comment
shireenf-ibm Jul 31, 2024
64fbe59
new func of selectors match in `netpol.go` to avoid duplicates
shireenf-ibm Aug 1, 2024
52278a7
updating comment in pod.go (what do the combinations of rep selectors…
shireenf-ibm Aug 1, 2024
9572ad4
renaming str vars
shireenf-ibm Aug 1, 2024
ff7c637
eliminating addIfMissingNamespace func
shireenf-ibm Aug 1, 2024
f04ae1d
new tests - rep peers when there is real ns but no real pods matching
shireenf-ibm Aug 1, 2024
f0fb5a3
add comment on String() func
shireenf-ibm Aug 1, 2024
b6d0f3e
rename handleRequirementWithInOpAndSingleValue
shireenf-ibm Aug 1, 2024
e744b53
renaming test dirs and expected output of exposure-analysis tests
shireenf-ibm Aug 4, 2024
c786a27
new fixes
shireenf-ibm Aug 5, 2024
4336adc
Merge branch 'new_exposure_analysis_first_branch' of github.com:np-gu…
shireenf-ibm Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
133 changes: 133 additions & 0 deletions pkg/netpol/connlist/connlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,4 +956,137 @@ var goodPathTests = []struct {
exposureAnalysis: true,
outputFormats: ValidFormats,
},
// tests on exposure with matchExpression selectors (generating representative peers from selectors with matchExpression
// requires special handling)
{
testDirName: "test_exposure_with_match_expression_not_in_op",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_in_op",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_exists_op",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_does_not_exist_op",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_rule_with_multiple_match_expressions",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_1",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_2",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_3",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_4",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_5",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_6",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_multiple_policies_1", // one workload in manifests
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_multiple_policies_2", // two workloads in manifests, each policy captures one
exposureAnalysis: true,
outputFormats: ValidFormats,
},
// some exposure tests with matching expressions (from above) with also matching pod/s in the manifests
{
testDirName: "test_egress_exposure_with_named_port_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_rule_with_multiple_match_expressions_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_2_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_3_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_4_with_matching_pods",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_5_with_matching_pods",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_different_rules_6_with_matching_pods",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_does_not_exist_op_with_matching_pods",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_exists_op_with_matching_pods",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_in_op_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_match_expression_not_in_op_with_matching_pods",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_new_namespace_conn_and_entire_cluster_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
{
testDirName: "test_exposure_with_multiple_policies_1_with_matching_pod",
exposureAnalysis: true,
outputFormats: ValidFormats,
},
}
62 changes: 45 additions & 17 deletions pkg/netpol/connlist/conns_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

"github.com/np-guard/netpol-analyzer/pkg/netpol/internal/common"
Expand Down Expand Up @@ -77,11 +78,16 @@ func formSingleP2PConn(conn Peer2PeerConnection) singleConnFields {
return singleConnFields{Src: conn.Src().String(), Dst: conn.Dst().String(), ConnString: connStr}
}

// commonly (to be) used for exposure analysis output formatters
const (
entireCluster = "entire-cluster"
exposureAnalysisHeader = "Exposure Analysis Result:"
egressExposureHeader = "Egress Exposure:"
ingressExposureHeader = "Ingress Exposure:"
stringInBrackets = "[%s]"
mapOpen = "{"
mapClose = "}"
comma = ","
)

// formSingleExposureConn returns a representation of single exposure connection fields as singleConnFields object
Expand All @@ -108,24 +114,46 @@ func convertLabelsMapToString(labelsMap map[string]string) string {
return labels.SelectorFromSet(labels.Set(labelsMap)).String()
}

const (
stringInBrackets = "[%s]"
mapOpen = "{"
mapClose = "}"
)
// convertRequirementsToString returns a string representation of the given requirements list
func convertRequirementsToString(reqs []v1.LabelSelectorRequirement) string {
const strPrefix = "&LabelSelectorRequirement"
reqStrings := make([]string, len(reqs))
for i, req := range reqs {
reqStrings[i] = strings.ReplaceAll(req.String(), strPrefix, "")
}
sort.Strings(reqStrings)
return strings.Join(reqStrings, comma)
}

// writeLabelSelectorAsString returns a string representation of the label selector
func writeLabelSelectorAsString(labelSel v1.LabelSelector) string {
var res string
if len(labelSel.MatchLabels) > 0 {
res = convertLabelsMapToString(labelSel.MatchLabels)
}
if len(labelSel.MatchExpressions) > 0 {
if len(labelSel.MatchLabels) > 0 {
res += comma
}
res += convertRequirementsToString(labelSel.MatchExpressions)
}
return res
}

// getRepresentativeNamespaceString returns a string representation of a potential peer with namespace labels.
// if namespace with multiple words adds [] , in case of textual (non-graphical) output
func getRepresentativeNamespaceString(nsLabels map[string]string, txtOutFlag bool) string {
nsName, ok := nsLabels[common.K8sNsNameLabelKey]
if len(nsLabels) == 1 && ok {
func getRepresentativeNamespaceString(nsLabels v1.LabelSelector, txtOutFlag bool) string {
// if ns selector contains only namespace name label - return ns name
nsName, ok := nsLabels.MatchLabels[common.K8sNsNameLabelKey]
if len(nsLabels.MatchLabels) == 1 && len(nsLabels.MatchExpressions) == 0 && ok {
return nsName
}
res := ""
if len(nsLabels) > 0 {
res += "namespace with " + mapOpen + convertLabelsMapToString(nsLabels) + mapClose
// else if ns labels are empty - res = all namespaces
var res string
if nsLabels.Size() == 0 {
res = allNamespacesLbl
} else {
res += allNamespacesLbl
res = "namespace with " + mapOpen + writeLabelSelectorAsString(nsLabels) + mapClose
}
if txtOutFlag {
return fmt.Sprintf(stringInBrackets, res)
Expand All @@ -136,12 +164,12 @@ func getRepresentativeNamespaceString(nsLabels map[string]string, txtOutFlag boo
// getRepresentativePodString returns a string representation of potential peer with pod labels
// or all pods string for empty pod labels map (which indicates all pods).
// adds [] in case of textual (non-graphical) output
func getRepresentativePodString(podLabels map[string]string, txtOutFlag bool) string {
res := ""
if len(podLabels) == 0 {
res += allPeersLbl
func getRepresentativePodString(podLabels v1.LabelSelector, txtOutFlag bool) string {
var res string
if podLabels.Size() == 0 {
res = allPeersLbl
} else {
res += "pod with " + mapOpen + convertLabelsMapToString(podLabels) + mapClose
res = "pod with " + mapOpen + writeLabelSelectorAsString(podLabels) + mapClose
}
if txtOutFlag {
return fmt.Sprintf(stringInBrackets, res)
Expand Down
14 changes: 9 additions & 5 deletions pkg/netpol/connlist/exposed_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ SPDX-License-Identifier: Apache-2.0
*/
package connlist

import "github.com/np-guard/netpol-analyzer/pkg/netpol/internal/common"
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/np-guard/netpol-analyzer/pkg/netpol/internal/common"
)

// ExposedPeer captures potential ingress and egress connections data for an exposed Peer
type ExposedPeer interface {
Expand All @@ -32,10 +36,10 @@ type ExposedPeer interface {
type XgressExposureData interface {
// IsExposedToEntireCluster indicates if the peer is exposed to all namespaces in the cluster for the relevant direction
IsExposedToEntireCluster() bool
// NamespaceLabels are matchLabels of potential namespaces which the peer might be exposed to
NamespaceLabels() map[string]string
// PodLabels are matchLabels of potential pods which the peer might be exposed to
PodLabels() map[string]string
// NamespaceLabels are label selectors of potential namespaces which the peer might be exposed to
NamespaceLabels() v1.LabelSelector
// PodLabels are label selectors of potential pods which the peer might be exposed to
PodLabels() v1.LabelSelector
// PotentialConnectivity the potential connectivity of the exposure
PotentialConnectivity() common.Connection
}
14 changes: 8 additions & 6 deletions pkg/netpol/connlist/exposure_analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SPDX-License-Identifier: Apache-2.0
package connlist

import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/np-guard/netpol-analyzer/pkg/netpol/internal/common"
)

Expand Down Expand Up @@ -34,12 +36,12 @@ type peerXgressExposureData struct {
type xgressExposure struct {
// exposedToEntireCluster indicates if the peer is exposed to all namespaces in the cluster for the relevant direction
exposedToEntireCluster bool
// namespaceLabels are matchLabels of potential namespaces which the peer might be exposed to.
// namespaceLabels are label selectors of potential namespaces which the peer might be exposed to.
// if exposedToEntireCluster is true, this field will be empty
namespaceLabels map[string]string
// podLabels are matchLabels of potential pods which the peer might be exposed to.
namespaceLabels v1.LabelSelector
// podLabels are label selectors of potential pods which the peer might be exposed to.
// if exposedToEntireCluster is true, this field will be empty
podLabels map[string]string
podLabels v1.LabelSelector
// potentialConn the potential connectivity of the exposure
potentialConn *common.ConnectionSet
}
Expand All @@ -48,11 +50,11 @@ func (e *xgressExposure) IsExposedToEntireCluster() bool {
return e.exposedToEntireCluster
}

func (e *xgressExposure) NamespaceLabels() map[string]string {
func (e *xgressExposure) NamespaceLabels() v1.LabelSelector {
return e.namespaceLabels
}

func (e *xgressExposure) PodLabels() map[string]string {
func (e *xgressExposure) PodLabels() v1.LabelSelector {
return e.podLabels
}

Expand Down
30 changes: 19 additions & 11 deletions pkg/netpol/connlist/exposure_analysis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

v1 "k8s.io/api/core/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/np-guard/netpol-analyzer/pkg/internal/testutils"
Expand Down Expand Up @@ -46,6 +47,9 @@ var peerExposedToEntireClusterOnTCP8050 *xgressExposure = &xgressExposure{
potentialConn: newTCPConnWithPorts([]int{8050}),
}

var matchExpression []metaV1.LabelSelectorRequirement = []metaV1.LabelSelectorRequirement{{Key: "foo.com/managed-state",
Operator: metaV1.LabelSelectorOpIn, Values: []string{"managed"}}}

func newTCPConnWithPorts(ports []int) *common.ConnectionSet {
conn := common.MakeConnectionSet(false)
portSet := common.MakePortSet(false)
Expand All @@ -56,15 +60,15 @@ func newTCPConnWithPorts(ports []int) *common.ConnectionSet {
return conn
}

func newExpDataWithLabelAndTCPConn(nsLabels, podLabels map[string]string, ports []int) *xgressExposure {
func newExpDataWithLabelAndTCPConn(nsSel, podSel metaV1.LabelSelector, ports []int) *xgressExposure {
conn := common.MakeConnectionSet(true)
if len(ports) > 0 {
conn = newTCPConnWithPorts(ports)
}
return &xgressExposure{
exposedToEntireCluster: false,
namespaceLabels: nsLabels,
podLabels: podLabels,
namespaceLabels: nsSel,
podLabels: podSel,
potentialConn: conn,
}
}
Expand Down Expand Up @@ -149,7 +153,7 @@ func TestExposureBehavior(t *testing.T) {
lenIngressExposedConns: 2,
ingressExp: []*xgressExposure{
peerExposedToEntireClusterOnTCP8050,
newExpDataWithLabelAndTCPConn(map[string]string{"foo.com/managed-state": "managed"}, nil, []int{8050, 8090}),
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchExpressions: matchExpression}, metaV1.LabelSelector{}, []int{8050, 8090}),
},
lenEgressExposedConns: 0,
},
Expand Down Expand Up @@ -184,9 +188,11 @@ func TestExposureBehavior(t *testing.T) {
isEgressProtected: false,
lenIngressExposedConns: 3,
ingressExp: []*xgressExposure{
newExpDataWithLabelAndTCPConn(map[string]string{"foo.com/managed-state": "managed"}, nil, []int{8050}),
newExpDataWithLabelAndTCPConn(map[string]string{"release": "stable"}, nil, []int{}),
newExpDataWithLabelAndTCPConn(map[string]string{"effect": "NoSchedule"}, nil, []int{8050}),
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchExpressions: matchExpression}, metaV1.LabelSelector{}, []int{8050}),
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchLabels: map[string]string{"release": "stable"}},
metaV1.LabelSelector{}, []int{}),
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchLabels: map[string]string{"effect": "NoSchedule"}},
metaV1.LabelSelector{}, []int{8050}),
},
lenEgressExposedConns: 0,
},
Expand Down Expand Up @@ -262,8 +268,8 @@ func TestExposureBehavior(t *testing.T) {
lenIngressExposedConns: 1,
lenEgressExposedConns: 1,
ingressExp: []*xgressExposure{
newExpDataWithLabelAndTCPConn(map[string]string{common.K8sNsNameLabelKey: "backend"},
map[string]string{}, []int{8050}),
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchLabels: map[string]string{common.K8sNsNameLabelKey: "backend"}},
metaV1.LabelSelector{}, []int{8050}),
},
egressExp: []*xgressExposure{
peerExposedToEntireCluster,
Expand All @@ -280,7 +286,8 @@ func TestExposureBehavior(t *testing.T) {
lenIngressExposedConns: 1,
lenEgressExposedConns: 0,
ingressExp: []*xgressExposure{
newExpDataWithLabelAndTCPConn(map[string]string{"effect": "NoSchedule"}, map[string]string{"role": "monitoring"}, []int{8050}),
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchLabels: map[string]string{"effect": "NoSchedule"}},
metaV1.LabelSelector{MatchLabels: map[string]string{"role": "monitoring"}}, []int{8050}),
},
},
},
Expand All @@ -294,7 +301,8 @@ func TestExposureBehavior(t *testing.T) {
lenIngressExposedConns: 1,
lenEgressExposedConns: 0,
ingressExp: []*xgressExposure{
newExpDataWithLabelAndTCPConn(map[string]string{common.K8sNsNameLabelKey: "hello-world"}, map[string]string{"role": "monitoring"},
newExpDataWithLabelAndTCPConn(metaV1.LabelSelector{MatchLabels: map[string]string{common.K8sNsNameLabelKey: "hello-world"}},
metaV1.LabelSelector{MatchLabels: map[string]string{"role": "monitoring"}},
[]int{8050}),
},
},
Expand Down
Loading