Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
276c030
added scaling fix for MongoDB 4.4
chatton Sep 7, 2020
b9bdad0
wip
chatton Sep 7, 2020
595b45e
Added new statuses and unit tests
chatton Sep 7, 2020
1173c31
moved into main controller package
chatton Sep 7, 2020
b915732
implemented scaling for replica sets
chatton Sep 7, 2020
017f6e4
merge master
chatton Sep 9, 2020
3cc7e22
Fix 4.4 scaling by scaling one member at a time
chatton Sep 9, 2020
50e55e5
reverted unintentional changes
chatton Sep 9, 2020
5a6137d
immediate requeue if still scaling
chatton Sep 9, 2020
a9a606b
updated scaling test to use mongodb 4.4
chatton Sep 9, 2020
6469e8c
removed duplicate log line
chatton Sep 9, 2020
c141d78
wip
chatton Sep 10, 2020
3fbe0bd
renamed to replicas
chatton Sep 10, 2020
b29d4d3
scale down working using new readiness probe
chatton Sep 10, 2020
71d7f4b
increased test timeout
chatton Sep 11, 2020
531394e
updated scaling test with correct automation config versions
chatton Sep 11, 2020
d74ce96
merged master
chatton Sep 11, 2020
cc4033c
wip
chatton Sep 11, 2020
7fefc74
configure operator to use headless mode configuration for readiness p…
chatton Sep 11, 2020
b474a1d
updated agent dockerfile
chatton Sep 11, 2020
741f9c8
updated agent dockerfile
chatton Sep 11, 2020
bc22e44
added publishNotReadyAddresses to service
chatton Sep 11, 2020
c63f8da
publish not ready addresses
chatton Sep 11, 2020
9fb4105
bumped failure threshold to 30
chatton Sep 11, 2020
13ab601
updated python scripts to use correct namespace
chatton Sep 14, 2020
f970435
Merge branch 'master' into use_headloess_mode_readiness_probe
chatton Sep 15, 2020
a8ca532
fixed ready replicas
chatton Sep 15, 2020
76aeef6
fixed unit tests
chatton Sep 15, 2020
fadd770
set replicas back to spec.Members
chatton Sep 15, 2020
b8fc319
Merge branch 'use_headloess_mode_readiness_probe' into CLOUDP-69096_f…
chatton Sep 15, 2020
be838db
typos
chatton Sep 15, 2020
eaceb22
fix unit tests
chatton Sep 15, 2020
0055b25
wip
chatton Sep 15, 2020
3cee13a
split members status field into 2 different fields, update status dur…
chatton Sep 16, 2020
8990f71
merge master
chatton Sep 16, 2020
31f74a0
added CRD updates
chatton Sep 16, 2020
62e6693
test with readienss probe failure threshold set to high number
chatton Sep 17, 2020
13b0031
increase timeouts for scale down drastically
chatton Sep 17, 2020
8252180
tweak readiness probe values, added test just for scale down
chatton Sep 18, 2020
ae19bde
increase timeout for e2e test
chatton Sep 18, 2020
935e9f9
wip
chatton Sep 18, 2020
c36a4a0
set failureThreshold to 60
chatton Sep 18, 2020
95c7c1a
wip
chatton Sep 18, 2020
969b2ba
Added unit tests and cleaned up code
chatton Sep 21, 2020
e5b1ad2
removed dead code
chatton Sep 21, 2020
a9b892c
updated readiness failure threshold
chatton Sep 21, 2020
6b04176
udpated after PR feedback
chatton Sep 24, 2020
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
8 changes: 8 additions & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ task_groups:
- e2e_test_replica_set
- e2e_test_replica_set_readiness_probe
- e2e_test_replica_set_scale
- e2e_test_replica_set_scale_down
- e2e_test_replica_set_change_version
- e2e_test_feature_compatibility_version
- e2e_test_feature_compatibility_version_upgrade
Expand Down Expand Up @@ -279,6 +280,13 @@ tasks:
vars:
test: replica_set_scale

- name: e2e_test_replica_set_scale_down
exec_timeout_secs: 3600
commands:
- func: run_e2e_test
vars:
test: replica_set_scale_down

- name: e2e_test_replica_set_change_version
commands:
- func: run_e2e_test
Expand Down
4 changes: 2 additions & 2 deletions agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ RUN mkdir -p agent \
&& chmod -R +r /var/lib/automation/config \
&& rm agent/mongodb-agent.tar.gz \
&& rm -r mongodb-mms-automation-agent-*

RUN mkdir -p /var/lib/mongodb-mms-automation/probes/ \
&& curl --retry 3 https://readinessprobe.s3-us-west-1.amazonaws.com/readiness -o /var/lib/mongodb-mms-automation/probes/readinessprobe \
# && curl --retry 3 https://readinessprobe.s3-us-west-1.amazonaws.com/readiness -o /var/lib/mongodb-mms-automation/probes/readinessprobe \
&& curl --retry 3 https://readiness-probe-scale-test.s3.amazonaws.com/readiness -o /var/lib/mongodb-mms-automation/probes/readinessprobe \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update this again once I've moved the readiness probe to the correct bucket

&& chmod +x /var/lib/mongodb-mms-automation/probes/readinessprobe \
&& mkdir -p /var/log/mongodb-mms-automation/ \
&& chmod -R +wr /var/log/mongodb-mms-automation/ \
Expand Down
3 changes: 2 additions & 1 deletion cmd/testrunner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ func withTest(test string) func(obj runtime.Object) {
"--kubeconfig",
"/etc/config/kubeconfig",
"--go-test-flags",
"-timeout=20m",
// TODO: allow this to be configurable per test, this is only large due to scale down test
"-timeout=60m",
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions deploy/crds/mongodb.com_mongodb_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,16 @@ spec:
status:
description: MongoDBStatus defines the observed state of MongoDB
properties:
members:
currentStatefulSetReplicas:
type: integer
currentMongoDBMembers:
type: integer
message:
type: string
mongoUri:
type: string
phase:
type: string
required:
- members
- mongoUri
- phase
type: object
type: object
version: v1
Expand Down
3 changes: 2 additions & 1 deletion deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ spec:
- name: OPERATOR_NAME
value: "mongodb-kubernetes-operator"
- name: AGENT_IMAGE # The MongoDB Agent the operator will deploy to manage MongoDB deployments
value: quay.io/mongodb/mongodb-agent:10.19.0.6562-1
value: quay.io/mongodb/mongodb-agent-dev:scaledown
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this image is the same as the previous one, but just with a new readiness probe, I will create a separate PR once this is no longer a dev image.

# value: quay.io/mongodb/mongodb-agent:10.19.0.6562-1
- name: VERSION_UPGRADE_HOOK_IMAGE
value: quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.2
- name: MONGODB_IMAGE
Expand Down
48 changes: 36 additions & 12 deletions pkg/apis/mongodb/v1/mongodb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ type AuthMode string
type MongoDBStatus struct {
MongoURI string `json:"mongoUri"`
Phase Phase `json:"phase"`
Members int `json:"members"`
Message string `json:"message,omitempty"`

CurrentStatefulSetReplicas int `json:"currentStatefulSetReplicas"`
CurrentMongoDBMembers int `json:"currentMongoDBMembers"`

Message string `json:"message,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -220,16 +223,13 @@ type MongoDB struct {
Status MongoDBStatus `json:"status,omitempty"`
}

func (m MongoDB) DesiredReplicas() int {
return m.Spec.Members
}

func (m MongoDB) CurrentReplicas() int {
return m.Status.Members
}

func (m *MongoDB) ReplicasThisReconciliation() int {
return scale.ReplicasThisReconciliation(m)
func (m MongoDB) AutomationConfigMembersThisReconciliation() int {
// determine the correct number of automation config replica set members
// based on our desired number, and our current number
return scale.ReplicasThisReconciliation(automationConfigReplicasScaler{
desired: m.Spec.Members,
current: m.Status.CurrentMongoDBMembers,
})
}

// MongoURI returns a mongo uri which can be used to connect to this deployment
Expand Down Expand Up @@ -298,6 +298,30 @@ func (m MongoDB) GetFCV() string {
return strings.Join(parts[:minorIndex+1], ".")
}

func (m MongoDB) DesiredReplicas() int {
return m.Spec.Members
}

func (m MongoDB) CurrentReplicas() int {
return m.Status.CurrentStatefulSetReplicas
}

func (m *MongoDB) StatefulSetReplicasThisReconciliation() int {
return scale.ReplicasThisReconciliation(m)
}

type automationConfigReplicasScaler struct {
current, desired int
}

func (a automationConfigReplicasScaler) DesiredReplicas() int {
return a.desired
}

func (a automationConfigReplicasScaler) CurrentReplicas() int {
return a.current
}
Comment on lines +301 to +323
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-use existing interface to allow us to get the correct number of automation config members each reconciliation (we will get all of them on first creation, otherwise we scale up/down one at a time)


// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// MongoDBList contains a list of MongoDB
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/mongodb/build_statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func assertStatefulSetIsBuiltCorrectly(t *testing.T, mdb mdbv1.MongoDB, sts *app
assert.Equal(t, "agent-image", agentContainer.Image)
probe := agentContainer.ReadinessProbe
assert.True(t, reflect.DeepEqual(probes.New(defaultReadiness()), *probe))
assert.Equal(t, int32(240), probe.FailureThreshold)
assert.Equal(t, probes.New(defaultReadiness()).FailureThreshold, probe.FailureThreshold)
assert.Equal(t, int32(5), probe.InitialDelaySeconds)
assert.Len(t, agentContainer.VolumeMounts, 4)

Expand Down
83 changes: 45 additions & 38 deletions pkg/controller/mongodb/mongodb_status_options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package mongodb

import (
"time"

mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/pkg/apis/mongodb/v1"
"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/result"
"go.uber.org/zap"

"github.com/mongodb/mongodb-kubernetes-operator/pkg/util/status"
Expand All @@ -16,6 +15,7 @@ type severity string

const (
Info severity = "INFO"
Debug severity = "DEBUG"
Warn severity = "WARN"
Error severity = "ERROR"
None severity = "NONE"
Expand Down Expand Up @@ -56,28 +56,9 @@ func (m mongoUriOption) ApplyOption(mdb *mdbv1.MongoDB) {
}

func (m mongoUriOption) GetResult() (reconcile.Result, error) {
return okResult()
return result.OK()
}

func (o *optionBuilder) withMembers(members int) *optionBuilder {
o.options = append(o.options,
membersOption{
members: members,
})
return o
}

type membersOption struct {
members int
}

func (m membersOption) ApplyOption(mdb *mdbv1.MongoDB) {
mdb.Status.Members = m.members
}

func (m membersOption) GetResult() (reconcile.Result, error) {
return okResult()
}
func (o *optionBuilder) withPhase(phase mdbv1.Phase, retryAfter int) *optionBuilder {
o.options = append(o.options,
phaseOption{
Expand All @@ -99,18 +80,35 @@ type messageOption struct {
func (m messageOption) ApplyOption(mdb *mdbv1.MongoDB) {
mdb.Status.Message = m.message.messageString
if m.message.severityLevel == Error {
zap.S().Error(m.message)
zap.S().Error(m.message.messageString)
}
if m.message.severityLevel == Warn {
zap.S().Warn(m.message)
zap.S().Warn(m.message.messageString)
}
if m.message.severityLevel == Info {
zap.S().Info(m.message)
zap.S().Info(m.message.messageString)
}
if m.message.severityLevel == Debug {
zap.S().Debug(m.message.messageString)
}
}

func (m messageOption) GetResult() (reconcile.Result, error) {
return okResult()
return result.OK()
}

func (o *optionBuilder) withMongoDBMembers(members int) *optionBuilder {
o.options = append(o.options, mongoDBReplicasOption{
mongoDBMembers: members,
})
return o
}

func (o *optionBuilder) withStatefulSetReplicas(members int) *optionBuilder {
o.options = append(o.options, statefulSetReplicasOption{
replicas: members,
})
return o
}

func (o *optionBuilder) withMessage(severityLevel severity, msg string) *optionBuilder {
Expand Down Expand Up @@ -146,28 +144,37 @@ func (p phaseOption) ApplyOption(mdb *mdbv1.MongoDB) {

func (p phaseOption) GetResult() (reconcile.Result, error) {
if p.phase == mdbv1.Running {
return okResult()
return result.OK()
}
if p.phase == mdbv1.Pending {
return retryResult(p.retryAfter)
return result.Retry(p.retryAfter)
}
if p.phase == mdbv1.Failed {
return failedResult()
return result.Failed()
}
return okResult()
return result.OK()
}

type mongoDBReplicasOption struct {
mongoDBMembers int
}

// helper functions which return reconciliation results which should be
// returned from the main reconciliation loop
func (a mongoDBReplicasOption) ApplyOption(mdb *mdbv1.MongoDB) {
mdb.Status.CurrentMongoDBMembers = a.mongoDBMembers
}

func (a mongoDBReplicasOption) GetResult() (reconcile.Result, error) {
return result.OK()
}

func okResult() (reconcile.Result, error) {
return reconcile.Result{}, nil
type statefulSetReplicasOption struct {
replicas int
}

func retryResult(after int) (reconcile.Result, error) {
return reconcile.Result{Requeue: true, RequeueAfter: time.Second * time.Duration(after)}, nil
func (s statefulSetReplicasOption) ApplyOption(mdb *mdbv1.MongoDB) {
mdb.Status.CurrentStatefulSetReplicas = s.replicas
}

func failedResult() (reconcile.Result, error) {
return retryResult(0)
func (s statefulSetReplicasOption) GetResult() (reconcile.Result, error) {
return result.OK()
}
13 changes: 0 additions & 13 deletions pkg/controller/mongodb/mongodb_status_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ func TestMongoUriOption_ApplyOption(t *testing.T) {
assert.Equal(t, "my-uri", mdb.Status.MongoURI, "Status should be updated")
}

func TestMembersOption_ApplyOption(t *testing.T) {
mdb := newReplicaSet(3, "my-rs", "my-ns")

opt := membersOption{
members: 5,
}

opt.ApplyOption(&mdb)

assert.Equal(t, 3, mdb.Spec.Members, "Spec should remain unchanged")
assert.Equal(t, 5, mdb.Status.Members, "Status should be updated")
}

func TestOptionBuilder_RunningPhase(t *testing.T) {
mdb := newReplicaSet(3, "my-rs", "my-ns")

Expand Down
Loading