Skip to content

Commit

Permalink
Only get receptor.conf lock in k8s environment
Browse files Browse the repository at this point in the history
- Writing to receptor.conf only takes place in K8S, so only get a
lock if IS_K8S is true
  • Loading branch information
fosterseth authored and jbradberry committed Sep 23, 2022
1 parent e0c9013 commit 3018074
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions awx/main/tasks/receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,22 @@ class ReceptorConnectionType(Enum):
STREAMTLS = 2


def get_receptor_sockfile():
lock = FileLock(__RECEPTOR_CONF_LOCKFILE)
with lock:
def read_receptor_config():
# for K8S deployments, getting a lock is necessary as another process
# may be re-writing the config at this time
if settings.IS_K8S:
lock = FileLock(__RECEPTOR_CONF_LOCKFILE)
with lock:
with open(__RECEPTOR_CONF, 'r') as f:
return yaml.safe_load(f)
else:
with open(__RECEPTOR_CONF, 'r') as f:
data = yaml.safe_load(f)
return yaml.safe_load(f)


def get_receptor_sockfile():
data = read_receptor_config()

for section in data:
for entry_name, entry_data in section.items():
if entry_name == 'control-service':
Expand All @@ -68,10 +79,7 @@ def get_tls_client(use_stream_tls=None):
if not use_stream_tls:
return None

lock = FileLock(__RECEPTOR_CONF_LOCKFILE)
with lock:
with open(__RECEPTOR_CONF, 'r') as f:
data = yaml.safe_load(f)
data = read_receptor_config()
for section in data:
for entry_name, entry_data in section.items():
if entry_name == 'tls-client':
Expand Down

0 comments on commit 3018074

Please sign in to comment.