Skip to content

Commit

Permalink
issue-602-expose-service-improve, expose services handing for private…
Browse files Browse the repository at this point in the history
… clusters was improved
  • Loading branch information
DoodgeMatvey committed Oct 24, 2023
1 parent 26eee3c commit c709424
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions controllers/clusters/cadence_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/cassandra_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/kafka_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/kafkaconnect_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/opensearch_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/postgresql_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions controllers/clusters/zookeeper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 11 additions & 5 deletions pkg/exposeservice/expose_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c709424

Please sign in to comment.