Skip to content

Commit

Permalink
refactor, correct cluster_context value for dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AntFMoJ committed Jun 27, 2024
1 parent 314f93b commit fb7cfa0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions mojap_airflow_tools/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ def basic_kubernetes_pod_operator(
"privileged": False,
}

cluster_context = {
"dev" : "analytical-platform-compute-test",
"prod" : "analytical-platform-compute-production"
}

if run_as_user is not None:
security_context["runAsUser"] = run_as_user



if sandboxed:
user = role.replace("alpha_user_", "", 1).replace("_", "-").lower()
namespace = f"user-{user}"
Expand All @@ -173,15 +176,11 @@ def basic_kubernetes_pod_operator(
**kwargs,
)
elif service_account_name != "default":
if environment == "dev":
cluster_context = "analytical-platform-compute-development"
elif environment == "prod":
cluster_context = "analytical-platform-compute-production"
else:
if environment not in ["dev", "prod"]:
raise ValueError(
f"environment should be 'dev' or 'prod'. ({environment=})"
)

"if service_account_name argument is populated,"
f"environment should be 'dev' or 'prod'. ({environment=})"
)
kube_op = KubernetesPodOperator(
dag=dag,
namespace="airflow",
Expand All @@ -191,7 +190,7 @@ def basic_kubernetes_pod_operator(
name=task_id,
in_cluster=False,
is_delete_operator_pod=True,
cluster_context=cluster_context,
cluster_context=cluster_context[environment],
config_file="/usr/local/airflow/dags/.kube/config",
task_id=task_id,
get_logs=True,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_value_error():
@pytest.mark.parametrize(
"environment,cluster_context",
[
("dev", "analytical-platform-compute-development"),
("dev", "analytical-platform-compute-test"),
("prod", "analytical-platform-compute-production"),
],
)
Expand Down

0 comments on commit fb7cfa0

Please sign in to comment.