Skip to content

Commit f41867e

Browse files
EVEREST-1711 Add DB creating state (#653) (#659)
1 parent e0753cf commit f41867e

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

api/v1alpha1/databasecluster_types.go

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var (
3333
const (
3434
// AppStateUnknown is an unknown state.
3535
AppStateUnknown AppState = "unknown"
36+
// AppStateCreating is used when the db did not start to initialize yet.
37+
AppStateCreating AppState = "creating"
3638
// AppStateInit is a initializing state.
3739
AppStateInit AppState = "initializing"
3840
// AppStatePaused is a paused state.
@@ -101,6 +103,18 @@ const (
101103
EngineSizeLarge EngineSize = "large"
102104
)
103105

106+
// WithCreatingState transforms empty and unknown states to a single AppStateCreating.
107+
// The upstream operators have the different statuses when a cluster is being created -
108+
// pxc - "unknown", psmdb - "", pg does not have any empty status.
109+
// Everest maps the DB status 1:1, and there is no point so far to create a separate mapping
110+
// for each upstream operator separately only because we want to unify AppStateCreating.
111+
func (s AppState) WithCreatingState() AppState {
112+
if s == AppStateUnknown || s == AppStateNew {
113+
return AppStateCreating
114+
}
115+
return s
116+
}
117+
104118
// Applier provides methods for specifying how to apply a DatabaseCluster CR
105119
// onto the CR(s) provided by the underlying DB operators (e.g. PerconaXtraDBCluster, PerconaServerMongoDB, PerconaPGCluster, etc.)
106120
//

internal/controller/providers/pg/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (p *Provider) Status(ctx context.Context) (everestv1alpha1.DatabaseClusterS
9494
pg := p.PerconaPGCluster
9595

9696
status := p.DB.Status
97-
status.Status = everestv1alpha1.AppState(pg.Status.State)
97+
status.Status = everestv1alpha1.AppState(pg.Status.State).WithCreatingState()
9898
status.Hostname = pg.Status.Host
9999
status.Ready = pg.Status.Postgres.Ready + pg.Status.PGBouncer.Ready
100100
status.Size = pg.Status.Postgres.Size + pg.Status.PGBouncer.Size

internal/controller/providers/psmdb/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (p *Provider) Status(ctx context.Context) (everestv1alpha1.DatabaseClusterS
117117
psmdb := p.PerconaServerMongoDB
118118

119119
activeStorage := getActiveStorage(psmdb)
120-
status.Status = everestv1alpha1.AppState(psmdb.Status.State)
120+
status.Status = everestv1alpha1.AppState(psmdb.Status.State).WithCreatingState()
121121
status.Hostname = psmdb.Status.Host
122122
status.Ready = psmdb.Status.Ready
123123
status.Size = psmdb.Status.Size

internal/controller/providers/pxc/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (p *Provider) Status(ctx context.Context) (everestv1alpha1.DatabaseClusterS
199199
status := p.DB.Status
200200
pxc := p.PerconaXtraDBCluster
201201

202-
status.Status = everestv1alpha1.AppState(p.PerconaXtraDBCluster.Status.Status)
202+
status.Status = everestv1alpha1.AppState(p.PerconaXtraDBCluster.Status.Status).WithCreatingState()
203203
status.Hostname = pxc.Status.Host
204204
status.Ready = pxc.Status.Ready
205205
status.Size = pxc.Status.Size

0 commit comments

Comments
 (0)