Skip to content

Commit

Permalink
Adding podAntiAffinity (ansible#15578)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowni000 authored Oct 8, 2024
1 parent 579c2b7 commit 825a02c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion awx/main/utils/execution_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,38 @@ def get_default_execution_environment():


def get_default_pod_spec():
job_label: str = settings.AWX_CONTAINER_GROUP_DEFAULT_JOB_LABEL
ee = get_default_execution_environment()
if ee is None:
raise RuntimeError("Unable to find an execution environment.")

return {
"apiVersion": "v1",
"kind": "Pod",
"metadata": {"namespace": settings.AWX_CONTAINER_GROUP_DEFAULT_NAMESPACE},
"metadata": {"namespace": settings.AWX_CONTAINER_GROUP_DEFAULT_NAMESPACE, "labels": {job_label: ""}},
"spec": {
"serviceAccountName": "default",
"automountServiceAccountToken": False,
"affinity": {
"podAntiAffinity": {
"preferredDuringSchedulingIgnoredDuringExecution": [
{
"weight": 100,
"podAffinityTerm": {
"labelSelector": {
"matchExpressions": [
{
"key": job_label,
"operator": "Exists",
}
]
},
"topologyKey": "kubernetes.io/hostname",
},
}
]
}
},
"containers": [
{
"image": ee.image,
Expand Down
1 change: 1 addition & 0 deletions awx/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

AWX_CONTAINER_GROUP_K8S_API_TIMEOUT = 10
AWX_CONTAINER_GROUP_DEFAULT_NAMESPACE = os.getenv('MY_POD_NAMESPACE', 'default')
AWX_CONTAINER_GROUP_DEFAULT_JOB_LABEL = os.getenv('AWX_CONTAINER_GROUP_DEFAULT_JOB_LABEL', 'ansible_job')
# Timeout when waiting for pod to enter running state. If the pod is still in pending state , it will be terminated. Valid time units are "s", "m", "h". Example : "5m" , "10s".
AWX_CONTAINER_GROUP_POD_PENDING_TIMEOUT = "2h"

Expand Down

0 comments on commit 825a02c

Please sign in to comment.