Skip to content

Enable plugins folder #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ jobs:
run: |
pytest -vv --gherkin-terminal-reporter \
unity-test/unit
env:
PYTHONPATH: airflow/plugins
60 changes: 1 addition & 59 deletions airflow/dags/karpenter_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime

from airflow.providers.cncf.kubernetes.operators.pod import KubernetesPodOperator
from unity_sps_utils import get_affinity

from airflow import DAG

Expand All @@ -15,65 +16,6 @@
default_params = {"placeholder": 1}


def get_affinity(
capacity_type: list[str], instance_family=list[str], instance_cpu=list[str], anti_affinity_label=str
):

affinity = {
"nodeAffinity": {
"preferredDuringSchedulingIgnoredDuringExecution": [
{
"weight": 1,
"preference": {
"matchExpressions": [
{
"key": "karpenter.sh/capacity-type",
"operator": "In",
"values": capacity_type,
}
]
},
}
],
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "karpenter.k8s.aws/instance-family",
"operator": "In",
"values": instance_family,
},
{
"key": "karpenter.k8s.aws/instance-cpu",
"operator": "In",
"values": instance_cpu,
},
]
}
]
},
},
"podAntiAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": [
{
"labelSelector": {
"matchExpressions": [
{
"key": "app",
"operator": "In",
"values": [anti_affinity_label],
},
]
},
"topologyKey": "kubernetes.io/hostname",
}
]
},
}
return affinity


dag = DAG(
"karpenter_test",
default_args=default_args,
Expand Down
2 changes: 2 additions & 0 deletions airflow/docker/custom_airflow/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ FROM apache/airflow:2.9.1-python3.11

RUN pip install cwltool==3.1.20240112164112
RUN pip install boto3==1.34.89

COPY airflow/plugins /opt/airflow/plugins
6 changes: 6 additions & 0 deletions airflow/helm/values.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ env:

# https://airflow.apache.org/docs/apache-airflow/stable/administration-and-deployment/security/api.html
extraEnv: |
- name: AIRFLOW__CORE__DAGS_FOLDER
value: "/opt/airflow/dags"
- name: AIRFLOW__CORE__PLUGINS_FOLDER
value: "/opt/airflow/plugins"
- name: AIRFLOW__CORE__LAZY_LOAD_PLUGINS
value: "False"
- name: AIRFLOW__API__AUTH_BACKENDS
value: "airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session"
- name: AIRFLOW__CORE__PARALLELISM
Expand Down
Empty file added airflow/plugins/__init__.py
Empty file.
62 changes: 62 additions & 0 deletions airflow/plugins/unity_sps_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
Module containing common utilities for the Unity Science Processing System.
"""


def get_affinity(
capacity_type: list[str], instance_family: list[str], instance_cpu: list[str], anti_affinity_label: str
):

affinity = {
"nodeAffinity": {
"preferredDuringSchedulingIgnoredDuringExecution": [
{
"weight": 1,
"preference": {
"matchExpressions": [
{
"key": "karpenter.sh/capacity-type",
"operator": "In",
"values": capacity_type,
}
]
},
}
],
"requiredDuringSchedulingIgnoredDuringExecution": {
"nodeSelectorTerms": [
{
"matchExpressions": [
{
"key": "karpenter.k8s.aws/instance-family",
"operator": "In",
"values": instance_family,
},
{
"key": "karpenter.k8s.aws/instance-cpu",
"operator": "In",
"values": instance_cpu,
},
]
}
]
},
},
"podAntiAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": [
{
"labelSelector": {
"matchExpressions": [
{
"key": "app",
"operator": "In",
"values": [anti_affinity_label],
},
]
},
"topologyKey": "kubernetes.io/hostname",
}
]
},
}
return affinity