11package mongodb
22
33import (
4- "time"
5-
64 mdbv1 "github.com/mongodb/mongodb-kubernetes-operator/pkg/apis/mongodb/v1"
5+ "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/result"
76 "go.uber.org/zap"
87
98 "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/status"
@@ -16,6 +15,7 @@ type severity string
1615
1716const (
1817 Info severity = "INFO"
18+ Debug severity = "DEBUG"
1919 Warn severity = "WARN"
2020 Error severity = "ERROR"
2121 None severity = "NONE"
@@ -56,28 +56,9 @@ func (m mongoUriOption) ApplyOption(mdb *mdbv1.MongoDB) {
5656}
5757
5858func (m mongoUriOption ) GetResult () (reconcile.Result , error ) {
59- return okResult ()
59+ return result . OK ()
6060}
6161
62- func (o * optionBuilder ) withMembers (members int ) * optionBuilder {
63- o .options = append (o .options ,
64- membersOption {
65- members : members ,
66- })
67- return o
68- }
69-
70- type membersOption struct {
71- members int
72- }
73-
74- func (m membersOption ) ApplyOption (mdb * mdbv1.MongoDB ) {
75- mdb .Status .Members = m .members
76- }
77-
78- func (m membersOption ) GetResult () (reconcile.Result , error ) {
79- return okResult ()
80- }
8162func (o * optionBuilder ) withPhase (phase mdbv1.Phase , retryAfter int ) * optionBuilder {
8263 o .options = append (o .options ,
8364 phaseOption {
@@ -99,18 +80,35 @@ type messageOption struct {
9980func (m messageOption ) ApplyOption (mdb * mdbv1.MongoDB ) {
10081 mdb .Status .Message = m .message .messageString
10182 if m .message .severityLevel == Error {
102- zap .S ().Error (m .message )
83+ zap .S ().Error (m .message . messageString )
10384 }
10485 if m .message .severityLevel == Warn {
105- zap .S ().Warn (m .message )
86+ zap .S ().Warn (m .message . messageString )
10687 }
10788 if m .message .severityLevel == Info {
108- zap .S ().Info (m .message )
89+ zap .S ().Info (m .message .messageString )
90+ }
91+ if m .message .severityLevel == Debug {
92+ zap .S ().Debug (m .message .messageString )
10993 }
11094}
11195
11296func (m messageOption ) GetResult () (reconcile.Result , error ) {
113- return okResult ()
97+ return result .OK ()
98+ }
99+
100+ func (o * optionBuilder ) withMongoDBMembers (members int ) * optionBuilder {
101+ o .options = append (o .options , mongoDBReplicasOption {
102+ mongoDBMembers : members ,
103+ })
104+ return o
105+ }
106+
107+ func (o * optionBuilder ) withStatefulSetReplicas (members int ) * optionBuilder {
108+ o .options = append (o .options , statefulSetReplicasOption {
109+ replicas : members ,
110+ })
111+ return o
114112}
115113
116114func (o * optionBuilder ) withMessage (severityLevel severity , msg string ) * optionBuilder {
@@ -146,28 +144,37 @@ func (p phaseOption) ApplyOption(mdb *mdbv1.MongoDB) {
146144
147145func (p phaseOption ) GetResult () (reconcile.Result , error ) {
148146 if p .phase == mdbv1 .Running {
149- return okResult ()
147+ return result . OK ()
150148 }
151149 if p .phase == mdbv1 .Pending {
152- return retryResult (p .retryAfter )
150+ return result . Retry (p .retryAfter )
153151 }
154152 if p .phase == mdbv1 .Failed {
155- return failedResult ()
153+ return result . Failed ()
156154 }
157- return okResult ()
155+ return result .OK ()
156+ }
157+
158+ type mongoDBReplicasOption struct {
159+ mongoDBMembers int
158160}
159161
160- // helper functions which return reconciliation results which should be
161- // returned from the main reconciliation loop
162+ func (a mongoDBReplicasOption ) ApplyOption (mdb * mdbv1.MongoDB ) {
163+ mdb .Status .CurrentMongoDBMembers = a .mongoDBMembers
164+ }
165+
166+ func (a mongoDBReplicasOption ) GetResult () (reconcile.Result , error ) {
167+ return result .OK ()
168+ }
162169
163- func okResult () (reconcile. Result , error ) {
164- return reconcile. Result {}, nil
170+ type statefulSetReplicasOption struct {
171+ replicas int
165172}
166173
167- func retryResult ( after int ) (reconcile. Result , error ) {
168- return reconcile. Result { Requeue : true , RequeueAfter : time . Second * time . Duration ( after )}, nil
174+ func ( s statefulSetReplicasOption ) ApplyOption ( mdb * mdbv1. MongoDB ) {
175+ mdb . Status . CurrentStatefulSetReplicas = s . replicas
169176}
170177
171- func failedResult () (reconcile.Result , error ) {
172- return retryResult ( 0 )
178+ func ( s statefulSetReplicasOption ) GetResult () (reconcile.Result , error ) {
179+ return result . OK ( )
173180}
0 commit comments