Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions .github/workflows/e2e-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ on:
pull_request:
workflow_dispatch:
inputs:
test_path:
description: 'Enter specific test path. E.g. linode_client/test_linode_client.py, models/test_account.py'
test_suite:
description: 'Enter specific test suite. E.g. domain, linode_client'
required: false
sha:
description: 'The hash value of the commit.'
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions-ecosystem/action-regex-match@v2
id: validate-tests
with:
text: ${{ inputs.test_path }}
text: ${{ inputs.test_suite }}
regex: '[^a-z0-9-:.\/_]' # Tests validation
flags: gi

Expand Down Expand Up @@ -71,6 +71,14 @@ jobs:
- name: Install Python deps
run: pip install -U setuptools wheel boto3 certifi

- name: Download kubectl and calicoctl for LKE clusters
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
chmod +x calicoctl-linux-amd64 kubectl
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
mv kubectl /usr/local/bin/kubectl

- name: Install Python SDK
run: make dev-install
env:
Expand All @@ -80,26 +88,28 @@ jobs:
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_sdk_test_report.xml"
status=0
if ! python3 -m pytest test/integration/${INTEGRATION_TEST_PATH} --disable-warnings --junitxml="${report_filename}"; then
echo "EXIT_STATUS=1" >> $GITHUB_ENV
fi
make testint TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}"
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Apply Calico Rules to LKE
if: always()
run: |
cd scripts && ./lke_calico_rules_e2e.sh
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Add additional information to XML report
- name: Upload test results
if: always()
run: |
filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
python tod_scripts/add_to_xml_test_report.py \
--branch_name "${GITHUB_REF#refs/*/}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"

- name: Upload test results
run: |
report_filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
python3 tod_scripts/test_report_upload_script.py "${report_filename}"
sync
python3 tod_scripts/test_report_upload_script.py "${filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
Expand Down Expand Up @@ -131,12 +141,3 @@ jobs:
conclusion: process.env.conclusion
});
return result;

- name: Test Execution Status Handler
run: |
if [[ "$EXIT_STATUS" != 0 ]]; then
echo "Test execution contains failure(s)"
exit $EXIT_STATUS
else
echo "Tests passed!"
fi
15 changes: 15 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Download kubectl and calicoctl for LKE clusters
run: |
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
chmod +x calicoctl-linux-amd64 kubectl
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
mv kubectl /usr/local/bin/kubectl

- name: Run Integration tests
run: |
timestamp=$(date +'%Y%m%d%H%M')
Expand All @@ -40,6 +48,13 @@ jobs:
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Apply Calico Rules to LKE
if: always()
run: |
cd scripts && ./lke_calico_rules_e2e.sh
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Upload test results
if: always()
run: |
Expand Down
78 changes: 78 additions & 0 deletions scripts/lke-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: lke-rules
spec:
preDNAT: true
applyOnForward: true
order: 100
# Remember to run calicoctl patch command for this to work
selector: ""
ingress:
# Allow ICMP
- action: Allow
protocol: ICMP
- action: Allow
protocol: ICMPv6

# Allow LKE-required ports
- action: Allow
protocol: TCP
destination:
nets:
- 192.168.128.0/17
- 10.0.0.0/8
ports:
- 10250
- 10256
- 179
- action: Allow
protocol: UDP
destination:
nets:
- 192.168.128.0/17
- 10.2.0.0/16
ports:
- 51820

# Allow NodeBalancer ingress to the Node Ports & Allow DNS
- action: Allow
protocol: TCP
source:
nets:
- 192.168.255.0/24
- 10.0.0.0/8
destination:
ports:
- 53
- 30000:32767
- action: Allow
protocol: UDP
source:
nets:
- 192.168.255.0/24
- 10.0.0.0/8
destination:
ports:
- 53
- 30000:32767

# Allow cluster internal communication
- action: Allow
destination:
nets:
- 10.0.0.0/8
- action: Allow
source:
nets:
- 10.0.0.0/8

# 127.0.0.1/32 is needed for kubectl exec and node-shell
- action: Allow
destination:
nets:
- 127.0.0.1/32

# Block everything else
- action: Deny
- action: Log
60 changes: 60 additions & 0 deletions scripts/lke_calico_rules_e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

RETRIES=3
DELAY=30

# Function to retry a command with exponential backoff
retry_command() {
local retries=$1
local wait_time=60
shift
until "$@"; do
if ((retries == 0)); then
echo "Command failed after multiple retries. Exiting."
exit 1
fi
echo "Command failed. Retrying in $wait_time seconds..."
sleep $wait_time
((retries--))
wait_time=$((wait_time * 2))
done
}

# Fetch the list of LKE cluster IDs
CLUSTER_IDS=$(curl -s -H "Authorization: Bearer $LINODE_TOKEN" \
-H "Content-Type: application/json" \
"https://api.linode.com/v4/lke/clusters" | jq -r '.data[].id')

# Check if CLUSTER_IDS is empty
if [ -z "$CLUSTER_IDS" ]; then
echo "All clusters have been cleaned and properly destroyed. No need to apply inbound or outbound rules"
exit 0
fi

for ID in $CLUSTER_IDS; do
echo "Applying Calico rules to nodes in Cluster ID: $ID"

# Download cluster configuration file with retry
for ((i=1; i<=RETRIES; i++)); do
config_response=$(curl -sH "Authorization: Bearer $LINODE_TOKEN" "https://api.linode.com/v4/lke/clusters/$ID/kubeconfig")
if [[ $config_response != *"kubeconfig is not yet available"* ]]; then
echo $config_response | jq -r '.[] | @base64d' > "/tmp/${ID}_config.yaml"
break
fi
echo "Attempt $i to download kubeconfig for cluster $ID failed. Retrying in $DELAY seconds..."
sleep $DELAY
done

if [[ $config_response == *"kubeconfig is not yet available"* ]]; then
echo "kubeconfig for cluster id:$ID not available after $RETRIES attempts, mostly likely it is an empty cluster. Skipping..."
else
# Export downloaded config file
export KUBECONFIG="/tmp/${ID}_config.yaml"

retry_command $RETRIES kubectl get nodes

retry_command $RETRIES calicoctl patch kubecontrollersconfiguration default --allow-version-mismatch --patch='{"spec": {"controllers": {"node": {"hostEndpoint": {"autoCreate": "Enabled"}}}}}'

retry_command $RETRIES calicoctl apply --allow-version-mismatch -f "$(pwd)/lke-policy.yaml"
fi
done