Skip to content

Commit

Permalink
adding minimal example for connectivity analysis and diff (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
shireenf-ibm authored Aug 8, 2023
1 parent 75f57a8 commit 448241d
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/netpol/connlist/connlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func TestConnList(t *testing.T) {
testDirName: "test_with_named_ports",
outputFormats: []string{common.TextFormat},
},
{
testDirName: "netpol-analysis-example-minimal",
outputFormats: []string{common.TextFormat},
},
}

for _, entry := range testingEntries {
Expand Down
7 changes: 7 additions & 0 deletions pkg/netpol/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func TestDiff(t *testing.T) {
secondDirName: "acs-security-demos-added-workloads",
formats: allFormats,
},
{
// description:
// **changed netpols : default/backend-netpol,
firstDirName: "netpol-analysis-example-minimal",
secondDirName: "netpol-diff-example-minimal",
formats: allFormats,
},
}

for _, entry := range testingEntries {
Expand Down
53 changes: 53 additions & 0 deletions tests/netpol-analysis-example-minimal/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec:
selector:
matchLabels:
app: backendservice
template:
metadata:
labels:
app: backendservice
spec:
containers:
- name: server
image: backendservice
ports:
- containerPort: 9090
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 9090
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 9090
env:
- name: PORT
value: "9090"
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: backendservice
spec:
type: ClusterIP
selector:
app: backendservice
ports:
- name: http
port: 9090
targetPort: 9090

3 changes: 3 additions & 0 deletions tests/netpol-analysis-example-minimal/connlist_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0.0.0.0-255.255.255.255 => default/frontend[Deployment] : TCP 8080
default/frontend[Deployment] => 0.0.0.0-255.255.255.255 : UDP 53
default/frontend[Deployment] => default/backend[Deployment] : TCP 9090
67 changes: 67 additions & 0 deletions tests/netpol-analysis-example-minimal/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: server
image: frontend
ports:
- containerPort: 8080
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 8080
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 8080
env:
- name: PORT
value: "8080"
- name: BACKEND_SERVICE_ADDR
value: "backendservice:9090"
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
type: ClusterIP
selector:
app: frontend
ports:
- name: http
port: 80
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: frontend-external
spec:
type: LoadBalancer
selector:
app: frontend
ports:
- name: http
port: 80
targetPort: 8080
65 changes: 65 additions & 0 deletions tests/netpol-analysis-example-minimal/netpols.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
creationTimestamp: null
name: backend-netpol
spec:
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
ports:
- port: 9090
protocol: TCP
podSelector:
matchLabels:
app: backendservice
policyTypes:
- Ingress
- Egress
status: {}

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
creationTimestamp: null
name: frontend-netpol
spec:
egress:
- ports:
- port: 9090
protocol: TCP
to:
- podSelector:
matchLabels:
app: backendservice
- ports:
- port: 53
protocol: UDP
ingress:
- ports:
- port: 8080
protocol: TCP
podSelector:
matchLabels:
app: frontend
policyTypes:
- Ingress
- Egress
status: {}

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
creationTimestamp: null
name: default-deny-in-namespace
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
status: {}

53 changes: 53 additions & 0 deletions tests/netpol-diff-example-minimal/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec:
selector:
matchLabels:
app: backendservice
template:
metadata:
labels:
app: backendservice
spec:
containers:
- name: server
image: backendservice
ports:
- containerPort: 9090
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 9090
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 9090
env:
- name: PORT
value: "9090"
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: backendservice
spec:
type: ClusterIP
selector:
app: backendservice
ports:
- name: http
port: 9090
targetPort: 9090

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source,destination,dir1,dir2,diff-type
default/frontend[Deployment],default/backend[Deployment],TCP 9090,"TCP 9090,UDP 53",changed
0.0.0.0-255.255.255.255,default/backend[Deployment],No Connections,TCP 9090,added
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| source | destination | dir1 | dir2 | diff-type |
|--------|-------------|------|------|-----------|
| default/frontend[Deployment] | default/backend[Deployment] | TCP 9090 | TCP 9090,UDP 53 | changed |
| 0.0.0.0-255.255.255.255 | default/backend[Deployment] | No Connections | TCP 9090 | added |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Connectivity diff:
source: default/frontend[Deployment], destination: default/backend[Deployment], dir1: TCP 9090, dir2: TCP 9090,UDP 53, diff-type: changed
source: 0.0.0.0-255.255.255.255, destination: default/backend[Deployment], dir1: No Connections, dir2: TCP 9090, diff-type: added
67 changes: 67 additions & 0 deletions tests/netpol-diff-example-minimal/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: server
image: frontend
ports:
- containerPort: 8080
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 8080
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 8080
env:
- name: PORT
value: "8080"
- name: BACKEND_SERVICE_ADDR
value: "backendservice:9090"
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
type: ClusterIP
selector:
app: frontend
ports:
- name: http
port: 80
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: frontend-external
spec:
type: LoadBalancer
selector:
app: frontend
ports:
- name: http
port: 80
targetPort: 8080
Loading

0 comments on commit 448241d

Please sign in to comment.