Skip to content

Commit

Permalink
fix iterate dns records for aws api changes --skip-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Jan 28, 2024
1 parent 2e0785e commit 3f7f380
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ jobs:
if [ "$(uci github actions get-branch-name)" == "main" ]; then
uci docker tag-push \
--source-tag-name cwm_worker_operator \
--push-tag-name "ghcr.io/cloudwebmanage/cwm-worker-operator/cwm_worker_operator:latest" &&\
sed -i "s/appVersion: latest/appVersion: ${GITHUB_SHA}/g" helm/Chart.yaml &&\
bin/helm_publish.sh
--push-tag-name "ghcr.io/cloudwebmanage/cwm-worker-operator/cwm_worker_operator:latest"
fi
- uses: 8398a7/action-slack@v3
Expand Down
10 changes: 7 additions & 3 deletions cwm_worker_operator/deployments_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,13 @@ def iterate_dns_healthchecks(self):

def iterate_dns_records(self):
client = boto3.client('route53')
next_record_identifier = None
next_record_identifier, next_record_name, next_record_type = None, None, None
while True:
res = client.list_resource_record_sets(
HostedZoneId=config.AWS_ROUTE53_HOSTEDZONE_ID,
**({'StartRecordIdentifier': next_record_identifier} if next_record_identifier is not None else {})
**({'StartRecordIdentifier': next_record_identifier} if next_record_identifier is not None else {}),
**({'StartRecordName': next_record_name} if next_record_name is not None else {}),
**({'StartRecordType': next_record_type} if next_record_type is not None else {}),
)
for record in res.get('ResourceRecordSets', []):
if record['Type'] == 'A' and record['Name'] == '{}.{}.'.format(config.DNS_RECORDS_PREFIX, config.AWS_ROUTE53_HOSTEDZONE_DOMAIN):
Expand All @@ -325,7 +327,9 @@ def iterate_dns_records(self):
'ip': record_ip
}
if res['IsTruncated']:
next_record_identifier = res['NextRecordIdentifier']
next_record_identifier = res.get('NextRecordIdentifier')
next_record_name = res.get('NextRecordName')
next_record_type = res.get('NextRecordType')
else:
break

Expand Down
9 changes: 9 additions & 0 deletions cwm_worker_operator/nodes_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
which are not currently listed as worker nodes - so nodes which are removed
will instantly stop serving.
"""
from cwm_worker_operator import logs
from cwm_worker_operator import config
from cwm_worker_operator.daemon import Daemon

Expand All @@ -32,23 +33,31 @@ def set_node_healthy_keys(domains_config, deployments_manager):


def update_dns_records(deployments_manager, healthy_node_name_ips):
logs.debug('update_dns_records', healthy_node_name_ips=healthy_node_name_ips, debug_verbosity=10)
dns_healthchecks = {}
dns_records = {}
# collect node names of existing dns healthchecks / records
# delete records which need updating for recreation
update_required_healthcheck_node_names = set()
update_required_records_node_names = set()
for dns_healthcheck in deployments_manager.iterate_dns_healthchecks():
logs.debug('dns_healthcheck', dns_healthcheck=dns_healthcheck, debug_verbosity=10)
dns_healthchecks[dns_healthcheck['node_name']] = {'id': dns_healthcheck['id'], 'ip': dns_healthcheck['ip']}
if dns_healthcheck['node_name'] in healthy_node_name_ips and dns_healthcheck['ip'] != healthy_node_name_ips[
dns_healthcheck['node_name']]:
deployments_manager.delete_dns_healthcheck(dns_healthcheck['id'])
update_required_healthcheck_node_names.add(dns_healthcheck['node_name'])
for dns_record in deployments_manager.iterate_dns_records():
logs.debug('dns_record', dns_record=dns_record, debug_verbosity=10)
dns_records[dns_record['node_name']] = {'id': dns_record['id'], 'ip': dns_record['ip']}
if dns_record['node_name'] in update_required_healthcheck_node_names or (dns_record['node_name'] in healthy_node_name_ips and dns_record['ip'] != healthy_node_name_ips[dns_record['node_name']]):
deployments_manager.delete_dns_record(dns_record['id'])
update_required_records_node_names.add(dns_record['node_name'])
logs.debug(
'updates', debug_verbosity=10,
update_required_records_node_names=update_required_records_node_names,
update_required_healthcheck_node_names=update_required_healthcheck_node_names,
)
# set dns healthcheck and record for nodes which are in list of healthy nodes but have a missing healthcheck or record
for node_name, node_ip in healthy_node_name_ips.items():
if node_name not in dns_healthchecks or node_name in update_required_healthcheck_node_names:
Expand Down

0 comments on commit 3f7f380

Please sign in to comment.