Skip to content

Commit

Permalink
Add error check for config_file parameter in GKEStartPodOperator (#17700
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leahecole authored Aug 19, 2021
1 parent bee48f3 commit b68d193
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions airflow/providers/google/cloud/operators/kubernetes_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ def __init__(
"Credentials (ADC) strategy for authorization, create an empty connection "
"called `google_cloud_default`.",
)
# There is no need to manage the kube_config file, as it will be generated automatically.
# All Kubernetes parameters (except config_file) are also valid for the GKEStartPodOperator.
if self.config_file:
raise AirflowException("config_file is not an allowed parameter for the GKEStartPodOperator.")

def execute(self, context) -> Optional[str]:
hook = GoogleBaseHook(gcp_conn_id=self.gcp_conn_id)
Expand Down
13 changes: 13 additions & 0 deletions tests/providers/google/cloud/operators/test_kubernetes_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ def test_execute(self, file_mock, mock_execute_in_subprocess, mock_gcp_hook, exe

assert self.gke_op.config_file == FILE_NAME

def test_config_file_throws_error(self):
with pytest.raises(AirflowException):
GKEStartPodOperator(
project_id=TEST_GCP_PROJECT_ID,
location=PROJECT_LOCATION,
cluster_name=CLUSTER_NAME,
task_id=PROJECT_TASK_ID,
name=TASK_NAME,
namespace=NAMESPACE,
image=IMAGE,
config_file="/path/to/alternative/kubeconfig",
)

@mock.patch.dict(os.environ, {})
@mock.patch(
"airflow.hooks.base.BaseHook.get_connections",
Expand Down

0 comments on commit b68d193

Please sign in to comment.