Skip to content

Commit

Permalink
Update deployment validation to account for flex
Browse files Browse the repository at this point in the history
  • Loading branch information
roothorp committed Jan 13, 2025
1 parent 9a53e92 commit 8ac2bee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/controller/atlasdatabaseuser/databaseuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20231115008/mockadmin"
adminv20241113001 "go.mongodb.org/atlas-sdk/v20241113001/admin"

//mockadminv20241113001 "go.mongodb.org/atlas-sdk/v20241113001/mockadmin"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (r *AtlasDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Requ

isServerless := atlasDeployment.IsServerless()
isFlex := atlasDeployment.IsFlex()

wasDeleted := !atlasDeployment.GetDeletionTimestamp().IsZero()
existsInAtlas := deploymentInAtlas != nil

Expand Down
23 changes: 16 additions & 7 deletions pkg/controller/validate/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ import (
func AtlasDeployment(atlasDeployment *akov2.AtlasDeployment, isGov bool, regionUsageRestrictions string) error {
isRegularDeployment := atlasDeployment.Spec.DeploymentSpec != nil
isServerlessDeployment := atlasDeployment.Spec.ServerlessSpec != nil
isFlexDeployment := atlasDeployment.Spec.FlexSpec != nil
var err error
var tagsSpec []*akov2.TagSpec

switch {
case !isRegularDeployment && !isServerlessDeployment:
return errors.New("expected exactly one of spec.deploymentSpec or spec.serverlessSpec to be present, but none were")
case isRegularDeployment && isServerlessDeployment:
return errors.New("expected exactly one of spec.deploymentSpec or spec.serverlessSpec to be present, but none were")
case !isRegularDeployment && isServerlessDeployment:
case !isRegularDeployment && !isServerlessDeployment && !isFlexDeployment:
return errors.New("expected exactly one of spec.deploymentSpec or spec.serverlessSpec or spec.flexSpec to be present, but none were")
case isRegularDeployment && !isServerlessDeployment && !isFlexDeployment:
tagsSpec = atlasDeployment.Spec.DeploymentSpec.Tags
err = regularDeployment(atlasDeployment.Spec.DeploymentSpec, isGov, regionUsageRestrictions)
case !isRegularDeployment && isServerlessDeployment && !isFlexDeployment:
tagsSpec = atlasDeployment.Spec.ServerlessSpec.Tags
err = serverlessDeployment(atlasDeployment.Spec.ServerlessSpec)
case !isRegularDeployment && !isServerlessDeployment && isFlexDeployment:
tagsSpec = atlasDeployment.Spec.FlexSpec.Tags
err = flexDeployment(atlasDeployment.Spec.FlexSpec)
default:
tagsSpec = atlasDeployment.Spec.DeploymentSpec.Tags
err = regularDeployment(atlasDeployment.Spec.DeploymentSpec, isGov, regionUsageRestrictions)
return errors.New("expected exactly one of spec.deploymentSpec or spec.serverlessSpec or spec.flexSpec to be present, but none were")
}

if err != nil {
Expand Down Expand Up @@ -265,3 +269,8 @@ func serverlessPrivateEndpoints(privateEndpoints []akov2.ServerlessPrivateEndpoi

return nil
}

func flexDeployment(spec *akov2.FlexSpec) error {
// TODO
return nil
}

0 comments on commit 8ac2bee

Please sign in to comment.