Skip to content

Commit

Permalink
CLOUDP-221980: Added search nodes implementation (#1392)
Browse files Browse the repository at this point in the history
* Added search nodes implementation

* Removed debug output

* Make linter happy

* add e2e tests

* run search tests in CI

* set conditions for search nodes

* fix tests

* fix unit tests

* fix e2e tests more

* update manifests

* updates as per review

* bump to new atlas sdk version

* add more unit tests

* updates per review

* add unit testing

* more informative conditions

* centralise error logging & clean up

* rewrite to idiomatic controller using state handlers and transitions

* Add descriptions to new CRD fields

* terminate on changes during updating state

* further unit tests

* Update pkg/controller/atlasdeployment/search_nodes.go

Co-authored-by: josvaz <[email protected]>

* Update pkg/controller/atlasdeployment/search_nodes.go

Co-authored-by: Helder Santana <[email protected]>

* Update pkg/controller/atlasdeployment/search_nodes.go

Co-authored-by: josvaz <[email protected]>

* further unit tests for new states

* appease linter & fix comments

---------

Co-authored-by: Roo Thorp <[email protected]>
Co-authored-by: Sergiusz Urbaniak <[email protected]>
Co-authored-by: josvaz <[email protected]>
Co-authored-by: Helder Santana <[email protected]>
  • Loading branch information
5 people authored Apr 26, 2024
1 parent dc10775 commit bacd4c5
Show file tree
Hide file tree
Showing 12 changed files with 1,312 additions and 155 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ jobs:
"teams",
"backup-config",
"data-federation",
"deletion-protection"
"deletion-protection",
"atlas-search"
]
steps:
- name: Get repo files from cache
Expand Down
33 changes: 33 additions & 0 deletions config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,39 @@ spec:
type: array
rootCertType:
type: string
searchNodes:
description: Settings for Search Nodes for the cluster. Currently,
at most one search node configuration may be defined.
items:
properties:
instanceSize:
description: Hardware specification for the Search Node
instance sizes.
enum:
- S20_HIGHCPU_NVME
- S30_HIGHCPU_NVME
- S40_HIGHCPU_NVME
- S50_HIGHCPU_NVME
- S60_HIGHCPU_NVME
- S70_HIGHCPU_NVME
- S80_HIGHCPU_NVME
- S30_LOWCPU_NVME
- S40_LOWCPU_NVME
- S50_LOWCPU_NVME
- S60_LOWCPU_NVME
- S80_LOWCPU_NVME
- S90_LOWCPU_NVME
- S100_LOWCPU_NVME
- S110_LOWCPU_NVME
type: string
nodeCount:
description: Number of Search Nodes in the cluster.
maximum: 32
minimum: 2
type: integer
type: object
maxItems: 1
type: array
tags:
description: Key-value pairs for resource tagging.
items:
Expand Down
40 changes: 40 additions & 0 deletions pkg/api/v1/atlasdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"regexp"
"strconv"

"go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas/mongodbatlas"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -70,6 +71,16 @@ type AtlasDeploymentSpec struct {
ProcessArgs *ProcessArgs `json:"processArgs,omitempty"`
}

type SearchNode struct {
// Hardware specification for the Search Node instance sizes.
// +kubebuilder:validation:Enum:=S20_HIGHCPU_NVME;S30_HIGHCPU_NVME;S40_HIGHCPU_NVME;S50_HIGHCPU_NVME;S60_HIGHCPU_NVME;S70_HIGHCPU_NVME;S80_HIGHCPU_NVME;S30_LOWCPU_NVME;S40_LOWCPU_NVME;S50_LOWCPU_NVME;S60_LOWCPU_NVME;S80_LOWCPU_NVME;S90_LOWCPU_NVME;S100_LOWCPU_NVME;S110_LOWCPU_NVME
InstanceSize string `json:"instanceSize,omitempty"`
// Number of Search Nodes in the cluster.
// +kubebuilder:validation:Minimum:=2
// +kubebuilder:validation:Maximum:=32
NodeCount uint8 `json:"nodeCount,omitempty"`
}

type AdvancedDeploymentSpec struct {
// Applicable only for M10+ deployments.
// Flag that indicates if the deployment uses Cloud Backups for backups.
Expand Down Expand Up @@ -130,6 +141,10 @@ type AdvancedDeploymentSpec struct {
// Flag that indicates whether termination protection is enabled on the cluster. If set to true, MongoDB Cloud won't delete the cluster. If set to false, MongoDB Cloud will delete the cluster.
// +kubebuilder:default:=false
TerminationProtectionEnabled bool `json:"terminationProtectionEnabled,omitempty"`
// Settings for Search Nodes for the cluster. Currently, at most one search node configuration may be defined.
// +kubebuilder:validation:MaxItems=1
// +optional
SearchNodes []SearchNode `json:"searchNodes,omitempty"`
}

// ToAtlas converts the AdvancedDeploymentSpec to native Atlas client ToAtlas format.
Expand All @@ -139,6 +154,21 @@ func (s *AdvancedDeploymentSpec) ToAtlas() (*mongodbatlas.AdvancedCluster, error
return result, err
}

func (s *AdvancedDeploymentSpec) SearchNodesToAtlas() []admin.ApiSearchDeploymentSpec {
if len(s.SearchNodes) == 0 {
return nil
}
result := make([]admin.ApiSearchDeploymentSpec, len(s.SearchNodes))

for i := 0; i < len(s.SearchNodes); i++ {
result[i] = admin.ApiSearchDeploymentSpec{
InstanceSize: s.SearchNodes[i].InstanceSize,
NodeCount: int(s.SearchNodes[i].NodeCount),
}
}
return result
}

func LessAD(a, b interface{}) bool {
switch a.(type) {
case *AdvancedReplicationSpec:
Expand Down Expand Up @@ -711,6 +741,16 @@ func (c *AtlasDeployment) WithBackingProvider(name string) *AtlasDeployment {
return c
}

func (c *AtlasDeployment) WithSearchNodes(instanceSize string, count uint8) *AtlasDeployment {
c.Spec.DeploymentSpec.SearchNodes = []SearchNode{
{
InstanceSize: instanceSize,
NodeCount: count,
},
}
return c
}

// Lightweight makes the deployment work with small shared instance M2. This is useful for non-deployment tests (e.g.
// database users) and saves some money for the company.
func (c *AtlasDeployment) Lightweight() *AtlasDeployment {
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/status/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
ServerlessPrivateEndpointReadyType ConditionType = "ServerlessPrivateEndpointReady"
ManagedNamespacesReadyType ConditionType = "ManagedNamespacesReady"
CustomZoneMappingReadyType ConditionType = "CustomZoneMappingReady"
SearchNodesReadyType ConditionType = "SearchNodesReady"
)

// AtlasDatabaseUser condition types
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/controller/atlasdeployment/advanced_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func advancedDeploymentIdle(ctx *workflow.Context, project *akov2.AtlasProject,
return atlasDeploymentAsAtlas, workflow.Terminate(workflow.Internal, err.Error())
}

searchNodeResult := handleSearchNodes(ctx, deployment, project.ID())
if !searchNodeResult.IsOk() {
return atlasDeploymentAsAtlas, searchNodeResult
}

if areEqual, _ := AdvancedDeploymentsEqual(ctx.Log, &specDeployment, &atlasDeployment); areEqual {
return atlasDeploymentAsAtlas, workflow.OK()
}
Expand Down Expand Up @@ -198,6 +203,8 @@ func AdvancedDeploymentsEqual(log *zap.SugaredLogger, deploymentOperator *akov2.
expected := deploymentOperator.DeepCopy()
actualCleaned := cleanupFieldsToCompare(deploymentAtlas.DeepCopy(), expected)

// Ignore Atlas Search and Search Nodes
expected.SearchNodes = nil
// Ignore differences on auto-scaled region configs
for _, rs := range expected.ReplicationSpecs {
for _, rc := range rs.RegionConfigs {
Expand Down
Loading

0 comments on commit bacd4c5

Please sign in to comment.