Skip to content

Commit 1b0735c

Browse files
authored
fix issue #550 + add test (#552)
Signed-off-by: adisos <[email protected]>
1 parent c4e1aef commit 1b0735c

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed

nca/NetworkConfig/NetworkConfigQuery.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,17 +2033,12 @@ def exec(self):
20332033
self.output_config.fullExplanation = True # assign true for this query - it is always ok to compare its results
20342034
# get_all_peers_group() does not require getting dnsEntry peers, since they are not ClusterEP (pods)
20352035
existing_pods = self.config.peer_container.get_all_peers_group()
2036-
if not self.config:
2036+
if not self.config or self.config.policies_container.layers.does_contain_single_layer(NetworkLayerName.Ingress):
20372037
return QueryAnswer(bool_result=False,
20382038
output_result=f'There are no network policies in {self.config.name}. '
20392039
f'All workload resources are non captured',
20402040
numerical_result=len(existing_pods))
20412041

2042-
if self.config.policies_container.layers.does_contain_single_layer(NetworkLayerName.Ingress):
2043-
return QueryAnswer(bool_result=False,
2044-
output_result='AllCapturedQuery cannot be applied using Ingress resources only',
2045-
query_not_executed=True)
2046-
20472042
k8s_calico_pods_list_explanation, k8s_calico_res = self._compute_uncaptured_pods_by_layer(NetworkLayerName.K8s_Calico)
20482043
istio_pods_list_explanation, istio_res = self._compute_uncaptured_pods_by_layer(NetworkLayerName.Istio, True)
20492044

tests/expected_runtime/k8s_tests_expected_runtime.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,5 @@ k8s_testcases/example_policies/withIpBlock2/withIpBlock2-scheme.yaml,5.51
139139
k8s_testcases/example_policies/workload-resources-test/file-system-resource-test-scheme.yaml,0.07
140140
k8s_testcases/example_policies/workload-resources-test/git-resource-test-scheme.yaml,7.66
141141
k8s_testcases/network-policy-checks-bad-path/network-policy-check-bad-path-scheme.yaml,0.80
142-
k8s_testcases/ingress-bad-path-test/test-ingress-bad-port-scheme.yaml,0.06
142+
k8s_testcases/ingress-bad-path-test/test-ingress-bad-port-scheme.yaml,0.06
143+
k8s_testcases/example_policies/sample-app/sample-all-captured-scheme.yaml,0.08
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resourceList: []
2+
networkConfigList:
3+
- name: sample
4+
resourceList:
5+
- ./**
6+
queries:
7+
- name: sample-all-captured
8+
allCaptured:
9+
- sample
10+
expected: 2
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: my-service-ingress
5+
namespace: sample
6+
spec:
7+
rules:
8+
- host: my-app.domain
9+
http:
10+
paths:
11+
- path: /
12+
pathType: Prefix
13+
backend:
14+
service:
15+
name: my-service
16+
port:
17+
number: 8080
18+
---
19+
20+
apiVersion: v1
21+
kind: Service
22+
metadata:
23+
name: my-service
24+
namespace: sample
25+
labels:
26+
app: my-app
27+
spec:
28+
type: ClusterIP
29+
ports:
30+
- port: 8080
31+
targetPort: 8080
32+
selector:
33+
app: my-app
34+
35+
---
36+
apiVersion: apps/v1
37+
kind: Deployment
38+
metadata:
39+
name: my-app
40+
namespace: sample
41+
spec:
42+
replicas: 1
43+
selector:
44+
matchLabels:
45+
app: my-app
46+
template:
47+
metadata:
48+
labels:
49+
app: my-app
50+
spec:
51+
serviceAccountName: sample
52+
containers:
53+
- name: my-app
54+
image: webapp:1
55+
ports:
56+
- containerPort: 8080

0 commit comments

Comments
 (0)