Skip to content

Commit 3bc1a1f

Browse files
authored
[CI] Add Cyclonus to merge validation (#860)
1 parent 8648739 commit 3bc1a1f

File tree

7 files changed

+160
-8
lines changed

7 files changed

+160
-8
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Cyclonus Network Policy Test
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
schedule:
10+
# run once a day at midnight
11+
- cron: '0 0 * * *'
12+
13+
jobs:
14+
cyclonus-test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Make NPM image
21+
run: |
22+
VERSION=cyclonus make azure-npm-image
23+
24+
- name: Setup Kind
25+
uses: engineerd/[email protected]
26+
with:
27+
version: "v0.9.0"
28+
config: ./test/kind/kind.yaml
29+
name: npm-kind
30+
31+
- name: Install Azure NPM
32+
run: |
33+
sed -i 's/mcr.microsoft.com\/containernetworking\/azure-npm:v1.3.1/acnpublic.azurecr.io\/azure-npm:cyclonus/' ./npm/azure-npm.yaml
34+
kind load docker-image acnpublic.azurecr.io/azure-npm:cyclonus --name npm-kind
35+
kubectl apply -f ./npm/azure-npm.yaml
36+
37+
- name: Run Cyclonus network policy test
38+
run: make test-cyclonus
39+
40+
- name: Fetch logs
41+
if: always()
42+
run: |
43+
kubectl logs -n kube-system -l k8s-app=azure-npm --tail -1 --prefix > npm-logs.txt
44+
mv ./test/cyclonus/cyclonus-test.txt ./cyclonus-test.txt
45+
46+
- name: 'Upload Logs'
47+
uses: actions/upload-artifact@v2
48+
if: always()
49+
with:
50+
name: logs
51+
path: |
52+
./npm-logs.txt
53+
./cyclonus-test.txt
54+

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,14 @@ test-all:
461461
# run all tests
462462
.PHONY: test-integration
463463
test-integration:
464-
go test -coverpkg=./... -v -race -covermode atomic -coverprofile=coverage.out -tags=integration ./test/integration...
464+
go test -coverpkg=./... -v -race -covermode atomic -coverprofile=coverage.out -tags=integration ./test/integration...
465+
466+
.PHONY: test-cyclonus
467+
test-cyclonus:
468+
cd test/cyclonus && bash ./test-cyclonus.sh
469+
cd ..
470+
471+
.PHONY: kind
472+
kind:
473+
kind create cluster --config ./test/kind/kind.yaml
474+

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Microsoft Azure Container Networking
22

33
[![Build Status](https://msazure.visualstudio.com/One/_apis/build/status/Custom/Networking/ContainerNetworking/Azure.azure-container-networking?branchName=master)](https://msazure.visualstudio.com/One/_build/latest?definitionId=95007&branchName=master) [![Go Report Card](https://goreportcard.com/badge/github.com/Azure/azure-container-networking)](https://goreportcard.com/report/github.com/Azure/azure-container-networking) ![GitHub release](https://img.shields.io/github/release/Azure/azure-container-networking.svg)
4-
[![codecov](https://codecov.io/gh/Azure/azure-container-networking/branch/master/graph/badge.svg)](https://codecov.io/gh/Azure/azure-container-networking)
4+
5+
| Azure Network Policy Manager Conformance | |
6+
| ----------- | ----------- |
7+
| Cyclonus Network Policy Suite | [![Cyclonus Network Policy Test](https://github.com/Azure/azure-container-networking/actions/workflows/cyclonus-netpol-test.yaml/badge.svg?branch=master)](https://github.com/Azure/azure-container-networking/actions/workflows/cyclonus-netpol-test.yaml) |
8+
| Kubernetes Network Policy E2E | [![Build Status](https://dev.azure.com/msazure/One/_apis/build/status/Custom/Networking/ContainerNetworking/NPM%20Conformance%20Tests?branchName=master)](https://dev.azure.com/msazure/One/_build/latest?definitionId=195725&branchName=master) |
9+
10+
511

612
## Overview
713
This repository contains container networking services and plugins for Linux and Windows containers running on Azure:

npm/azure-npm.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
labels:
77
addonmanager.kubernetes.io/mode: EnsureExists
88
---
9-
apiVersion: rbac.authorization.k8s.io/v1beta1
9+
apiVersion: rbac.authorization.k8s.io/v1
1010
kind: ClusterRole
1111
metadata:
1212
name: azure-npm
@@ -33,7 +33,7 @@ rules:
3333
- list
3434
- watch
3535
---
36-
apiVersion: rbac.authorization.k8s.io/v1beta1
36+
apiVersion: rbac.authorization.k8s.io/v1
3737
kind: ClusterRoleBinding
3838
metadata:
3939
name: azure-npm-binding
@@ -77,12 +77,10 @@ spec:
7777
effect: NoSchedule
7878
- key: CriticalAddonsOnly
7979
operator: Exists
80-
nodeSelector:
81-
beta.kubernetes.io/os: linux
82-
kubernetes.io/role: agent
80+
8381
containers:
8482
- name: azure-npm
85-
image: mcr.microsoft.com/containernetworking/azure-npm:v1.1.5
83+
image: mcr.microsoft.com/containernetworking/azure-npm:v1.3.1
8684
resources:
8785
limits:
8886
cpu: 250m
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: cyclonus
5+
namespace: kube-system
6+
labels:
7+
app: cyclonus
8+
spec:
9+
template:
10+
spec:
11+
restartPolicy: Never
12+
containers:
13+
- command:
14+
- ./cyclonus
15+
- generate
16+
- --noisy=true
17+
- --ignore-loopback=true
18+
- --cleanup-namespaces=true
19+
- --perturbation-wait-seconds=5
20+
- --pod-creation-timeout-seconds=20
21+
- --job-timeout-seconds=2
22+
- --server-protocol=TCP,UDP
23+
- --server-port=80
24+
name: cyclonus
25+
imagePullPolicy: IfNotPresent
26+
image: mfenwick100/cyclonus:v0.4.4
27+
serviceAccount: cyclonus
28+

test/cyclonus/test-cyclonus.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail
4+
set -xv
5+
6+
kubectl delete --ignore-not-found=true clusterrolebinding cyclonus
7+
kubectl delete --ignore-not-found=true sa cyclonus -n kube-system
8+
kubectl delete --ignore-not-found=true -f ./install-cyclonus.yaml
9+
kubectl delete --ignore-not-found=true ns x y z
10+
11+
sleep 5
12+
13+
# set up cyclonus
14+
kubectl create clusterrolebinding cyclonus --clusterrole=cluster-admin --serviceaccount=kube-system:cyclonus
15+
kubectl create sa cyclonus -n kube-system
16+
kubectl create -f ./install-cyclonus.yaml
17+
18+
time kubectl wait --for=condition=ready --timeout=1m pod -n kube-system -l job-name=cyclonus
19+
20+
#!/bin/bash
21+
{ kubectl logs -f -n kube-system job.batch/cyclonus; } &
22+
{ time kubectl wait --for=condition=completed --timeout=600m pod -n kube-system -l job-name=cyclonus; } &
23+
wait -n
24+
pkill -P $$
25+
echo done
26+
27+
# grab the job logs
28+
LOG_FILE=cyclonus-test.txt
29+
kubectl logs -n kube-system job.batch/cyclonus | tee "$LOG_FILE"
30+
cat "$LOG_FILE"
31+
32+
kubectl delete --ignore-not-found=true clusterrolebinding cyclonus
33+
kubectl delete --ignore-not-found=true sa cyclonus -n kube-system
34+
kubectl delete --ignore-not-found=true -f ./install-cyclonus.yaml
35+
36+
# if 'failure' is in the logs, fail; otherwise succeed
37+
rc=0
38+
39+
cat "$LOG_FILE" | grep "failed" > /dev/null 2>&1 || rc=$?
40+
echo $rc
41+
if [ $rc -eq 0 ]; then
42+
exit 1
43+
fi

test/kind/kind.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
image: kindest/node:v1.19.1
6+
- role: worker
7+
image: kindest/node:v1.19.1
8+
- role: worker
9+
image: kindest/node:v1.19.1
10+
networking:
11+
ipFamily: ipv4
12+
podSubnet: "10.10.0.0/16"
13+
serviceSubnet: "10.11.0.0/16"

0 commit comments

Comments
 (0)