Skip to content

Commit 25fe52c

Browse files
authored
test: Add job in E2E CI to attach firewall to any remaining instances (#468)
* add add-fw-to-remaining-instances job to e2e ci workflows * update needs field
1 parent 4fced5b commit 25fe52c

File tree

2 files changed

+115
-31
lines changed

2 files changed

+115
-31
lines changed

.github/workflows/e2e-test-pr.yml

+57-15
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ jobs:
7171
- name: Install Python deps
7272
run: pip install -U setuptools wheel boto3 certifi
7373

74-
- name: Download kubectl and calicoctl for LKE clusters
75-
run: |
76-
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
77-
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
78-
chmod +x calicoctl-linux-amd64 kubectl
79-
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
80-
mv kubectl /usr/local/bin/kubectl
81-
8274
- name: Install Python SDK
8375
run: make dev-install
8476
env:
@@ -92,13 +84,6 @@ jobs:
9284
env:
9385
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
9486

95-
- name: Apply Calico Rules to LKE
96-
if: always()
97-
run: |
98-
cd scripts && ./lke_calico_rules_e2e.sh
99-
env:
100-
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
101-
10287
- name: Upload test results
10388
if: always()
10489
run: |
@@ -141,3 +126,60 @@ jobs:
141126
conclusion: process.env.conclusion
142127
});
143128
return result;
129+
130+
apply-calico-rules:
131+
runs-on: ubuntu-latest
132+
needs: [integration-fork-ubuntu]
133+
if: ${{ success() || failure() }}
134+
135+
steps:
136+
- name: Checkout code
137+
uses: actions/checkout@v4
138+
with:
139+
fetch-depth: 0
140+
submodules: 'recursive'
141+
142+
- name: Download kubectl and calicoctl for LKE clusters
143+
run: |
144+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
145+
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
146+
chmod +x calicoctl-linux-amd64 kubectl
147+
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
148+
mv kubectl /usr/local/bin/kubectl
149+
150+
- name: Apply Calico Rules to LKE
151+
run: |
152+
cd e2e_scripts/cloud_security_scripts/lke_calico_rules/ && ./lke_calico_rules_e2e.sh
153+
env:
154+
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
155+
156+
add-fw-to-remaining-instances:
157+
runs-on: ubuntu-latest
158+
needs: [integration-fork-ubuntu]
159+
if: ${{ success() || failure() }}
160+
161+
steps:
162+
- name: Set up Python
163+
uses: actions/setup-python@v5
164+
with:
165+
python-version: '3.x'
166+
167+
- name: Install Linode CLI
168+
run: |
169+
pip install linode-cli
170+
171+
- name: Create Firewall and Attach to Instances
172+
run: |
173+
FIREWALL_ID=$(linode-cli firewalls create --label "e2e-fw-$(date +%s)" --rules.inbound_policy "DROP" --rules.outbound_policy "ACCEPT" --text --format=id --no-headers)
174+
echo "Created Firewall with ID: $FIREWALL_ID"
175+
176+
for instance_id in $(linode-cli linodes list --format "id" --text --no-header); do
177+
echo "Attaching firewall to instance: $instance_id"
178+
if linode-cli firewalls device-create "$FIREWALL_ID" --id "$instance_id" --type linode; then
179+
echo "Firewall attached to instance $instance_id successfully."
180+
else
181+
echo "An error occurred while attaching firewall to instance $instance_id. Skipping..."
182+
fi
183+
done
184+
env:
185+
LINODE_CLI_TOKEN: ${{ secrets.LINODE_TOKEN }}

.github/workflows/e2e-test.yml

+58-16
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ jobs:
6464
env:
6565
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6666

67-
- name: Download kubectl and calicoctl for LKE clusters
68-
run: |
69-
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
70-
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
71-
chmod +x calicoctl-linux-amd64 kubectl
72-
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
73-
mv kubectl /usr/local/bin/kubectl
74-
7567
- name: Set LINODE_TOKEN
7668
run: |
7769
echo "LINODE_TOKEN=${{ secrets[inputs.use_minimal_test_account == 'true' && 'MINIMAL_LINODE_TOKEN' || 'LINODE_TOKEN'] }}" >> $GITHUB_ENV
@@ -84,13 +76,6 @@ jobs:
8476
env:
8577
LINODE_TOKEN: ${{ env.LINODE_TOKEN }}
8678

87-
- name: Apply Calico Rules to LKE
88-
if: always()
89-
run: |
90-
cd scripts && ./lke_calico_rules_e2e.sh
91-
env:
92-
LINODE_TOKEN: ${{ env.LINODE_TOKEN }}
93-
9479
- name: Upload test results
9580
if: always()
9681
run: |
@@ -106,10 +91,67 @@ jobs:
10691
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
10792
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
10893

94+
apply-calico-rules:
95+
runs-on: ubuntu-latest
96+
needs: [integration-tests]
97+
if: ${{ success() || failure() }}
98+
99+
steps:
100+
- name: Checkout code
101+
uses: actions/checkout@v4
102+
with:
103+
fetch-depth: 0
104+
submodules: 'recursive'
105+
106+
- name: Download kubectl and calicoctl for LKE clusters
107+
run: |
108+
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
109+
curl -LO "https://github.com/projectcalico/calico/releases/download/v3.25.0/calicoctl-linux-amd64"
110+
chmod +x calicoctl-linux-amd64 kubectl
111+
mv calicoctl-linux-amd64 /usr/local/bin/calicoctl
112+
mv kubectl /usr/local/bin/kubectl
113+
114+
- name: Apply Calico Rules to LKE
115+
run: |
116+
cd e2e_scripts/cloud_security_scripts/lke_calico_rules/ && ./lke_calico_rules_e2e.sh
117+
env:
118+
LINODE_TOKEN: ${{ env.LINODE_TOKEN }}
119+
120+
add-fw-to-remaining-instances:
121+
runs-on: ubuntu-latest
122+
needs: [integration-tests]
123+
if: ${{ success() || failure() }}
124+
125+
steps:
126+
- name: Set up Python
127+
uses: actions/setup-python@v5
128+
with:
129+
python-version: '3.x'
130+
131+
- name: Install Linode CLI
132+
run: |
133+
pip install linode-cli
134+
135+
- name: Create Firewall and Attach to Instances
136+
run: |
137+
FIREWALL_ID=$(linode-cli firewalls create --label "e2e-fw-$(date +%s)" --rules.inbound_policy "DROP" --rules.outbound_policy "ACCEPT" --text --format=id --no-headers)
138+
echo "Created Firewall with ID: $FIREWALL_ID"
139+
140+
for instance_id in $(linode-cli linodes list --format "id" --text --no-header); do
141+
echo "Attaching firewall to instance: $instance_id"
142+
if linode-cli firewalls device-create "$FIREWALL_ID" --id "$instance_id" --type linode; then
143+
echo "Firewall attached to instance $instance_id successfully."
144+
else
145+
echo "An error occurred while attaching firewall to instance $instance_id. Skipping..."
146+
fi
147+
done
148+
env:
149+
LINODE_CLI_TOKEN: ${{ env.LINODE_TOKEN }}
150+
109151
notify-slack:
110152
runs-on: ubuntu-latest
111153
needs: [integration-tests]
112-
if: always() && github.repository == 'linode/linode_api4-python' # Run even if integration tests fail and only on main repository
154+
if: ${{ (success() || failure()) && github.repository == 'linode/linode_api4-python' }} # Run even if integration tests fail and only on main repository
113155

114156
steps:
115157
- name: Notify Slack

0 commit comments

Comments
 (0)