Skip to content

Commit 2fadf3c

Browse files
authored
Fix kubernetes engine system test (#18548)
- Add 'in_cluster=False' argument to 'GKEStartPodOperator' - Change order of activating service account and setting project
1 parent a458fcc commit 2fadf3c

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

airflow/providers/google/cloud/example_dags/example_kubernetes_engine.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
namespace="default",
6262
image="perl",
6363
name="test-pod",
64+
in_cluster=False,
6465
)
6566

6667
# [START howto_operator_gke_start_pod_xcom]
@@ -74,6 +75,7 @@
7475
image="alpine",
7576
cmds=["sh", "-c", 'mkdir -p /airflow/xcom/;echo \'[1,2,3,4]\' > /airflow/xcom/return.json'],
7677
name="test-pod-xcom",
78+
in_cluster=False,
7779
)
7880
# [END howto_operator_gke_start_pod_xcom]
7981

airflow/providers/google/common/hooks/base_google.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,6 @@ def provide_authorized_gcloud(self):
493493
gcloud_config_tmp = exit_stack.enter_context(tempfile.TemporaryDirectory())
494494
exit_stack.enter_context(patch_environ({CLOUD_SDK_CONFIG_DIR: gcloud_config_tmp}))
495495

496-
if project_id:
497-
# Don't display stdout/stderr for security reason
498-
check_output(["gcloud", "config", "set", "core/project", project_id])
499496
if CREDENTIALS in os.environ:
500497
# This solves most cases when we are logged in using the service key in Airflow.
501498
# Don't display stdout/stderr for security reason
@@ -507,6 +504,9 @@ def provide_authorized_gcloud(self):
507504
f"--key-file={os.environ[CREDENTIALS]}",
508505
]
509506
)
507+
if project_id:
508+
# Don't display stdout/stderr for security reason
509+
check_output(["gcloud", "config", "set", "core/project", project_id])
510510
elif os.path.exists(credentials_path):
511511
# If we are logged in by `gcloud auth application-default` then we need to log in manually.
512512
# This will make the `gcloud auth application-default` and `gcloud auth` credentials equals.

0 commit comments

Comments
 (0)