26
26
import typing
27
27
import uuid
28
28
29
- SCRIPT_VERSION = "1.2 "
29
+ SCRIPT_VERSION = "1.3 "
30
30
31
31
USAGE = r"""This script handles database transfer for Cloud Composer
32
32
(Airflow 1.10.14/15 -> Airflow 2.0.1+).
@@ -3084,7 +3084,7 @@ def _get_environment_variable_from_container_description(
3084
3084
variable_name : str ,
3085
3085
container_description : typing .Dict [typing .Any , typing .Any ],
3086
3086
) -> str :
3087
- """Reads environment variable from monitoring """
3087
+ """Reads environment variable from container description """
3088
3088
for variable in container_description ["env" ]:
3089
3089
if variable ["name" ] == variable_name :
3090
3090
logger .info (
@@ -3093,7 +3093,7 @@ def _get_environment_variable_from_container_description(
3093
3093
variable ["value" ],
3094
3094
)
3095
3095
return variable ["value" ]
3096
- raise Exception (
3096
+ raise KeyError (
3097
3097
f"Environment variable { variable } could not be found in the container."
3098
3098
)
3099
3099
@@ -3138,6 +3138,13 @@ def _read_environment_variables_from_monitoring_pod(self: typing.Any) -> None:
3138
3138
monitoring_container_description ,
3139
3139
)
3140
3140
)
3141
+ try :
3142
+ self .sql_proxy = self ._get_environment_variable_from_container_description (
3143
+ "SQL_HOST" ,
3144
+ monitoring_container_description ,
3145
+ )
3146
+ except KeyError :
3147
+ self .sql_proxy = None
3141
3148
3142
3149
def _read_fernet_key (self : typing .Any ) -> None :
3143
3150
self .fernet_key = EnvironmentUtils .read_env_variable_from_container (
@@ -3172,15 +3179,23 @@ def _check_composer_system_namespace(self: typing.Any) -> None:
3172
3179
3173
3180
def _check_cloud_sql_proxy (self : typing .Any ) -> None :
3174
3181
"""Sets sql proxy."""
3175
- namespace = (
3176
- "composer-system" if self .composer_system_namespace_exists else "default"
3177
- )
3178
- self .sql_proxy = f"airflow-sqlproxy-service.{ namespace } .svc.cluster.local"
3179
- logger .info (
3180
- "composer-system %s -> sql proxy: %s" ,
3181
- "exists" if self .composer_system_namespace_exists else "does not exist" ,
3182
- self .sql_proxy ,
3183
- )
3182
+ if self .sql_proxy is not None :
3183
+ logger .info (
3184
+ "sql proxy as provided by SQL_HOST: %s" ,
3185
+ self .sql_proxy ,
3186
+ )
3187
+ else :
3188
+ namespace = (
3189
+ "composer-system"
3190
+ if self .composer_system_namespace_exists
3191
+ else "default"
3192
+ )
3193
+ self .sql_proxy = f"airflow-sqlproxy-service.{ namespace } .svc.cluster.local"
3194
+ logger .info (
3195
+ "composer-system %s -> sql proxy: %s" ,
3196
+ "exists" if self .composer_system_namespace_exists else "does not exist" ,
3197
+ self .sql_proxy ,
3198
+ )
3184
3199
3185
3200
def _check_drs_and_select_db_storage_bucket (self : typing .Any ) -> None :
3186
3201
"""Checks if the environment is DRS-compliant."""
0 commit comments