-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support regional GKE cluster (#18966)
- Loading branch information
Showing
4 changed files
with
82 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,10 +226,53 @@ def test_execute(self, file_mock, mock_execute_in_subprocess, mock_gcp_hook, exe | |
'clusters', | ||
'get-credentials', | ||
CLUSTER_NAME, | ||
'--project', | ||
TEST_GCP_PROJECT_ID, | ||
'--zone', | ||
PROJECT_LOCATION, | ||
] | ||
) | ||
|
||
assert self.gke_op.config_file == FILE_NAME | ||
|
||
@mock.patch.dict(os.environ, {}) | ||
@mock.patch( | ||
"airflow.hooks.base.BaseHook.get_connections", | ||
return_value=[ | ||
Connection( | ||
extra=json.dumps( | ||
{"extra__google_cloud_platform__keyfile_dict": '{"private_key": "r4nd0m_k3y"}'} | ||
) | ||
) | ||
], | ||
) | ||
@mock.patch('airflow.providers.cncf.kubernetes.operators.kubernetes_pod.KubernetesPodOperator.execute') | ||
@mock.patch('airflow.providers.google.cloud.operators.kubernetes_engine.GoogleBaseHook') | ||
@mock.patch('airflow.providers.google.cloud.operators.kubernetes_engine.execute_in_subprocess') | ||
@mock.patch('tempfile.NamedTemporaryFile') | ||
def test_execute_regional( | ||
self, file_mock, mock_execute_in_subprocess, mock_gcp_hook, exec_mock, get_con_mock | ||
): | ||
self.gke_op.regional = True | ||
type(file_mock.return_value.__enter__.return_value).name = PropertyMock( | ||
side_effect=[FILE_NAME, '/path/to/new-file'] | ||
) | ||
|
||
self.gke_op.execute(None) | ||
|
||
mock_gcp_hook.return_value.provide_authorized_gcloud.assert_called_once() | ||
|
||
mock_execute_in_subprocess.assert_called_once_with( | ||
[ | ||
'gcloud', | ||
'container', | ||
'clusters', | ||
'get-credentials', | ||
CLUSTER_NAME, | ||
'--project', | ||
TEST_GCP_PROJECT_ID, | ||
'--region', | ||
PROJECT_LOCATION, | ||
] | ||
) | ||
|
||
|
@@ -282,10 +325,10 @@ def test_execute_with_internal_ip( | |
'clusters', | ||
'get-credentials', | ||
CLUSTER_NAME, | ||
'--zone', | ||
PROJECT_LOCATION, | ||
'--project', | ||
TEST_GCP_PROJECT_ID, | ||
'--zone', | ||
PROJECT_LOCATION, | ||
'--internal-ip', | ||
] | ||
) | ||
|
@@ -325,12 +368,12 @@ def test_execute_with_impersonation_service_account( | |
'clusters', | ||
'get-credentials', | ||
CLUSTER_NAME, | ||
'--zone', | ||
PROJECT_LOCATION, | ||
'--project', | ||
TEST_GCP_PROJECT_ID, | ||
'--impersonate-service-account', | ||
'[email protected]', | ||
'--zone', | ||
PROJECT_LOCATION, | ||
] | ||
) | ||
|
||
|
@@ -369,12 +412,12 @@ def test_execute_with_impersonation_service_chain_one_element( | |
'clusters', | ||
'get-credentials', | ||
CLUSTER_NAME, | ||
'--zone', | ||
PROJECT_LOCATION, | ||
'--project', | ||
TEST_GCP_PROJECT_ID, | ||
'--impersonate-service-account', | ||
'[email protected]', | ||
'--zone', | ||
PROJECT_LOCATION, | ||
] | ||
) | ||
|
||
|