From e101a84f25ff98c23c2792a3f9fcaf43d3a1e4e3 Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 30 Aug 2021 17:07:46 +0300 Subject: [PATCH 1/6] Remove replicationSpecs field for AZURE cluster updates - cluster.replicationSpecs isn't allowed for Update operations on Azure clusters: https://docs.atlas.mongodb.com/reference/api/clusters-modify-one/#request-body-parameters --- pkg/broker/instance_operations.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/broker/instance_operations.go b/pkg/broker/instance_operations.go index 02a0805..908577c 100644 --- a/pkg/broker/instance_operations.go +++ b/pkg/broker/instance_operations.go @@ -505,6 +505,11 @@ func (b Broker) Update(ctx context.Context, instanceID string, details domain.Up // Atlas doesn't allow for cluster renaming - ignore any changes newPlan.Cluster.Name = existingCluster.Name + if newPlan.Cluster.ProviderSettings.ProviderName == "AZURE" { + logger.Warn("Cluster.ReplicationSpecs fields cannot be updated for 'AZURE' clusters") + newPlan.Cluster.ReplicationSpecs = nil + } + resultingCluster, _, err := client.Clusters.Update(ctx, oldPlan.Project.ID, existingCluster.Name, newPlan.Cluster) if err != nil { logger.Errorw("Failed to update Atlas cluster", "error", err, "new_cluster", newPlan.Cluster) From 7c98a7f2a1a605395266846e17fcf9103e211b0d Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 30 Aug 2021 17:09:17 +0300 Subject: [PATCH 2/6] Update go.sum file --- go.sum | 8 -------- 1 file changed, 8 deletions(-) diff --git a/go.sum b/go.sum index 94c1862..9f5e972 100644 --- a/go.sum +++ b/go.sum @@ -177,7 +177,6 @@ github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85q github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -200,7 +199,6 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= @@ -241,13 +239,11 @@ github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgo github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.0.0-20160823170715-cfb55aafdaf3/go.mod h1:Bvhd+E3laJ0AVkG0c9rmtZcnhV0HQ3+c3YxxqTvc/gA= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.0.0-20160504234017-7cafcd837844/go.mod h1:sjUstKUATFIcff4qlB53Kml0wQPtJVc/3fWrmuUmcfA= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= @@ -348,7 +344,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -407,7 +402,6 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= @@ -501,9 +495,7 @@ google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyz google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= From 027f70c96e3b65d8580fcb1af3a2243b98f531e1 Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 30 Aug 2021 17:59:27 +0300 Subject: [PATCH 3/6] fixup! Remove replicationSpecs field for AZURE cluster updates --- pkg/broker/instance_operations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/broker/instance_operations.go b/pkg/broker/instance_operations.go index 908577c..fb2dec8 100644 --- a/pkg/broker/instance_operations.go +++ b/pkg/broker/instance_operations.go @@ -505,7 +505,7 @@ func (b Broker) Update(ctx context.Context, instanceID string, details domain.Up // Atlas doesn't allow for cluster renaming - ignore any changes newPlan.Cluster.Name = existingCluster.Name - if newPlan.Cluster.ProviderSettings.ProviderName == "AZURE" { + if newPlan.Cluster.ProviderSettings.ProviderName == "AZURE" && len(newPlan.Cluster.ReplicationSpecs) > 0 { logger.Warn("Cluster.ReplicationSpecs fields cannot be updated for 'AZURE' clusters") newPlan.Cluster.ReplicationSpecs = nil } From 9a8f62e65cd7d876726c599895c88827fdd19467 Mon Sep 17 00:00:00 2001 From: fabritsius Date: Mon, 30 Aug 2021 19:12:09 +0300 Subject: [PATCH 4/6] Error-out if specs mismatch --- pkg/broker/instance_operations.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/broker/instance_operations.go b/pkg/broker/instance_operations.go index fb2dec8..8f955f9 100644 --- a/pkg/broker/instance_operations.go +++ b/pkg/broker/instance_operations.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" "net/http" + "reflect" "regexp" "github.com/mongodb/atlas-osb/pkg/broker/dynamicplans" @@ -506,7 +507,12 @@ func (b Broker) Update(ctx context.Context, instanceID string, details domain.Up newPlan.Cluster.Name = existingCluster.Name if newPlan.Cluster.ProviderSettings.ProviderName == "AZURE" && len(newPlan.Cluster.ReplicationSpecs) > 0 { - logger.Warn("Cluster.ReplicationSpecs fields cannot be updated for 'AZURE' clusters") + if !reflect.DeepEqual(oldPlan.Cluster.ReplicationSpecs, newPlan.Cluster.ReplicationSpecs) { + err = errors.New("update operation for cluster.ReplicationSpecs is not supported by Atlas for Azure clusters; please remove this section from the plan or recreate the cluster") + + return + } + newPlan.Cluster.ReplicationSpecs = nil } From 1f4053d37e55c17932505f0c483d5bd43bfe933d Mon Sep 17 00:00:00 2001 From: fabritsius Date: Tue, 31 Aug 2021 15:24:19 +0300 Subject: [PATCH 5/6] Fill IDs for ReplicationSpecs from the existing cluster --- pkg/broker/instance_operations.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/broker/instance_operations.go b/pkg/broker/instance_operations.go index 8f955f9..bf3be48 100644 --- a/pkg/broker/instance_operations.go +++ b/pkg/broker/instance_operations.go @@ -19,7 +19,6 @@ import ( "encoding/json" "fmt" "net/http" - "reflect" "regexp" "github.com/mongodb/atlas-osb/pkg/broker/dynamicplans" @@ -506,14 +505,16 @@ func (b Broker) Update(ctx context.Context, instanceID string, details domain.Up // Atlas doesn't allow for cluster renaming - ignore any changes newPlan.Cluster.Name = existingCluster.Name - if newPlan.Cluster.ProviderSettings.ProviderName == "AZURE" && len(newPlan.Cluster.ReplicationSpecs) > 0 { - if !reflect.DeepEqual(oldPlan.Cluster.ReplicationSpecs, newPlan.Cluster.ReplicationSpecs) { - err = errors.New("update operation for cluster.ReplicationSpecs is not supported by Atlas for Azure clusters; please remove this section from the plan or recreate the cluster") - - return + if len(newPlan.Cluster.ReplicationSpecs) > 0 { + logger.Debugw("Filling the IDs for Cluster.ReplicationSpecs", "newPlanCluster", newPlan.Cluster.ReplicationSpecs, "existingCluster", existingCluster.ReplicationSpecs) + for newSpecIdx, newSpec := range newPlan.Cluster.ReplicationSpecs { + for _, existing := range existingCluster.ReplicationSpecs { + if existing.ZoneName == newSpec.ZoneName { + newSpec.ID = existing.ID + newPlan.Cluster.ReplicationSpecs[newSpecIdx] = newSpec + } + } } - - newPlan.Cluster.ReplicationSpecs = nil } resultingCluster, _, err := client.Clusters.Update(ctx, oldPlan.Project.ID, existingCluster.Name, newPlan.Cluster) From f11ced9c970bff45755d776af52d2f1e0b0d731c Mon Sep 17 00:00:00 2001 From: fabritsius Date: Tue, 31 Aug 2021 15:46:34 +0300 Subject: [PATCH 6/6] fixup! Fill IDs for ReplicationSpecs from the existing cluster --- pkg/broker/instance_operations.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/broker/instance_operations.go b/pkg/broker/instance_operations.go index bf3be48..b00ded4 100644 --- a/pkg/broker/instance_operations.go +++ b/pkg/broker/instance_operations.go @@ -507,14 +507,7 @@ func (b Broker) Update(ctx context.Context, instanceID string, details domain.Up if len(newPlan.Cluster.ReplicationSpecs) > 0 { logger.Debugw("Filling the IDs for Cluster.ReplicationSpecs", "newPlanCluster", newPlan.Cluster.ReplicationSpecs, "existingCluster", existingCluster.ReplicationSpecs) - for newSpecIdx, newSpec := range newPlan.Cluster.ReplicationSpecs { - for _, existing := range existingCluster.ReplicationSpecs { - if existing.ZoneName == newSpec.ZoneName { - newSpec.ID = existing.ID - newPlan.Cluster.ReplicationSpecs[newSpecIdx] = newSpec - } - } - } + populateReplicationSpecsIDs(existingCluster.ReplicationSpecs, newPlan.Cluster.ReplicationSpecs) } resultingCluster, _, err := client.Clusters.Update(ctx, oldPlan.Project.ID, existingCluster.Name, newPlan.Cluster) @@ -838,3 +831,13 @@ func (b Broker) LastOperation(ctx context.Context, instanceID string, details do return resp, err } + +func populateReplicationSpecsIDs(sourceSpec, targetSpec []mongodbatlas.ReplicationSpec) { + for newSpecIdx, newSpec := range targetSpec { + for _, existing := range sourceSpec { + if existing.ZoneName == newSpec.ZoneName { + targetSpec[newSpecIdx].ID = existing.ID + } + } + } +}