From 11323f9efda2173376a25e1916b2567c34ae684f Mon Sep 17 00:00:00 2001 From: fabritsius Date: Fri, 28 Oct 2022 12:56:34 +0400 Subject: [PATCH 1/4] Correct the GCP Endpoints comparison --- pkg/controller/atlasproject/private_endpoint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/atlasproject/private_endpoint.go b/pkg/controller/atlasproject/private_endpoint.go index ab7495b076..8ed0f0fd41 100644 --- a/pkg/controller/atlasproject/private_endpoint.go +++ b/pkg/controller/atlasproject/private_endpoint.go @@ -268,7 +268,7 @@ func endpointNeedsUpdating(specPeService mdbv1.PrivateEndpoint, atlasPeService a case provider.ProviderAWS, provider.ProviderAzure: return specPeService.ID != atlasPeService.InterfaceEndpointID() case provider.ProviderGCP: - return specPeService.EndpointGroupName != atlasPeService.InterfaceEndpointID() && len(atlasPeService.EndpointServiceName) != len(specPeService.Endpoints) + return specPeService.EndpointGroupName != atlasPeService.InterfaceEndpointID() && len(atlasPeService.ServiceAttachmentNames) != len(specPeService.Endpoints) } } From df835d18adcabf967ee94e9e524381d04fafdbaf Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 31 Oct 2022 11:32:00 +0400 Subject: [PATCH 2/4] Parse Interface ID from serviceAttachmentNames for GCP --- .../atlasproject/private_endpoint.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/controller/atlasproject/private_endpoint.go b/pkg/controller/atlasproject/private_endpoint.go index 8ed0f0fd41..ea9a12c486 100644 --- a/pkg/controller/atlasproject/private_endpoint.go +++ b/pkg/controller/atlasproject/private_endpoint.go @@ -3,6 +3,7 @@ package atlasproject import ( "context" "errors" + "regexp" "go.mongodb.org/atlas/mongodbatlas" @@ -178,13 +179,27 @@ func (a atlasPE) InterfaceEndpointID() string { return a.PrivateEndpoints[0] } - if len(a.EndpointGroupNames) != 0 { - return a.EndpointGroupNames[0] + if len(a.ServiceAttachmentNames) != 0 { + return parseInterfaceIDForGCP(a.ServiceAttachmentNames) } return "" } +func parseInterfaceIDForGCP(serviceAttachmentNames []string) string { + if len(serviceAttachmentNames) < 1 { + return "" + } + + expr := regexp.MustCompile(`(\w+)-\d$`) + matches := expr.FindStringSubmatch(serviceAttachmentNames[0]) + if len(matches) < 2 { + return "" + } + + return matches[1] +} + func getAllPrivateEndpoints(client mongodbatlas.Client, projectID string) (result []atlasPE, err error) { providers := []string{"AWS", "AZURE", "GCP"} for _, provider := range providers { From ed0c5e8f34278ac85126260c97dc5c6111bbc6f1 Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 31 Oct 2022 13:52:35 +0400 Subject: [PATCH 3/4] Revert "Parse Interface ID from serviceAttachmentNames for GCP" This reverts commit df835d18adcabf967ee94e9e524381d04fafdbaf. --- .../atlasproject/private_endpoint.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/pkg/controller/atlasproject/private_endpoint.go b/pkg/controller/atlasproject/private_endpoint.go index ea9a12c486..8ed0f0fd41 100644 --- a/pkg/controller/atlasproject/private_endpoint.go +++ b/pkg/controller/atlasproject/private_endpoint.go @@ -3,7 +3,6 @@ package atlasproject import ( "context" "errors" - "regexp" "go.mongodb.org/atlas/mongodbatlas" @@ -179,27 +178,13 @@ func (a atlasPE) InterfaceEndpointID() string { return a.PrivateEndpoints[0] } - if len(a.ServiceAttachmentNames) != 0 { - return parseInterfaceIDForGCP(a.ServiceAttachmentNames) + if len(a.EndpointGroupNames) != 0 { + return a.EndpointGroupNames[0] } return "" } -func parseInterfaceIDForGCP(serviceAttachmentNames []string) string { - if len(serviceAttachmentNames) < 1 { - return "" - } - - expr := regexp.MustCompile(`(\w+)-\d$`) - matches := expr.FindStringSubmatch(serviceAttachmentNames[0]) - if len(matches) < 2 { - return "" - } - - return matches[1] -} - func getAllPrivateEndpoints(client mongodbatlas.Client, projectID string) (result []atlasPE, err error) { providers := []string{"AWS", "AZURE", "GCP"} for _, provider := range providers { From 8873d6c55b806a398f0b00dbe39ccaf829d164ee Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 31 Oct 2022 14:16:16 +0400 Subject: [PATCH 4/4] fixup! Correct the GCP Endpoints comparison --- pkg/controller/atlasproject/private_endpoint.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/atlasproject/private_endpoint.go b/pkg/controller/atlasproject/private_endpoint.go index 8ed0f0fd41..f6b26df4cc 100644 --- a/pkg/controller/atlasproject/private_endpoint.go +++ b/pkg/controller/atlasproject/private_endpoint.go @@ -268,7 +268,7 @@ func endpointNeedsUpdating(specPeService mdbv1.PrivateEndpoint, atlasPeService a case provider.ProviderAWS, provider.ProviderAzure: return specPeService.ID != atlasPeService.InterfaceEndpointID() case provider.ProviderGCP: - return specPeService.EndpointGroupName != atlasPeService.InterfaceEndpointID() && len(atlasPeService.ServiceAttachmentNames) != len(specPeService.Endpoints) + return specPeService.EndpointGroupName != atlasPeService.InterfaceEndpointID() || len(atlasPeService.ServiceAttachmentNames) != len(specPeService.Endpoints) } }