@@ -17,6 +17,7 @@ limitations under the License.
1717package v1
1818
1919import (
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
185201type 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.
490506var _ = 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
521547func (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
532562func (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.
537572func (c * AtlasDeployment ) IsAdvancedDeployment () bool {
538573 return c .Spec .AdvancedDeploymentSpec != nil
@@ -641,7 +676,7 @@ func newAwsAdvancedDeployment(namespace, name, nameInAtlas, instanceSize, provid
641676}
642677
643678func (c * AtlasDeployment ) WithName (name string ) * AtlasDeployment {
644- c .Spec . DeploymentSpec . Name = name
679+ c .Name = name
645680 return c
646681}
647682
0 commit comments