Skip to content

Commit af37325

Browse files
Ani1357j-zimnowodaCasLubbers
authored
fix: updated gh-actions, added no-apl (#1772)
Co-authored-by: jeho <[email protected]> Co-authored-by: CasLubbers <[email protected]>
1 parent e85ff2c commit af37325

File tree

3 files changed

+67
-43
lines changed

3 files changed

+67
-43
lines changed

.github/workflows/integration-on-schedule-minimal-no-admin-pass.yml

-14
This file was deleted.

.github/workflows/integration.yml

+35-19
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ on:
4343
options:
4444
- minimal
4545
- minimal-with-team
46-
- monitoring-with-team
4746
- full
4847
- upgrade
48+
- no-apl
4949
domain_zone:
5050
type: choice
5151
description: 'Select Domain Zone'
5252
options:
5353
- Zone-1
5454
- Zone-2
55+
- Random
56+
- DNS-Integration
5557
kms:
5658
type: choice
5759
description: Should APL encrypt secrets in values repo (DNS or KMS is turned on)?
@@ -117,11 +119,14 @@ jobs:
117119
case "${{ inputs.domain_zone }}" in
118120
"Zone-1") LINODE_CLUSTER_NAME=${{ github.actor }}-1 ;;
119121
"Zone-2") LINODE_CLUSTER_NAME=${{ github.actor }}-2 ;;
122+
"Random") LINODE_CLUSTER_NAME=${{ github.actor }}-$RANDOM ;;
123+
"DNS-Integration") LINODE_CLUSTER_NAME=apl-test-${{ inputs.install_profile }} ;;
120124
esac
121-
125+
[[ ${{ inputs.install_profile }} == 'no-apl' ]] && LINODE_CLUSTER_NAME=$LINODE_CLUSTER_NAME-no-apl
122126
if [[ $(linode-cli lke clusters-list --json | jq --arg name "$LINODE_CLUSTER_NAME" '[.[] | select(.label == $name)] | length > 0') == "true" ]]; then
123-
echo "An LKE cluster for Zone-1 named \"$LINODE_CLUSTER_NAME\" already exists."
124-
echo "Please delete the cluster before recreating it. Exiting workflow..."
127+
echo "An LKE cluster with the same name ($LINODE_CLUSTER_NAME) already exists."
128+
echo "Visit https://cloud.linode.com/kubernetes/clusters to delete your cluster"
129+
echo "Exiting workflow..."
125130
exit 1
126131
fi
127132
- id: k8s-versions
@@ -155,30 +160,33 @@ jobs:
155160
case "${{ inputs.domain_zone }}" in
156161
"Zone-1") LINODE_CLUSTER_NAME=${{ github.actor }}-1 ;;
157162
"Zone-2") LINODE_CLUSTER_NAME=${{ github.actor }}-2 ;;
158-
"DNS-Integration") LINODE_CLUSTER_NAME=nightly-apl-test-$RANDOM ;;
163+
"Random") LINODE_CLUSTER_NAME=${{ github.actor }}-$RANDOM ;;
164+
"DNS-Integration") LINODE_CLUSTER_NAME=apl-test-${{ inputs.install_profile }} ;;
159165
esac
166+
[[ ${{ inputs.install_profile }} == 'no-apl' ]] && LINODE_CLUSTER_NAME=$LINODE_CLUSTER_NAME-no-apl
160167
echo LINODE_CLUSTER_NAME=$LINODE_CLUSTER_NAME >> $GITHUB_ENV
161168
- name: Determine exact k8s version
162169
run: |
163170
echo LINODE_K8S_VERSION=$(linode-cli lke versions-list --json | jq -ce --arg version "$(echo ${{ matrix.kubernetes_versions }} | sed -E 's/^([0-9]+\.[0-9])$/\10/')" '.[] | select(.id | tostring | startswith($version)) | .id') >> $GITHUB_ENV
164-
- name: Creating domain for scheduled integration test
171+
- name: Determine domain name to use for scheduled integration test
165172
env:
166173
EDGEDNS_ZONE: ${{ secrets.EDGEDNS_ZONE }}
167-
if: ${{ inputs.domain_zone == 'DNS-Integration' }}
174+
if: ${{ inputs.domain_zone == 'DNS-Integration' && inputs.install_profile != 'no-apl'}}
168175
run: |
169-
# Generating a random 5 char string
170176
RAND=$(openssl rand -hex 4)
171177
DOMAIN="integration-${RAND}.${EDGEDNS_ZONE}"
172178
echo "::add-mask::$DOMAIN"
173179
echo DOMAIN=$DOMAIN >> $GITHUB_ENV
174-
175-
- name: Determine domain name to use
176-
if: ${{ inputs.domain_zone != 'DNS-Integration' }}
180+
- name: Determine domain name
181+
if: ${{ inputs.domain_zone != 'DNS-Integration' && inputs.install_profile != 'no-apl' }}
182+
env:
183+
EDGEDNS_ZONE: ${{ secrets.EDGEDNS_ZONE }}
177184
run: |
178185
# Mapping of domain_zone to domain names
179186
case "${{ inputs.domain_zone }}" in
180-
"Zone-1") DOMAIN=$(jq '."${{ github.actor }}"[0]' <<< ${{ env.DEV_DOMAINS }}) ;;
181-
"Zone-2") DOMAIN=$(jq '."${{ github.actor }}"[1]' <<< ${{ env.DEV_DOMAINS }}) ;;
187+
"Zone-1") DOMAIN=$(jq -r '."${{ github.actor }}"[0]' <<< ${{ env.DEV_DOMAINS }}) ;;
188+
"Zone-2") DOMAIN=$(jq -r '."${{ github.actor }}"[1]' <<< ${{ env.DEV_DOMAINS }}) ;;
189+
"Random") DOMAIN="$(openssl rand -hex 4)$(date +"%d%m%y").${EDGEDNS_ZONE}" ;;
182190
esac
183191
184192
echo "::add-mask::$DOMAIN"
@@ -217,6 +225,7 @@ jobs:
217225
sleep 30
218226
done
219227
- name: Save kubectl config with auth token and Get kubectl environment and create docker secret
228+
if: ${{ inputs.install_profile != 'no-apl' }}
220229
run: |
221230
# Get the kubeconfig from linode-cli
222231
kubeconfig=$(linode-cli lke kubeconfig-view ${{ env.LINODE_CLUSTER_ID }} --text | sed 1d | base64 --decode)
@@ -235,14 +244,17 @@ jobs:
235244
echo "Kubectl context set to linode"
236245
echo LINODE_CLUSTER_CONTEXT=`kubectl config current-context` >> $GITHUB_ENV
237246
- name: Create image pull secret on test cluster
247+
if: ${{ inputs.install_profile != 'no-apl' }}
238248
run: |
239249
kubectl create secret docker-registry reg-otomi-github \
240250
--docker-server=${{ env.CACHE_REGISTRY }} \
241251
--docker-username=${{ env.BOT_USERNAME }} \
242252
--docker-password='${{ secrets.BOT_PULL_TOKEN }}'
243253
- name: Checkout
254+
if: ${{ inputs.install_profile != 'no-apl' }}
244255
uses: actions/checkout@v4
245256
- name: Prepare APL chart
257+
if: ${{ inputs.install_profile != 'no-apl' }}
246258
run: |
247259
ref=${{ github.event.pull_request.head.ref || github.ref }}
248260
tag=${ref##*/}
@@ -261,6 +273,7 @@ jobs:
261273
- reg-otomi-github
262274
EOF
263275
- name: APL install
276+
if: ${{ inputs.install_profile != 'no-apl' }}
264277
env:
265278
LETSENCRYPT_STAGING: ${{ secrets.LETSENCRYPT_STAGING }}
266279
LETSENCRYPT_PRODUCTION: ${{ secrets.LETSENCRYPT_PRODUCTION }}
@@ -325,10 +338,13 @@ jobs:
325338
done
326339
327340
pip3 install edgegrid-python requests
328-
python3 bin/edgedns_A_record.py create $DOMAIN $PUB_IP
341+
python3 bin/edgedns_A_record.py create "*.${DOMAIN}" $PUB_IP || \
342+
(echo "Will try to recreate it" && \
343+
python3 bin/edgedns_A_record.py delete "*.${DOMAIN}" && \
344+
python3 bin/edgedns_A_record.py create "*.${DOMAIN}" $PUB_IP)
329345
330-
wait $HELM_PID
331346
347+
wait $HELM_PID
332348
- name: Gather k8s events on failure
333349
if: failure()
334350
run: |
@@ -340,25 +356,25 @@ jobs:
340356
- name: Gather APL logs on failure
341357
if: failure()
342358
run: |
343-
kubectl logs jobs/otomi --tail 150
359+
kubectl logs jobs/otomi-apl --tail 150
344360
- name: Gather otomi-e2e logs on failure
345361
if: failure()
346362
run: |
347363
kubectl logs -n maintenance -l app.kubernetes.io/instance=job-e2e --tail 15000
348364
- name: Remove the test cluster
349-
if: ${{ inputs.domain_zone == 'DNS-Integration' }}
365+
if: ${{ always() && inputs.domain_zone == 'DNS-Integration' }}
350366
run: |
351367
linode-cli lke cluster-delete ${{ env.LINODE_CLUSTER_ID }}
352368
- name: Delete Domain
353-
if: ${{ inputs.domain_zone == 'DNS-Integration' }}
369+
if: ${{ always() && inputs.domain_zone == 'DNS-Integration' }}
354370
env:
355371
EDGEDNS_ACCESS_TOKEN: ${{ secrets.EDGEDNS_ACCESS_TOKEN }}
356372
EDGEDNS_CLIENT_TOKEN: ${{ secrets.EDGEDNS_CLIENT_TOKEN }}
357373
EDGEDNS_CLIENT_SECRET: ${{ secrets.EDGEDNS_CLIENT_SECRET }}
358374
EDGEDNS_ZONE: ${{ secrets.EDGEDNS_ZONE }}
359375
EDGEDNS_HOST: ${{ secrets.EDGEDNS_HOST }}
360376
run: |
361-
python3 bin/edgedns_A_record.py delete $DOMAIN
377+
python3 bin/edgedns_A_record.py delete "*.${DOMAIN}"
362378
- name: Slack Notification
363379
if: always()
364380
uses: rtCamp/action-slack-notify@v2

bin/edgedns_A_record.py

+32-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from akamai.edgegrid import EdgeGridAuth
44
from requests import Session, HTTPError
5+
import json
56

67
EDGEDNS_ZONE = os.environ.get('EDGEDNS_ZONE')
78
EDGEDNS_HOST = os.environ.get('EDGEDNS_HOST')
@@ -24,13 +25,10 @@ def create_session():
2425
})
2526
return session
2627

27-
# Function to construct the DNS API URL
28-
def construct_dns_url(domain, record_type="A"):
29-
return f"https://{EDGEDNS_HOST}/config-dns/v2/zones/{EDGEDNS_ZONE}/names/{domain}/types/{record_type}"
3028

3129
# Function to create DNS record
3230
def create_dns_record(session, domain, ip):
33-
url = construct_dns_url(domain)
31+
url = f"https://{EDGEDNS_HOST}/config-dns/v2/zones/{EDGEDNS_ZONE}/names/{domain}/types/A"
3432
data = {
3533
"name": domain,
3634
"rdata": [ip],
@@ -43,26 +41,48 @@ def create_dns_record(session, domain, ip):
4341
response.raise_for_status()
4442
print(f"DNS record created successfully !")
4543
except HTTPError as e:
46-
print(f"Failed to create DNS record!")
44+
response_json = json.loads(e.response.text)
45+
print(f"Failed to create DNS record: {response_json['title']} ")
46+
sys.exit(1)
4747

4848
# Function to delete DNS record
4949
def delete_dns_record(session, domain):
50-
url = construct_dns_url(domain)
50+
url = f"https://{EDGEDNS_HOST}/config-dns/v2/zones/{EDGEDNS_ZONE}/names/{domain}/types/A"
5151

5252
try:
5353
response = session.delete(url)
5454
response.raise_for_status()
5555
print(f"DNS record deleted successfully!")
5656
except HTTPError as e:
57-
print(f"Failed to delete DNS record!")
57+
response_json = json.loads(e.response.text)
58+
print(f"Failed to delete DNS record: {response_json['title']}")
59+
sys.exit(1)
60+
61+
# Function to list A records
62+
def list_a_records(session):
63+
url = f"https://{EDGEDNS_HOST}/config-dns/v2/zones/{EDGEDNS_ZONE}/recordsets?types=A&showAll=true"
64+
65+
try:
66+
response = session.get(url)
67+
response.raise_for_status()
68+
records = response.json().get("recordsets", [])
69+
if not records:
70+
print("No A records found.")
71+
else:
72+
for record in records:
73+
print(record['name'])
74+
except HTTPError as e:
75+
response_json = json.loads(e.response.text)
76+
print(f"Failed to list DNS records: {response_json['title']}")
77+
sys.exit(1)
5878

5979
def main():
60-
if len(sys.argv) < 3 or (sys.argv[1].lower() == "create" and len(sys.argv) != 4):
80+
if len(sys.argv) < 2 or (sys.argv[1].lower() == "create" and len(sys.argv) != 4):
6181
print("Usage: python edgedns_A_record.py <action> <domain> [<ip>]")
6282
sys.exit(1)
6383

6484
action = sys.argv[1].lower()
65-
domain = sys.argv[2].lower()
85+
domain = sys.argv[2].lower() if len(sys.argv) > 2 else None
6686
ip = sys.argv[3] if action == "create" else None
6787

6888
session = create_session()
@@ -74,8 +94,10 @@ def main():
7494
create_dns_record(session, domain, ip)
7595
elif action == "delete":
7696
delete_dns_record(session, domain)
97+
elif action == "list":
98+
list_a_records(session)
7799
else:
78-
print("Invalid action. Use 'create' or 'delete'.")
100+
print("Invalid action. Use 'create', 'delete', or 'list'.")
79101
sys.exit(1)
80102

81103
if __name__ == "__main__":

0 commit comments

Comments
 (0)