|
25 | 25 | build_ec2_type_label,
|
26 | 26 | get_affinity,
|
27 | 27 | )
|
| 28 | +from kubernetes import client as k8s_client_lib |
| 29 | +from kubernetes import config as k8s_config_lib |
| 30 | +import base64 |
| 31 | +from airflow.providers.cncf.kubernetes.secret import Secret as AirflowK8sSecret |
28 | 32 |
|
29 | 33 | from airflow import DAG
|
30 | 34 |
|
|
39 | 43 | DOCKERHUB_TOKEN = "/unity/ads/app_gen/development/dockerhub_api_key"
|
40 | 44 | DOCKSTORE_TOKEN = "/unity/ads/app_gen/development/dockstore_token"
|
41 | 45 |
|
| 46 | +K8S_SECRET_NAME = "sps-app-credentials" # Must match metadata.name in kubernetes_secret |
| 47 | + |
42 | 48 | # HOST_SECRET_DIR = "/mnt/token-volume"
|
43 | 49 | # os.makedirs(HOST_SECRET_DIR, exist_ok=True)
|
44 | 50 |
|
|
110 | 116 | k8s.V1EnvVar(name="GITHUB_REPO", value="{{ params.repository }}"),
|
111 | 117 | ]
|
112 | 118 |
|
| 119 | +secret_env_vars = [ |
| 120 | + AirflowK8sSecret( |
| 121 | + deploy_type='env', # Expose as environment variable |
| 122 | + deploy_target='DOCKERHUB_USERNAME_IN_POD', # Name of the ENV VAR inside your pod |
| 123 | + secret=K8S_SECRET_NAME, # Name of the K8s Secret |
| 124 | + key='DOCKERHUB_USERNAME' # Key in the K8s Secret's data field |
| 125 | + ), |
| 126 | + AirflowK8sSecret( |
| 127 | + deploy_type='env', |
| 128 | + deploy_target='DOCKERHUB_TOKEN_IN_POD', |
| 129 | + secret=K8S_SECRET_NAME, |
| 130 | + key='DOCKERHUB_TOKEN' |
| 131 | + ), |
| 132 | + AirflowK8sSecret( |
| 133 | + deploy_type='env', |
| 134 | + deploy_target='DOCKSTORE_TOKEN_IN_POD', |
| 135 | + secret=K8S_SECRET_NAME, |
| 136 | + key='DOCKSTORE_TOKEN' |
| 137 | + ) |
| 138 | +] |
| 139 | + |
113 | 140 | def setup(ti=None, **context):
|
114 | 141 | """
|
115 | 142 | Task that selects the proper Karpenter Node Pool depending on the user requested resources.
|
@@ -195,6 +222,7 @@ def setup(ti=None, **context):
|
195 | 222 | # )
|
196 | 223 | # )
|
197 | 224 | # ],
|
| 225 | + secrets=[secret_env_vars], |
198 | 226 | volume_mounts=[
|
199 | 227 | k8s.V1VolumeMount(name="token-volume", mount_path="/")
|
200 | 228 | ],
|
|
0 commit comments