-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix ACL update bug and add e2e test for it (#306)
- Loading branch information
Showing
5 changed files
with
305 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: lb-fw-update-acl | ||
spec: | ||
namespace: "lb-fw-update-acl" | ||
steps: | ||
- name: Check if CCM is deployed | ||
try: | ||
- assert: | ||
file: ../assert-ccm-resources.yaml | ||
- name: Create pods and services | ||
try: | ||
- apply: | ||
file: create-pods-services.yaml | ||
catch: | ||
- describe: | ||
apiVersion: v1 | ||
kind: Pod | ||
- describe: | ||
apiVersion: v1 | ||
kind: Service | ||
- name: Check that loadbalancer ip is assigned | ||
try: | ||
- assert: | ||
resource: | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: svc-test | ||
status: | ||
(loadBalancer.ingress[0].ip != null): true | ||
- name: Fetch Nodebalancer ID, make sure it has firewall attached | ||
try: | ||
- script: | ||
content: | | ||
set -e | ||
for i in {1..10}; do | ||
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) | ||
fw=$(curl -s --request GET \ | ||
-H "Authorization: Bearer $LINODE_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-H "accept: application/json" \ | ||
"https://api.linode.com/v4/nodebalancers/${nbid}/firewalls" || true) | ||
fwCount=$(echo $fw | jq '.data | length') | ||
ips=$(echo $fw | jq '.data[].rules.inbound[].addresses.ipv4[]') | ||
if [[ $fwCount -eq 1 && -n $ips && $ips == *"7.7.7.7/32"* ]]; then | ||
echo "firewall attached and rule has specified ip" | ||
break | ||
fi | ||
sleep 10 | ||
done | ||
check: | ||
($error == null): true | ||
(contains($stdout, 'firewall attached and rule has specified ip')): true | ||
- name: Update service with new ACL | ||
try: | ||
- apply: | ||
file: update-service.yaml | ||
catch: | ||
- describe: | ||
apiVersion: v1 | ||
kind: Service | ||
- name: Fetch firewall ID and check rules are updated | ||
try: | ||
- script: | ||
content: | | ||
set -e | ||
for i in {1..10}; do | ||
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) | ||
fw=$(curl -s --request GET \ | ||
-H "Authorization: Bearer $LINODE_TOKEN" \ | ||
-H "Content-Type: application/json" \ | ||
-H "accept: application/json" \ | ||
"https://api.linode.com/v4/nodebalancers/${nbid}/firewalls" || true) | ||
fwCount=$(echo $fw | jq -r '.data | length') | ||
ips=$(echo $fw | jq -r '.data[].rules.inbound[].addresses.ipv4[]') | ||
if [[ $fwCount -eq 1 && -n $ips && ! $ips == *"7.7.7.7/32"* ]]; then | ||
echo "firewall attached and rule updated" | ||
break | ||
fi | ||
sleep 10 | ||
done | ||
check: | ||
($error == null): true | ||
(contains($stdout, 'firewall attached and rule updated')): true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: lb-fw-update-acl | ||
name: test | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: lb-fw-update-acl | ||
template: | ||
metadata: | ||
labels: | ||
app: lb-fw-update-acl | ||
spec: | ||
affinity: | ||
podAntiAffinity: | ||
preferredDuringSchedulingIgnoredDuringExecution: | ||
- podAffinityTerm: | ||
labelSelector: | ||
matchExpressions: | ||
- key: app | ||
operator: In | ||
values: | ||
- simple-lb | ||
topologyKey: kubernetes.io/hostname | ||
weight: 100 | ||
containers: | ||
- image: appscode/test-server:2.3 | ||
name: test | ||
ports: | ||
- name: http-1 | ||
containerPort: 8080 | ||
protocol: TCP | ||
env: | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: metadata.name | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: svc-test | ||
annotations: | ||
service.beta.kubernetes.io/linode-loadbalancer-firewall-acl: | | ||
{ | ||
"denyList": { | ||
"ipv4": ["8.8.8.8/32", | ||
"9.9.9.9/32", | ||
"7.7.7.7/32"] | ||
} | ||
} | ||
labels: | ||
app: lb-fw-update-acl | ||
spec: | ||
type: LoadBalancer | ||
selector: | ||
app: lb-fw-update-acl | ||
ports: | ||
- name: http-1 | ||
protocol: TCP | ||
port: 80 | ||
targetPort: 8080 | ||
sessionAffinity: None |
Oops, something went wrong.