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

[test] Add Cilium BGP LB e2e test #290

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ jobs:
- name: Run E2E Tests
run: devbox run e2e-test

- name: Run Cilium BGP e2e test
run: devbox run e2e-test-bgp

- name: Cleanup Resources
if: always()
run: devbox run cleanup-cluster
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,43 @@ e2e-test:
LINODE_TOKEN=$(LINODE_TOKEN) \
chainsaw test e2e/test --parallel 2

.PHONY: e2e-test-bgp
e2e-test-bgp:
KUBECONFIG=$(KUBECONFIG_PATH) kubectl -n kube-system patch daemonset ccm-linode --patch '\
spec:\
template:\
spec:\
containers:\
- name: ccm-linode\
args:\
- --leader-elect-resource-lock=leases\
- --v=3\
- --secure-port=10253\
- --webhook-secure-port=0\
- --enable-route-controller=true\
- --vpc-name=capl-cluster\
- --configure-cloud-routes=true\
- --cluster-cidr=10.0.0.0/8\
- --load-balancer-type=cilium-bgp\
- --bgp-node-selector=cilium-bgp-peering=true\
- --ip-holder-suffix=e2e-test
komer3 marked this conversation as resolved.
Show resolved Hide resolved
KUBECONFIG=$(KUBECONFIG_PATH) kubectl patch clusterrole ccm-linode-clusterrole --type='json' \
-p='[{\
"op": "add",\
"path": "/rules/-",\
"value": {\
"apiGroups": ["cilium.io"],\
"resources": ["ciliumloadbalancerippools", "ciliumbgppeeringpolicies"],\
"verbs": ["get", "list", "watch", "create", "update", "patch", "delete"]\
}\
}]'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we make the bgp stuff configurable in https://github.com/linode/linode-cloud-controller-manager/blob/main/deploy/generate-manifest.sh then we don't have to do this patching. That's probably worth adding since right now the raw manifest needs to be manually edited versus setting the options in the helm chart.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so we would regen the manifest with bgp enabled and apply the patches?

CLUSTER_NAME=$(CLUSTER_NAME) \
MGMT_KUBECONFIG=$(MGMT_KUBECONFIG_PATH) \
KUBECONFIG=$(KUBECONFIG_PATH) \
REGION=$(LINODE_REGION) \
LINODE_TOKEN=$(LINODE_TOKEN) \
chainsaw test e2e/test/lb-cilium-bgp

#####################################################################
# OS / ARCH
#####################################################################
Expand Down
1 change: 1 addition & 0 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"mgmt-and-capl-cluster": "make mgmt-and-capl-cluster",
"e2e-test": "make e2e-test",
"e2e-test-bgp": "make e2e-test-bgp",
"cleanup-cluster": "make cleanup-cluster"
}
},
Expand Down
113 changes: 113 additions & 0 deletions e2e/lb-cilium-bgp/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# 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: cilium-bgp-test
spec:
namespace: "cilium-bgp-test"
steps:
- name: Check if CCM is deployed
try:
- assert:
file: ../test/assert-ccm-resources.yaml
- name: Create a pod and service with load balancer type cilium-bgp
try:
- apply:
file: create-pod-service.yaml
catch:
- describe:
apiVersion: v1
kind: Pod
- describe:
apiVersion: v1
kind: Service
- name: Verify CiliumLoadBalancerIPPool creation
try:
- assert:
resource:
apiVersion: cilium.io/v2alpha1
kind: CiliumLoadBalancerIPPool
metadata:
name: cilium-bgp-test-test-bgp-svc-pool
spec:
disabled: false
- name: Verify CiliumBGPPeeringPolicy
try:
- assert:
resource:
apiVersion: cilium.io/v2alpha1
kind: CiliumBGPPeeringPolicy
metadata:
name: linode-ccm-bgp-peering
spec:
nodeSelector:
matchLabels:
cilium-bgp-peering: "true"
- name: Check LoadBalancer IP assignment
try:
- assert:
resource:
apiVersion: v1
kind: Service
metadata:
name: test-bgp-svc
status:
conditions:
- status: "True"
type: cilium.io/IPAMRequestSatisfied
- name: Verify IP sharing on labeled nodes
try:
- script:
content: |
set -e

# Get the LoadBalancer IP
LB_IP=$(kubectl get svc test-bgp-svc -n cilium-bgp-test -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

# Get nodes with BGP label
BGP_NODES=$(kubectl get nodes -l cilium-bgp-peering=true -o name)

if [ -z "$BGP_NODES" ]; then
echo "No nodes found with label cilium-bgp-peering=true"
exit 1
fi

# Check if IP is shared on each BGP node
for node in $BGP_NODES; do
NODE_ID=$(kubectl get $node -o jsonpath='{.spec.providerID}' | sed 's|linode://||')
echo "Node ID: $NODE_ID"

SHARED_IPS=$(curl -H "Authorization: Bearer $LINODE_TOKEN" \
"https://api.linode.com/v4/linode/instances/$NODE_ID/ips" | \
jq -r '.ipv4.shared[].address')
echo "shared IPs: $SHARED_IPS"

if ! echo "$SHARED_IPS" | grep -q "$LB_IP"; then
echo "LoadBalancer IP $LB_IP not found in shared IPs of node $node"
exit 1
fi

# Check if the nanode has the shared IP
NANODE_ID=$(curl -H "Authorization: Bearer $LINODE_TOKEN" \
"https://api.linode.com/v4/linode/instances" | \
jq -r '.data[] | select(.label | endswith("e2e-test")) | .id')

NANODE_IPS=$(curl -H "Authorization: Bearer $LINODE_TOKEN" \
"https://api.linode.com/v4/linode/instances/$NANODE_ID/ips" | \
jq -r '.ipv4.public[].address')

if ! echo "$NANODE_IPS" | grep -q "$LB_IP"; then
echo "LoadBalancer IP not found in nanode (IP placeholder) IPs"
exit 1
fi

# Delete the nanode
curl -X DELETE -H "Authorization: Bearer $LINODE_TOKEN" \
"https://api.linode.com/v4/linode/instances/$NANODE_ID"

done
check:
($error == null): true
(contains($stdout, 'LoadBalancer IP not found in shared IPs of node')): false
(contains($stdout, 'LoadBalancer IP not found in nanode IPs')): false

24 changes: 24 additions & 0 deletions e2e/lb-cilium-bgp/create-pod-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v1
kind: Pod
metadata:
name: test-pod-1
labels:
app: test-bgp
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: test-bgp-svc
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: test-bgp
Loading