From ace0764e3bdf17b54b7b4143074ba892fd4104e9 Mon Sep 17 00:00:00 2001 From: doodgeMatvey Date: Mon, 16 Oct 2023 14:09:48 +0300 Subject: [PATCH] issue-594-expose-services-deferred-status, deferred status for clusters was handled --- .../postgresqluser_controller.go | 1 - .../clusters/postgresql_controller_test.go | 2 +- pkg/exposeservice/expose_service.go | 26 +++++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/controllers/clusterresources/postgresqluser_controller.go b/controllers/clusterresources/postgresqluser_controller.go index 505c8882e..6269b4e7a 100644 --- a/controllers/clusterresources/postgresqluser_controller.go +++ b/controllers/clusterresources/postgresqluser_controller.go @@ -290,7 +290,6 @@ func (r *PostgreSQLUserReconciler) createUser( return fmt.Errorf("cannot list nodes, err: %w", err) } - // TODO: Handle scenario if there are no nodes with external IP, check private/public cluster for _, node := range nodeList.Items { for _, nodeAddress := range node.Status.Addresses { if nodeAddress.Type == k8sCore.NodeExternalIP { diff --git a/controllers/clusters/postgresql_controller_test.go b/controllers/clusters/postgresql_controller_test.go index 8aa7c84ee..a09cfc146 100644 --- a/controllers/clusters/postgresql_controller_test.go +++ b/controllers/clusters/postgresql_controller_test.go @@ -107,7 +107,7 @@ var _ = Describe("PostgreSQL Controller", func() { }) }) - When("Deleting the Kafka Connect resource by avoiding operator", func() { + When("Deleting the PostgreSQL resource by avoiding operator", func() { It("should try to get the cluster details and receive StatusNotFound", func() { postgresqlManifest2 := postgresqlManifest.DeepCopy() postgresqlManifest2.Name += "-test-external-delete" diff --git a/pkg/exposeservice/expose_service.go b/pkg/exposeservice/expose_service.go index ea02de72f..b4c89b2fe 100644 --- a/pkg/exposeservice/expose_service.go +++ b/pkg/exposeservice/expose_service.go @@ -37,6 +37,21 @@ func Create( nodes []*v1beta1.Node, targetPort int32, ) error { + addresses := []v1.EndpointAddress{} + for _, node := range nodes { + if node.PublicAddress == "" { + continue + } + + addresses = append(addresses, v1.EndpointAddress{ + IP: node.PublicAddress, + }) + } + + if len(addresses) == 0 { + return nil + } + svcName := fmt.Sprintf(models.ExposeServiceNameTemplate, clusterName) service := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -58,17 +73,6 @@ func Create( }, } - addresses := []v1.EndpointAddress{} - for _, node := range nodes { - if node.PublicAddress == "" { - continue - } - - addresses = append(addresses, v1.EndpointAddress{ - IP: node.PublicAddress, - }) - } - endpoints := &v1.Endpoints{ ObjectMeta: metav1.ObjectMeta{ Name: svcName,