Skip to content

Commit

Permalink
Do not ignore the internal_ip_only if set to false in Dataproc cluste…
Browse files Browse the repository at this point in the history
…r config (#37014)
  • Loading branch information
ahzaz committed Jan 31, 2024
1 parent 9a4164d commit 4150314
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/google/cloud/operators/dataproc.py
Expand Up @@ -361,10 +361,10 @@ def _build_gce_cluster_config(self, cluster_data):
if self.subnetwork_uri:
cluster_data[config]["subnetwork_uri"] = self.subnetwork_uri

if self.internal_ip_only:
if not self.subnetwork_uri:
if self.internal_ip_only is not None:
if not self.subnetwork_uri and self.internal_ip_only:
raise AirflowException("Set internal_ip_only to true only when you pass a subnetwork_uri.")
cluster_data[config]["internal_ip_only"] = True
cluster_data[config]["internal_ip_only"] = self.internal_ip_only

if self.tags:
cluster_data[config]["tags"] = self.tags
Expand Down
13 changes: 13 additions & 0 deletions tests/providers/google/cloud/operators/test_dataproc.py
Expand Up @@ -677,6 +677,19 @@ def test_build_with_gpu_accelerator(self):
cluster = generator.make()
assert CONFIG_WITH_GPU_ACCELERATOR == cluster

def test_build_with_default_value_for_internal_ip_only(self):
generator = ClusterGenerator(project_id="project_id")
cluster = generator.make()
assert "internal_ip_only" not in cluster["gce_cluster_config"]

def test_build_sets_provided_value_for_internal_ip_only(self):
for internal_ip_only in [True, False]:
generator = ClusterGenerator(
project_id="project_id", internal_ip_only=internal_ip_only, subnetwork_uri="subnetwork_uri"
)
cluster = generator.make()
assert cluster["gce_cluster_config"]["internal_ip_only"] == internal_ip_only


class TestDataprocCreateClusterOperator(DataprocClusterTestBase):
def test_deprecation_warning(self):
Expand Down

0 comments on commit 4150314

Please sign in to comment.