Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure vote / tag / priority #1467

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1/mongodbcommunity_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ type MongoDBCommunitySpec struct {
// +kubebuilder:pruning:PreserveUnknownFields
// +nullable
AdditionalConnectionStringConfig MapWrapper `json:"additionalConnectionStringConfig,omitempty"`

// MemberConfig
// +optional
MemberConfig []automationconfig.MemberOptions `json:"memberConfig,omitempty"`
}

// MapWrapper is a wrapper for a map to be used by other structs.
Expand Down
7 changes: 7 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down Expand Up @@ -188,6 +187,20 @@ spec:
description: FeatureCompatibilityVersion configures the feature compatibility
version that will be set for the deployment
type: string
memberConfig:
description: MemberConfig
items:
properties:
priority:
type: string
tags:
additionalProperties:
type: string
type: object
votes:
type: integer
type: object
type: array
members:
description: Members is the number of members in the replica set
type: integer
Expand Down
1 change: 1 addition & 0 deletions controllers/replica_set_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, auth automationconfig.Aut
SetFCV(mdb.Spec.FeatureCompatibilityVersion).
SetOptions(automationconfig.Options{DownloadBase: "/var/lib/mongodb-mms-automation"}).
SetAuth(auth).
SetMemberOptions(mdb.Spec.MemberConfig).
SetDataDir(mdb.GetMongodConfiguration().GetDBDataDir()).
AddModifications(getMongodConfigModification(mdb)).
AddModifications(modifications...).
Expand Down
23 changes: 22 additions & 1 deletion test/e2e/mongodbtests/mongodbtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/mongodb/mongodb-kubernetes-operator/pkg/authentication/authtypes"
"strconv"
"strings"
"testing"
"time"

"github.com/mongodb/mongodb-kubernetes-operator/pkg/authentication/authtypes"

"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/container"
Expand All @@ -34,6 +36,11 @@ func SkipTestIfLocal(t *testing.T, msg string, f func(t *testing.T)) {
t.Run(msg, f)
}

func strPointer(n float32) *string {
s := strconv.FormatFloat(float64(n), 'f', -1, 64)
return &s
}

// StatefulSetBecomesReady ensures that the underlying stateful set
// reaches the running state.
func StatefulSetBecomesReady(mdb *mdbv1.MongoDBCommunity, opts ...wait.Configuration) func(t *testing.T) {
Expand Down Expand Up @@ -416,6 +423,20 @@ func AutomationConfigHasTheExpectedCustomRoles(mdb *mdbv1.MongoDBCommunity, role
}
}

func AutomationConfigHasVoteTagPriorityConfigured(mdb *mdbv1.MongoDBCommunity, memberOptions []automationconfig.MemberOptions) func(t *testing.T) {
acMemberOptions := make([]automationconfig.MemberOptions, 0)

return func(t *testing.T) {
currentAc := getAutomationConfig(t, mdb)
rsMemebers := currentAc.ReplicaSets

for _, m := range rsMemebers[0].Members {
acMemberOptions = append(acMemberOptions, automationconfig.MemberOptions{Votes: m.Votes, Priority: strPointer(m.Priority), Tags: m.Tags})
}
assert.ElementsMatch(t, memberOptions, acMemberOptions)
}
}

// CreateMongoDBResource creates the MongoDB resource
func CreateMongoDBResource(mdb *mdbv1.MongoDBCommunity, ctx *e2eutil.Context) func(*testing.T) {
return func(t *testing.T) {
Expand Down
24 changes: 24 additions & 0 deletions test/e2e/replica_set/replica_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

func intPtr(x int) *int { return &x }
func strPtr(s string) *string { return &s }

func TestReplicaSet(t *testing.T) {
ctx := setup.Setup(t)
defer ctx.Teardown()
Expand Down Expand Up @@ -54,6 +57,26 @@ func TestReplicaSet(t *testing.T) {
mdb.Spec.AgentConfiguration.LogRotate = &lcr
mdb.Spec.AgentConfiguration.SystemLog = &systemLog

// config member options
memberOptions := []automationconfig.MemberOptions{
{
Votes: intPtr(1),
Tags: map[string]string{"foo1": "bar1"},
Priority: strPtr("1.5"),
},
{
Votes: intPtr(1),
Tags: map[string]string{"foo2": "bar2"},
Priority: strPtr("1"),
},
{
Votes: intPtr(1),
Tags: map[string]string{"foo3": "bar3"},
Priority: strPtr("2.5"),
},
}
mdb.Spec.MemberConfig = memberOptions

tester, err := FromResource(t, mdb)
if err != nil {
t.Fatal(err)
Expand All @@ -71,4 +94,5 @@ func TestReplicaSet(t *testing.T) {
tester.ConnectivitySucceeds(WithURI(mongodbtests.GetSrvConnectionStringForUser(mdb, scramUser))))
t.Run("Ensure Authentication", tester.EnsureAuthenticationIsConfigured(3))
t.Run("AutomationConfig has the correct version", mongodbtests.AutomationConfigVersionHasTheExpectedVersion(&mdb, 1))
t.Run("AutomationCondig has correct member options", mongodbtests.AutomationConfigHasVoteTagPriorityConfigured(&mdb, memberOptions))
}
Loading