diff --git a/controllers/clusters/cadence_controller.go b/controllers/clusters/cadence_controller.go index 3c95990b9..00cdd012d 100644 --- a/controllers/clusters/cadence_controller.go +++ b/controllers/clusters/cadence_controller.go @@ -841,6 +841,7 @@ func (r *CadenceReconciler) newWatchStatusJob(cadence *v1beta1.Cadence) schedule err = exposeservice.Create(r.Client, cadence.Name, cadence.Namespace, + cadence.Spec.PrivateNetworkCluster, nodes, models.CadenceConnectionPort) if err != nil { diff --git a/controllers/clusters/cassandra_controller.go b/controllers/clusters/cassandra_controller.go index 34498e1cb..f34beab5c 100644 --- a/controllers/clusters/cassandra_controller.go +++ b/controllers/clusters/cassandra_controller.go @@ -921,6 +921,7 @@ func (r *CassandraReconciler) newWatchStatusJob(cassandra *v1beta1.Cassandra) sc err = exposeservice.Create(r.Client, cassandra.Name, cassandra.Namespace, + cassandra.Spec.PrivateNetworkCluster, nodes, models.CassandraConnectionPort) if err != nil { diff --git a/controllers/clusters/kafka_controller.go b/controllers/clusters/kafka_controller.go index a24e576da..8dc3d1e91 100644 --- a/controllers/clusters/kafka_controller.go +++ b/controllers/clusters/kafka_controller.go @@ -752,6 +752,7 @@ func (r *KafkaReconciler) newWatchStatusJob(kafka *v1beta1.Kafka) scheduler.Job err = exposeservice.Create(r.Client, kafka.Name, kafka.Namespace, + kafka.Spec.PrivateNetworkCluster, nodes, models.KafkaConnectionPort) if err != nil { diff --git a/controllers/clusters/kafkaconnect_controller.go b/controllers/clusters/kafkaconnect_controller.go index b2dffc139..a1be7eb39 100644 --- a/controllers/clusters/kafkaconnect_controller.go +++ b/controllers/clusters/kafkaconnect_controller.go @@ -535,6 +535,7 @@ func (r *KafkaConnectReconciler) newWatchStatusJob(kc *v1beta1.KafkaConnect) sch err = exposeservice.Create(r.Client, kc.Name, kc.Namespace, + kc.Spec.PrivateNetworkCluster, nodes, models.KafkaConnectConnectionPort) if err != nil { diff --git a/controllers/clusters/opensearch_controller.go b/controllers/clusters/opensearch_controller.go index 44b5f24db..ba357c44e 100644 --- a/controllers/clusters/opensearch_controller.go +++ b/controllers/clusters/opensearch_controller.go @@ -665,6 +665,7 @@ func (r *OpenSearchReconciler) newWatchStatusJob(o *v1beta1.OpenSearch) schedule err = exposeservice.Create(r.Client, o.Name, o.Namespace, + o.Spec.PrivateNetworkCluster, nodes, models.OpenSearchConnectionPort) if err != nil { diff --git a/controllers/clusters/postgresql_controller.go b/controllers/clusters/postgresql_controller.go index 2083db2b8..c136d01f7 100644 --- a/controllers/clusters/postgresql_controller.go +++ b/controllers/clusters/postgresql_controller.go @@ -1157,6 +1157,7 @@ func (r *PostgreSQLReconciler) newWatchStatusJob(pg *v1beta1.PostgreSQL) schedul err = exposeservice.Create(r.Client, pg.Name, pg.Namespace, + pg.Spec.PrivateNetworkCluster, nodes, models.PgConnectionPort) if err != nil { diff --git a/controllers/clusters/redis_controller.go b/controllers/clusters/redis_controller.go index a46d687fb..e69d3a0be 100644 --- a/controllers/clusters/redis_controller.go +++ b/controllers/clusters/redis_controller.go @@ -965,6 +965,7 @@ func (r *RedisReconciler) newWatchStatusJob(redis *v1beta1.Redis) scheduler.Job err = exposeservice.Create(r.Client, redis.Name, redis.Namespace, + redis.Spec.PrivateNetworkCluster, nodes, models.RedisConnectionPort) if err != nil { diff --git a/controllers/clusters/zookeeper_controller.go b/controllers/clusters/zookeeper_controller.go index a33f57857..e95e79793 100644 --- a/controllers/clusters/zookeeper_controller.go +++ b/controllers/clusters/zookeeper_controller.go @@ -493,6 +493,7 @@ func (r *ZookeeperReconciler) newWatchStatusJob(zook *v1beta1.Zookeeper) schedul err = exposeservice.Create(r.Client, zook.Name, zook.Namespace, + zook.Spec.PrivateNetworkCluster, nodes, models.ZookeeperConnectionPort) if err != nil { diff --git a/pkg/exposeservice/expose_service.go b/pkg/exposeservice/expose_service.go index b4c89b2fe..2749c7e8b 100644 --- a/pkg/exposeservice/expose_service.go +++ b/pkg/exposeservice/expose_service.go @@ -34,18 +34,24 @@ func Create( c client.Client, clusterName string, ns string, + privateNetworkCluster bool, nodes []*v1beta1.Node, targetPort int32, ) error { addresses := []v1.EndpointAddress{} for _, node := range nodes { - if node.PublicAddress == "" { - continue + address := "" + if !privateNetworkCluster { + address = node.PublicAddress + } else { + address = node.PrivateAddress } - addresses = append(addresses, v1.EndpointAddress{ - IP: node.PublicAddress, - }) + if address != "" { + addresses = append(addresses, v1.EndpointAddress{ + IP: address, + }) + } } if len(addresses) == 0 {