Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

Commit 5715b5b

Browse files
authored
CLOUDP-59502: Configure FCV (#30)
1 parent 1ae5cee commit 5715b5b

File tree

8 files changed

+64
-8
lines changed

8 files changed

+64
-8
lines changed

deploy/crds/mongodb.com_mongodbs_crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ spec:
3131
spec:
3232
description: MongoDBSpec defines the desired state of MongoDB
3333
properties:
34+
featureCompatibilityVersion:
35+
description: FeatureCompatibilityVersion configures the feature compatibility
36+
version that will be set for the deployment
37+
type: string
3438
members:
3539
description: Members is the number of members in the replica set
3640
type: integer

pkg/apis/mongodb/v1/mongodb_types.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ type MongoDBSpec struct {
2424
Type Type `json:"type"`
2525
// Version defines which version of MongoDB will be used
2626
Version string `json:"version"`
27+
28+
// FeatureCompatibilityVersion configures the feature compatibility version that will
29+
// be set for the deployment
30+
// +optional
31+
FeatureCompatibilityVersion string `json:"featureCompatibilityVersion,omitempty"`
2732
}
2833

2934
// MongoDBStatus defines the observed state of MongoDB
@@ -55,14 +60,26 @@ func (m MongoDB) MongoURI() string {
5560

5661
// ServiceName returns the name of the Service that should be created for
5762
// this resource
58-
func (m *MongoDB) ServiceName() string {
63+
func (m MongoDB) ServiceName() string {
5964
return m.Name + "-svc"
6065
}
6166

62-
func (m *MongoDB) ConfigMapName() string {
67+
func (m MongoDB) ConfigMapName() string {
6368
return m.Name + "-config"
6469
}
6570

71+
// GetFCV returns the feature compatibility version. If no FeatureCompatibilityVersion is specified.
72+
// It uses the major and minor version for whichever version of MongoDB is configured.
73+
func (m MongoDB) GetFCV() string {
74+
versionToSplit := m.Spec.FeatureCompatibilityVersion
75+
if versionToSplit == "" {
76+
versionToSplit = m.Spec.Version
77+
}
78+
minorIndex := 1
79+
parts := strings.Split(versionToSplit, ".")
80+
return strings.Join(parts[:minorIndex+1], ".")
81+
}
82+
6683
// TODO: build the correct statefulset - this is a dummy implementation
6784
// BuildStatefulSet constructs an instance of appsv1.StatefulSet
6885
// which should be created during reconciliation

pkg/apis/mongodb/v1/mongodb_types_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ func TestMongoDB_MongoURI(t *testing.T) {
1616
assert.Equal(t, mdb.MongoURI(), "mongodb://my-big-rs-0.my-big-rs-svc.my-big-namespace.svc.cluster.local:27017,my-big-rs-1.my-big-rs-svc.my-big-namespace.svc.cluster.local:27017,my-big-rs-2.my-big-rs-svc.my-big-namespace.svc.cluster.local:27017,my-big-rs-3.my-big-rs-svc.my-big-namespace.svc.cluster.local:27017,my-big-rs-4.my-big-rs-svc.my-big-namespace.svc.cluster.local:27017")
1717
}
1818

19+
func TestGetFCV(t *testing.T) {
20+
mdb := newReplicaSet(3, "my-rs", "my-ns")
21+
mdb.Spec.Version = "4.2.0"
22+
assert.Equal(t, "4.2", mdb.GetFCV())
23+
24+
mdb.Spec.FeatureCompatibilityVersion = "4.0"
25+
assert.Equal(t, "4.0", mdb.GetFCV())
26+
27+
mdb.Spec.FeatureCompatibilityVersion = ""
28+
assert.Equal(t, "4.2", mdb.GetFCV())
29+
}
30+
1931
func newReplicaSet(members int, name, namespace string) MongoDB {
2032
return MongoDB{
2133
TypeMeta: metav1.TypeMeta{},

pkg/automationconfig/automation_config.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ type SystemLog struct {
6868
Path string `json:"path"`
6969
}
7070

71-
func newProcess(name, hostName, version, replSetName string) Process {
72-
return Process{
71+
func newProcess(name, hostName, version, replSetName string, opts ...func(process *Process)) Process {
72+
p := Process{
7373
Name: name,
7474
HostName: hostName,
7575
FeatureCompatibilityVersion: "4.0",
@@ -90,6 +90,12 @@ func newProcess(name, hostName, version, replSetName string) Process {
9090
Replication: Replication{ReplicaSetName: replSetName},
9191
},
9292
}
93+
94+
for _, opt := range opts {
95+
opt(&p)
96+
}
97+
98+
return p
9399
}
94100

95101
type Replication struct {

pkg/automationconfig/automation_config_builder.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Builder struct {
1818
members int
1919
domain string
2020
name string
21+
fcv string
2122
topology Topology
2223
mongodbVersion string
2324

@@ -53,6 +54,11 @@ func (b *Builder) SetName(name string) *Builder {
5354
return b
5455
}
5556

57+
func (b *Builder) SetFCV(fcv string) *Builder {
58+
b.fcv = fcv
59+
return b
60+
}
61+
5662
func (b *Builder) AddVersion(version MongoDbVersionConfig) *Builder {
5763
for idx, _ := range version.Builds {
5864
if version.Builds[idx].Modules == nil {
@@ -82,7 +88,7 @@ func (b *Builder) Build() AutomationConfig {
8288
members := make([]ReplicaSetMember, b.members)
8389
processes := make([]Process, b.members)
8490
for i, h := range hostnames {
85-
process := newProcess(toHostName(b.name, i), h, b.mongodbVersion, b.name)
91+
process := newProcess(toHostName(b.name, i), h, b.mongodbVersion, b.name, withFCV(b.fcv))
8692
processes[i] = process
8793
members[i] = newReplicaSetMember(process, i)
8894
}
@@ -106,3 +112,10 @@ func (b *Builder) Build() AutomationConfig {
106112
func toHostName(name string, index int) string {
107113
return fmt.Sprintf("%s-%d", name, index)
108114
}
115+
116+
// Process functional options
117+
func withFCV(fcv string) func(*Process) {
118+
return func(process *Process) {
119+
process.FeatureCompatibilityVersion = fcv
120+
}
121+
}

pkg/automationconfig/automation_config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestBuildAutomationConfig(t *testing.T) {
3232
SetMongoDBVersion("4.2.0").
3333
SetAutomationConfigVersion(1).
3434
SetMembers(3).
35+
SetFCV("4.0").
3536
Build()
3637

3738
assert.Len(t, ac.Processes, 3)
@@ -44,6 +45,7 @@ func TestBuildAutomationConfig(t *testing.T) {
4445
assert.Equal(t, "my-rs", p.Args26.Replication.ReplicaSetName, "replication should be configured based on the replica set name provided")
4546
assert.Equal(t, toHostName("my-rs", i), p.Name)
4647
assert.Equal(t, "4.2.0", p.Version)
48+
assert.Equal(t, "4.0", p.FeatureCompatibilityVersion)
4749
}
4850

4951
assert.Len(t, ac.ReplicaSets, 1)

pkg/controller/mongodb/mongodb_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func buildAutomationConfig(mdb mdbv1.MongoDB, mdbVersionConfig automationconfig.
157157
SetMembers(mdb.Spec.Members).
158158
SetMongoDBVersion(mdb.Spec.Version).
159159
SetAutomationConfigVersion(1). // TODO: Correctly set the version
160+
SetFCV(mdb.GetFCV()).
160161
AddVersion(mdbVersionConfig).
161162
Build()
162163
}

test/e2e/e2eutil.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ func NewTestMongoDB() mdbv1.MongoDB {
9797
Namespace: f.Global.Namespace,
9898
},
9999
Spec: mdbv1.MongoDBSpec{
100-
Members: 3,
101-
Type: "ReplicaSet",
102-
Version: "4.0.6",
100+
Members: 3,
101+
Type: "ReplicaSet",
102+
Version: "4.0.6",
103+
FeatureCompatibilityVersion: "4.0",
103104
},
104105
}
105106
}

0 commit comments

Comments
 (0)