Skip to content

Commit 95fbdd5

Browse files
authored
CLOUDP-147254: Use only Advanced Cluster API (mongodb#825)
1 parent e920ca9 commit 95fbdd5

22 files changed

+669
-821
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ require (
9595
go.opencensus.io v0.24.0 // indirect
9696
go.uber.org/atomic v1.9.0 // indirect
9797
go.uber.org/multierr v1.7.0 // indirect
98-
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
98+
golang.org/x/crypto v0.1.0 // indirect
9999
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb
100100
golang.org/x/net v0.2.0 // indirect
101101
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
401401
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
402402
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
403403
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
404-
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
405404
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
405+
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
406+
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
406407
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
407408
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
408409
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=

pkg/api/v1/atlasdeployment_types.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"reflect"
2223
"regexp"
@@ -181,6 +182,21 @@ func (s *AdvancedDeploymentSpec) ToAtlas() (*mongodbatlas.AdvancedCluster, error
181182
return result, err
182183
}
183184

185+
func LessAD(a, b interface{}) bool {
186+
switch a.(type) {
187+
case *AdvancedReplicationSpec:
188+
return a.(*AdvancedReplicationSpec).ZoneName < b.(*AdvancedReplicationSpec).ZoneName
189+
case *AdvancedRegionConfig:
190+
return a.(*AdvancedRegionConfig).RegionName < b.(*AdvancedRegionConfig).RegionName
191+
case ManagedNamespace:
192+
return a.(ManagedNamespace).Collection < b.(ManagedNamespace).Collection
193+
case CustomZoneMapping:
194+
return a.(CustomZoneMapping).Zone < b.(CustomZoneMapping).Zone
195+
default:
196+
return false
197+
}
198+
}
199+
184200
// ServerlessSpec defines the desired state of Atlas Serverless Instance
185201
type ServerlessSpec struct {
186202
// Name of the serverless deployment as it appears in Atlas.
@@ -489,8 +505,8 @@ type RegionsConfig struct {
489505
// Check compatibility with library type.
490506
var _ = RegionsConfig(mongodbatlas.RegionsConfig{})
491507

492-
// Deployment converts the Spec to native Atlas client format.
493-
func (spec *AtlasDeploymentSpec) Deployment() (*mongodbatlas.Cluster, error) {
508+
// LegacyDeployment converts the Spec to native Atlas client format.
509+
func (spec *AtlasDeploymentSpec) LegacyDeployment() (*mongodbatlas.Cluster, error) {
494510
result := &mongodbatlas.Cluster{}
495511
err := compat.JSONCopy(result, *spec.DeploymentSpec)
496512

@@ -505,6 +521,16 @@ func (spec *AtlasDeploymentSpec) Deployment() (*mongodbatlas.Cluster, error) {
505521
return result, err
506522
}
507523

524+
// Deployment converts the Spec to native Atlas client format.
525+
func (spec *AtlasDeploymentSpec) Deployment() (*mongodbatlas.AdvancedCluster, error) {
526+
result := &mongodbatlas.AdvancedCluster{}
527+
if spec.AdvancedDeploymentSpec == nil {
528+
return result, errors.New("AdvancedDeploymentSpec is empty")
529+
}
530+
err := compat.JSONCopy(result, *spec.AdvancedDeploymentSpec)
531+
return result, err
532+
}
533+
508534
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
509535
// +kubebuilder:object:root=true
510536
// +kubebuilder:subresource:status
@@ -519,20 +545,29 @@ type AtlasDeployment struct {
519545
}
520546

521547
func (c *AtlasDeployment) GetDeploymentName() string {
522-
if c.IsAdvancedDeployment() {
523-
return c.Spec.AdvancedDeploymentSpec.Name
548+
if c.IsLegacyDeployment() {
549+
return c.Spec.DeploymentSpec.Name
524550
}
525551
if c.IsServerless() {
526552
return c.Spec.ServerlessSpec.Name
527553
}
528-
return c.Spec.DeploymentSpec.Name
554+
if c.IsAdvancedDeployment() {
555+
return c.Spec.AdvancedDeploymentSpec.Name
556+
}
557+
558+
return ""
529559
}
530560

531561
// IsServerless returns true if the AtlasDeployment is configured to be a serverless instance
532562
func (c *AtlasDeployment) IsServerless() bool {
533563
return c.Spec.ServerlessSpec != nil
534564
}
535565

566+
// IsLegacyDeployment returns true if the AtlasDeployment is configured to be an legacy deployment.
567+
func (c *AtlasDeployment) IsLegacyDeployment() bool {
568+
return c.Spec.DeploymentSpec != nil
569+
}
570+
536571
// IsAdvancedDeployment returns true if the AtlasDeployment is configured to be an advanced deployment.
537572
func (c *AtlasDeployment) IsAdvancedDeployment() bool {
538573
return c.Spec.AdvancedDeploymentSpec != nil
@@ -641,7 +676,7 @@ func newAwsAdvancedDeployment(namespace, name, nameInAtlas, instanceSize, provid
641676
}
642677

643678
func (c *AtlasDeployment) WithName(name string) *AtlasDeployment {
644-
c.Spec.DeploymentSpec.Name = name
679+
c.Name = name
645680
return c
646681
}
647682

pkg/api/v1/atlasdeployment_types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestEnums(t *testing.T) {
7878
ClusterType: TypeGeoSharded,
7979
},
8080
}
81-
transformedCluster, err := operatorCluster.Deployment()
81+
transformedCluster, err := operatorCluster.LegacyDeployment()
8282
assert.NoError(t, err)
8383
assert.Equal(t, atlasCluster, *transformedCluster)
8484
}

pkg/controller/atlasdatabaseuser/databaseuser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ func performUpdateInAtlas(ctx *workflow.Context, k8sClient client.Client, projec
151151
func validateScopes(ctx *workflow.Context, projectID string, user mdbv1.AtlasDatabaseUser) error {
152152
for _, s := range user.GetScopes(mdbv1.DeploymentScopeType) {
153153
var apiError *mongodbatlas.ErrorResponse
154-
_, _, regularErr := ctx.Client.Clusters.Get(context.Background(), projectID, s)
155154
_, _, advancedErr := ctx.Client.AdvancedClusters.Get(context.Background(), projectID, s)
156-
if errors.As(regularErr, &apiError) && apiError.ErrorCode == atlas.ClusterNotFound && errors.As(advancedErr, &apiError) && apiError.ErrorCode == atlas.ClusterNotFound {
155+
if errors.As(advancedErr, &apiError) && apiError.ErrorCode == atlas.ClusterNotFound {
157156
return fmt.Errorf(`"scopes" field references deployment named "%s" but such deployment doesn't exist in Atlas'`, s)
158157
}
159158
}

0 commit comments

Comments
 (0)