@@ -17,6 +17,7 @@ limitations under the License.
17
17
package v1
18
18
19
19
import (
20
+ "errors"
20
21
"fmt"
21
22
"reflect"
22
23
"regexp"
@@ -181,6 +182,21 @@ func (s *AdvancedDeploymentSpec) ToAtlas() (*mongodbatlas.AdvancedCluster, error
181
182
return result , err
182
183
}
183
184
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
+
184
200
// ServerlessSpec defines the desired state of Atlas Serverless Instance
185
201
type ServerlessSpec struct {
186
202
// Name of the serverless deployment as it appears in Atlas.
@@ -489,8 +505,8 @@ type RegionsConfig struct {
489
505
// Check compatibility with library type.
490
506
var _ = RegionsConfig (mongodbatlas.RegionsConfig {})
491
507
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 ) {
494
510
result := & mongodbatlas.Cluster {}
495
511
err := compat .JSONCopy (result , * spec .DeploymentSpec )
496
512
@@ -505,6 +521,16 @@ func (spec *AtlasDeploymentSpec) Deployment() (*mongodbatlas.Cluster, error) {
505
521
return result , err
506
522
}
507
523
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
+
508
534
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
509
535
// +kubebuilder:object:root=true
510
536
// +kubebuilder:subresource:status
@@ -519,20 +545,29 @@ type AtlasDeployment struct {
519
545
}
520
546
521
547
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
524
550
}
525
551
if c .IsServerless () {
526
552
return c .Spec .ServerlessSpec .Name
527
553
}
528
- return c .Spec .DeploymentSpec .Name
554
+ if c .IsAdvancedDeployment () {
555
+ return c .Spec .AdvancedDeploymentSpec .Name
556
+ }
557
+
558
+ return ""
529
559
}
530
560
531
561
// IsServerless returns true if the AtlasDeployment is configured to be a serverless instance
532
562
func (c * AtlasDeployment ) IsServerless () bool {
533
563
return c .Spec .ServerlessSpec != nil
534
564
}
535
565
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
+
536
571
// IsAdvancedDeployment returns true if the AtlasDeployment is configured to be an advanced deployment.
537
572
func (c * AtlasDeployment ) IsAdvancedDeployment () bool {
538
573
return c .Spec .AdvancedDeploymentSpec != nil
@@ -641,7 +676,7 @@ func newAwsAdvancedDeployment(namespace, name, nameInAtlas, instanceSize, provid
641
676
}
642
677
643
678
func (c * AtlasDeployment ) WithName (name string ) * AtlasDeployment {
644
- c .Spec . DeploymentSpec . Name = name
679
+ c .Name = name
645
680
return c
646
681
}
647
682
0 commit comments