Skip to content

Commit 526f08e

Browse files
authored
fix(mariadb): restore the dump a Backup was taken as (cozystack#5227)
## What this PR does A RestoreJob that names a MariaDB `Backup` restored the newest dump of the application, not the dump of that `Backup`. The driver created the operator `Restore` with only `backupRef`, and mariadb-operator then restores the dump nearest to the moment the restore starts, from the prefix every run of the app shares. Restoring an older `Backup` brought back the latest data, and when its own dump was already gone it silently restored another one. The `Backup` now records the dump its operator `Backup` wrote, the file name in `k8s.mariadb.com/dump-file` and the timestamp from that name in `k8s.mariadb.com/dump-time`. They come from the ownership-proven match the size probe already makes, and nothing is recorded when ownership is not proven. A restore first checks with a bounded S3 listing of the operator `Backup`'s own storage that the dump still exists, then sets `targetRecoveryTime` on the operator `Restore` to the dump's own timestamp, which mariadb-operator matches exactly. If the dump is gone the RestoreJob fails and names it. If the check cannot be made it waits with `Ready=False/DumpCheckPending` until the restore deadline and then fails with the cause. `Backup`s taken before this stay restorable. The restore makes the same ownership-proven match against their operator `Backup` and pins the dump when it is provable, otherwise it restores the newest dump as before and a `BestEffortDump` warning event on the RestoreJob says so. One case is not covered: the `Backup`'s own dump is gone, a neighbour's dump from within the minute of slack is still there and its operator `Backup` was deleted, so that dump is taken as the match. Nothing in the platform deletes operator `Backup`s, it needs someone to delete one by hand. A `Backup` made of an operator `Backup` whose Job failed (`Complete` with reason `JobFailed`) has no dump, so its RestoreJob now fails instead of restoring another run's dump. Stacked on cozystack#5223 and targets its branch until that merges, only the last three commits belong here. Checked on a test cluster with mariadb-operator 25.10.2. An operator `Restore` of an older `Backup` with `targetRecoveryTime` set to its dump timestamp restored exactly that dump (`obtained target backup` names it and a row inserted after it is absent from the target), the same `Restore` without the target restored the newest one. Against the real bucket and operator `Backup`s the recording probe attributed to each `Backup` the dump its backup pod logged, the existence check passed for those dumps and refused a pruned one, legacy `Backup`s with a provable dump got pinned while back-to-back runs fell back with the warning, and the two failed runs on that cluster were refused. The controller itself was not run on the cluster, only its code driven by a test against the real bucket. Fixes cozystack#5196 ### Screenshots Not a UI change. ### Downstream repositories The diff is confined to the backup controller's Go code. It changes no CRD or API type (`driverMetadata` is an opaque map), no chart, values, package layout or `hack/` script, so no entry of the trigger map applies. - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note fix(mariadb): a RestoreJob now restores the dump of the Backup it names instead of the newest dump of the application. It fails with a clear message when that dump no longer exists in storage, or when the Backup was made of a failed backup run. Backups taken before this release are restored by the one dump that can be matched to them, or else, as before, by the newest dump, with a BestEffortDump warning event on the RestoreJob. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * MariaDB backups now record the selected dump’s filename and timestamp, allowing restores to target the corresponding recovery time. * For older backups without dump metadata, restores use a uniquely matched dump when possible or fall back to the latest dump with a warning. * Restore processing verifies recorded dumps, retries temporary storage checks, and reports failures for invalid or missing recorded dumps. * **Bug Fixes** * Deleting a MariaDB backup now removes its associated dump and operator backup when ownership is verified and no restore is active. Cleanup avoids deleting artifacts when it cannot safely identify them. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 53078a1 + 5d453c4 commit 526f08e

13 files changed

Lines changed: 2717 additions & 83 deletions

‎internal/backupcontroller/artifact_size.go‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ type s3ObjectLister interface {
3939
StatObject(ctx context.Context, bucket, key string) (int64, error)
4040
}
4141

42+
type s3ObjectRemover interface {
43+
// RemoveObject deletes key. S3 answers 204 for a key that does not
44+
// exist and minio-go takes 204 as success; a backend answering a
45+
// missing key with any other status makes it an error.
46+
RemoveObject(ctx context.Context, bucket, key string) error
47+
}
48+
4249
// s3Connection is what a driver resolves from its rendered strategy to
4350
// read the bucket with the same identity the backup was written with.
4451
type s3Connection struct {
@@ -67,8 +74,10 @@ type objectStore struct {
6774
// reader reads Secrets, which the manager's client fetches uncached,
6875
// and lists operator Backups, which it serves from the cache.
6976
reader client.Reader
70-
// newLister overrides the S3 client; nil means a real minio client.
71-
newLister func(conn s3Connection) (s3ObjectLister, error)
77+
// newLister and newRemover override the S3 client; nil means a real
78+
// minio client.
79+
newLister func(conn s3Connection) (s3ObjectLister, error)
80+
newRemover func(conn s3Connection) (s3ObjectRemover, error)
7281
}
7382

7483
func (s objectStore) lister(conn s3Connection) (s3ObjectLister, error) {
@@ -78,6 +87,17 @@ func (s objectStore) lister(conn s3Connection) (s3ObjectLister, error) {
7887
return newMinioObjectLister(conn)
7988
}
8089

90+
func (s objectStore) remover(conn s3Connection) (s3ObjectRemover, error) {
91+
if s.newRemover != nil {
92+
return s.newRemover(conn)
93+
}
94+
c, err := newMinioObjectClient(conn)
95+
if err != nil {
96+
return nil, err
97+
}
98+
return c, nil
99+
}
100+
81101
func (s objectStore) secretValue(ctx context.Context, namespace, name, key string) (string, error) {
82102
secret := &corev1.Secret{}
83103
if err := s.reader.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, secret); err != nil {
@@ -94,6 +114,14 @@ func (r *BackupJobReconciler) objectStore() objectStore {
94114
return objectStore{reader: r.Client, newLister: r.newS3ObjectLister}
95115
}
96116

117+
func (r *RestoreJobReconciler) objectStore() objectStore {
118+
return objectStore{reader: r.Client, newLister: r.newS3ObjectLister}
119+
}
120+
121+
func (r *BackupReconciler) objectStore() objectStore {
122+
return objectStore{reader: r.Client, newLister: r.newS3ObjectLister, newRemover: r.newS3ObjectRemover}
123+
}
124+
97125
func (r *BackupJobReconciler) s3Lister(conn s3Connection) (s3ObjectLister, error) {
98126
return r.objectStore().lister(conn)
99127
}
@@ -103,6 +131,14 @@ type minioObjectLister struct {
103131
}
104132

105133
func newMinioObjectLister(conn s3Connection) (s3ObjectLister, error) {
134+
c, err := newMinioObjectClient(conn)
135+
if err != nil {
136+
return nil, err
137+
}
138+
return c, nil
139+
}
140+
141+
func newMinioObjectClient(conn s3Connection) (*minioObjectLister, error) {
106142
opts := &minio.Options{
107143
Creds: credentials.NewStaticV4(conn.AccessKey, conn.SecretKey, conn.SessionToken),
108144
Region: conn.Region,
@@ -168,6 +204,10 @@ func (l *minioObjectLister) StatObject(ctx context.Context, bucket, key string)
168204
return info.Size, nil
169205
}
170206

207+
func (l *minioObjectLister) RemoveObject(ctx context.Context, bucket, key string) error {
208+
return l.client.RemoveObject(ctx, bucket, key, minio.RemoveObjectOptions{})
209+
}
210+
171211
// collectObjects drains a minio listing. minio-go ends a listing whose
172212
// context is cancelled between pages by closing the channel without an
173213
// error item, so a cancelled context is checked once the channel closes:

‎internal/backupcontroller/backup_controller.go‎

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,22 @@ type BackupReconciler struct {
3939
client.Client
4040
Scheme *runtime.Scheme
4141
Recorder record.EventRecorder
42-
// CredentialsConfig lets the Rabbitmq cleanup path project cozy-backups-creds
43-
// into the Backup's namespace before spawning its best-effort delete Job.
42+
// CredentialsConfig locates the platform backup credentials: the Job-based
43+
// cleanups project them into the Backup's namespace, and the MariaDB
44+
// cleanup reads them to reach the platform bucket.
4445
CredentialsConfig BackupCredentialsConfig
46+
// APIReader is the manager's uncached reader. The MariaDB cleanup lists
47+
// the RestoreJobs and operator Restores of a Backup, and the operator
48+
// Backups that may own its dump, through it: a restore that started
49+
// before the delete, or a run that has already uploaded its dump, may
50+
// not be in the cache yet. Wired in SetupWithManager.
51+
APIReader client.Reader
52+
53+
// newS3ObjectLister and newS3ObjectRemover override the S3 client the
54+
// MariaDB cleanup deletes a dump with; nil means a real minio client.
55+
// Set by unit tests.
56+
newS3ObjectLister func(conn s3Connection) (s3ObjectLister, error)
57+
newS3ObjectRemover func(conn s3Connection) (s3ObjectRemover, error)
4558
}
4659

4760
func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -126,22 +139,20 @@ func (r *BackupReconciler) cleanupOnDelete(ctx context.Context, backup *backupsv
126139
// orchestration" for tenant-facing guidance.
127140
return ctrl.Result{}, nil
128141
case strategyv1alpha1.MariaDBStrategyKind:
129-
// Cozystack Backup deletion does NOT delete the operator-side
130-
// k8s.mariadb.com/Backup CR or the backing S3/PVC archive.
131-
// Lifecycle of that CR is owned by mariadb-operator's
132-
// MaxRetention setting and by tenants / explicit teardown flows;
133-
// the controller's RBAC has no delete verb on
134-
// k8s.mariadb.com/backups for that reason. Surfacing this as an
135-
// explicit branch (rather than falling through to the Velero
136-
// default) keeps the contract honest: the MariaDB driver does
137-
// not own the archive, so it does not delete it on CR removal.
138-
// Mirrors the Altinity branch's "we do not own S3" stance.
139-
return ctrl.Result{}, nil
142+
// mariadb-operator's maxRetention prunes only from inside the next
143+
// backup run of the same prefix and a Plan never deletes a Backup, so
144+
// a dump on the platform bucket is deleted here or never. A dump in
145+
// a tenant's own bucket is deleted too: the Backup proves it owns
146+
// it, and tenants cannot delete Backups, so the delete comes from an
147+
// administrator or from namespace teardown. Teardown can remove the
148+
// operator Backup first, and the dump is then left behind with a
149+
// Warning, since its storage is read from it (see cleanupMariaDBBackup).
150+
return r.cleanupMariaDBBackup(ctx, backup)
140151
case strategyv1alpha1.MongoDBStrategyKind:
141152
// Split by flow (see cleanupMongoDBBackup). A legacy backup writes to the
142153
// tenant's own bucket and its lifecycle stays the tenant's / psmdb
143154
// operator's — that branch is a no-op, the same "we do not own the
144-
// archive" contract as Altinity / MariaDB / FDB. A useSystemBucket backup
155+
// archive" contract as Altinity / FDB. A useSystemBucket backup
145156
// lands in the shared cozy-backups bucket with no psmdb task retention to
146157
// prune it, so the driver OWNS it: this deletes the operator
147158
// PerconaServerMongoDBBackup CR and waits for its delete-backup finalizer
@@ -154,7 +165,7 @@ func (r *BackupReconciler) cleanupOnDelete(ctx context.Context, backup *backupsv
154165
// is governed by the next BackupJob's stopOtherFoundationDBBackups
155166
// call, by manual operator action, or by
156167
// examples/backups/foundationdb/cleanup.sh. Same "we do not own
157-
// the archive" contract as Altinity / MariaDB — the explicit
168+
// the archive" contract as Altinity — the explicit
158169
// branch guards the seam against a future driver refactor that
159170
// might incidentally stamp velero.io/backup-name onto FDB
160171
// driverMetadata via a shared helper.
@@ -294,7 +305,18 @@ func (r *BackupReconciler) cleanupCNPGBackup(ctx context.Context, backup *backup
294305

295306
// SetupWithManager registers the BackupReconciler with the Manager.
296307
func (r *BackupReconciler) SetupWithManager(mgr ctrl.Manager) error {
308+
r.APIReader = mgr.GetAPIReader()
297309
return ctrl.NewControllerManagedBy(mgr).
298310
For(&backupsv1alpha1.Backup{}).
299311
Complete(r)
300312
}
313+
314+
// apiReader returns the uncached reader. Reconcilers built by hand in unit
315+
// tests have none and fall back to their fake Client, which has no cache to
316+
// bypass.
317+
func (r *BackupReconciler) apiReader() client.Reader {
318+
if r.APIReader != nil {
319+
return r.APIReader
320+
}
321+
return r.Client
322+
}

‎internal/backupcontroller/backup_controller_test.go‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,8 @@ func TestBackupCleanup_Altinity_DoesNotFallThroughToVelero(t *testing.T) {
176176

177177
// TestBackupCleanup_MariaDB_DoesNotFallThroughToVelero locks in the same
178178
// invariant as the Altinity test above for the MariaDB strategy. The
179-
// dispatcher must explicitly route MariaDB-strategy Backups to a no-op
180-
// cleanup rather than fall through to the Velero default - the MariaDB
181-
// driver does not own the operator-side k8s.mariadb.com/Backup CR or the
182-
// S3/PVC archive behind it (rbac.yaml grants no delete verb on
183-
// k8s.mariadb.com/backups for that reason). The test seeds the Velero
179+
// dispatcher must route MariaDB-strategy Backups to their own cleanup
180+
// rather than fall through to the Velero default. The test seeds the Velero
184181
// metadata keys plus a matching velero.io/Backup; with the explicit branch
185182
// no DeleteBackupRequest is synthesised, and the Velero Backup survives.
186183
// Without the branch the default falls through to cleanupVeleroBackup,

‎internal/backupcontroller/mariadb_artifact_size.go‎

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ type mariadbDump struct {
3939
LastModified time.Time
4040
}
4141

42-
// mariadbArtifactSizeBytes measures the dump mariadb-operator uploaded for
43-
// mdbBackup. Returns 0 - leaving Artifact.SizeBytes absent - when the dump
44-
// cannot be found or told apart: an unknown size must not be reported as a
45-
// measured one.
46-
func (r *BackupJobReconciler) mariadbArtifactSizeBytes(ctx context.Context, mdbBackup *mariadbtypes.Backup, completedAt time.Time) int64 {
42+
// attributedMariaDBDump returns the dump mariadb-operator uploaded for
43+
// mdbBackup. ok is false when the dump cannot be found or told apart, and
44+
// the Backup then reports neither a size nor a dump: an unknown dump must
45+
// not be reported as a measured one.
46+
func (r *BackupJobReconciler) attributedMariaDBDump(ctx context.Context, mdbBackup *mariadbtypes.Backup, completedAt time.Time) (dump mariadbDump, ok bool) {
4747
ctx, cancel := context.WithTimeout(ctx, artifactSizeProbeTimeout)
4848
defer cancel()
4949
dump, err := findMariaDBDump(ctx, r.objectStore(), mdbBackup, completedAt)
5050
if err != nil {
51-
getLogger(ctx).Info("MariaDB backup size not measured; leaving it unset", "backup", mdbBackup.Name, "error", err)
52-
return 0
51+
getLogger(ctx).Info("MariaDB dump not attributed; leaving its size and name unset", "backup", mdbBackup.Name, "error", err)
52+
return mariadbDump{}, false
5353
}
54-
return dump.Size
54+
return dump, true
5555
}
5656

5757
// findMariaDBDump lists the bucket mdbBackup wrote to and returns the one
@@ -60,22 +60,26 @@ func (r *BackupJobReconciler) mariadbArtifactSizeBytes(ctx context.Context, mdbB
6060
// from can have been edited since, and pointing at another bucket now says
6161
// nothing about where this dump went.
6262
func findMariaDBDump(ctx context.Context, store objectStore, mdbBackup *mariadbtypes.Backup, completedAt time.Time) (mariadbDump, error) {
63+
lister, _, err := mariadbStorage(ctx, store, mdbBackup)
64+
if err != nil {
65+
return mariadbDump{}, err
66+
}
67+
return findMariaDBDumpWith(ctx, lister, store.reader, mdbBackup, completedAt, false)
68+
}
69+
70+
// findMariaDBDumpWith is findMariaDBDump reading the bucket through lister,
71+
// for a caller that reaches the bucket by another endpoint than the one
72+
// mdbBackup names. withUnfinished lets runs that have not completed contest
73+
// the dump too, as neighbourMariaDBRuns describes.
74+
func findMariaDBDumpWith(ctx context.Context, lister s3ObjectLister, reader client.Reader, mdbBackup *mariadbtypes.Backup, completedAt time.Time, withUnfinished bool) (mariadbDump, error) {
6375
s3 := mdbBackup.Spec.Storage.S3
6476
if s3 == nil {
6577
return mariadbDump{}, errors.New("the operator Backup does not store to S3")
6678
}
67-
others, err := finishedMariaDBRuns(ctx, store.reader, mdbBackup)
79+
others, err := neighbourMariaDBRuns(ctx, reader, mdbBackup, withUnfinished)
6880
if err != nil {
6981
return mariadbDump{}, fmt.Errorf("list operator Backups: %w", err)
7082
}
71-
conn, err := mariadbS3Connection(ctx, store, mdbBackup.Namespace, s3)
72-
if err != nil {
73-
return mariadbDump{}, fmt.Errorf("resolve S3 credentials: %w", err)
74-
}
75-
lister, err := store.lister(conn)
76-
if err != nil {
77-
return mariadbDump{}, fmt.Errorf("build S3 client: %w", err)
78-
}
7983
// Non-recursive, as mariadb-operator lists it: the default prefix is also
8084
// the default CNPG destinationPath, so an app of each kind with the same
8185
// name shares it and a recursive listing would walk the WAL archive.
@@ -88,13 +92,55 @@ func findMariaDBDump(ctx context.Context, store objectStore, mdbBackup *mariadbt
8892
return matchMariaDBDump(objects, prefix, own, others)
8993
}
9094

95+
// mariadbDumpExists reports whether the dump file name is still in the
96+
// storage mdbBackup wrote to.
97+
func mariadbDumpExists(ctx context.Context, store objectStore, mdbBackup *mariadbtypes.Backup, name string) (bool, error) {
98+
lister, s3, err := mariadbStorage(ctx, store, mdbBackup)
99+
if err != nil {
100+
return false, err
101+
}
102+
key := mariadbOperatorS3Prefix(s3.Prefix) + name
103+
objects, err := lister.ListObjects(ctx, s3.Bucket, key, false)
104+
if err != nil {
105+
return false, fmt.Errorf("list s3://%s/%s: %w", s3.Bucket, key, err)
106+
}
107+
for _, obj := range objects {
108+
if obj.Key == key {
109+
return true, nil
110+
}
111+
}
112+
return false, nil
113+
}
114+
115+
// mariadbStorage opens the bucket mdbBackup wrote to, with the credentials
116+
// its own spec names.
117+
func mariadbStorage(ctx context.Context, store objectStore, mdbBackup *mariadbtypes.Backup) (s3ObjectLister, *mariadbtypes.S3Storage, error) {
118+
s3 := mdbBackup.Spec.Storage.S3
119+
if s3 == nil {
120+
return nil, nil, errors.New("the operator Backup does not store to S3")
121+
}
122+
conn, err := mariadbS3Connection(ctx, store, mdbBackup.Namespace, s3)
123+
if err != nil {
124+
return nil, nil, fmt.Errorf("resolve S3 credentials: %w", err)
125+
}
126+
lister, err := store.lister(conn)
127+
if err != nil {
128+
return nil, nil, fmt.Errorf("build S3 client: %w", err)
129+
}
130+
return lister, s3, nil
131+
}
132+
91133
// mariadbRun is the span in which an operator Backup can have written its
92134
// dump: its lifetime, widened by mariadbSizeProbeClockSkew on each side.
93135
type mariadbRun struct {
94136
name string
95137
lower, upper time.Time
96138
}
97139

140+
// mariadbUnfinishedRunEnd closes the window of a run that has not completed,
141+
// which can still write its dump at any time.
142+
var mariadbUnfinishedRunEnd = time.Date(9999, time.December, 31, 0, 0, 0, 0, time.UTC)
143+
98144
func newMariaDBRun(b *mariadbtypes.Backup, created, completed time.Time) mariadbRun {
99145
return mariadbRun{
100146
name: b.Namespace + "/" + b.Name,
@@ -120,8 +166,8 @@ func (r mariadbRun) placesOnEitherClock(d mariadbDump) bool {
120166
// dump in the window on one clock only may be this run's own, misplaced by
121167
// a skewed clock, which leaves any other candidate unproven. A neighbour's
122168
// dump is still taken if this run's own is missing from the listing, or
123-
// misplaced on both clocks, and the neighbour's operator Backup is gone or
124-
// has not completed.
169+
// misplaced on both clocks, and the neighbour's operator Backup is gone or,
170+
// unless others includes unfinished runs, has not completed.
125171
func matchMariaDBDump(objects []s3ObjectInfo, prefix string, own mariadbRun, others []mariadbRun) (mariadbDump, error) {
126172
var near []mariadbDump
127173
for _, obj := range objects {
@@ -153,14 +199,17 @@ func matchMariaDBDump(objects []s3ObjectInfo, prefix string, own mariadbRun, oth
153199
return d, nil
154200
}
155201

156-
// finishedMariaDBRuns returns the runs of the other operator Backups that
202+
// neighbourMariaDBRuns returns the runs of the other operator Backups that
157203
// write under the same bucket and prefix as b and have completed, whether
158-
// their Job succeeded or failed. One still running is left out: its window
159-
// has no end yet, and an operator Backup stuck short of Complete, as one
160-
// whose Job pod never starts is, would otherwise contest every later run of
161-
// the application for good. The endpoint is not compared, since one has
162-
// several spellings, and a false neighbour only leaves a size unset.
163-
func finishedMariaDBRuns(ctx context.Context, reader client.Reader, b *mariadbtypes.Backup) ([]mariadbRun, error) {
204+
// their Job succeeded or failed. One still running is left out unless
205+
// withUnfinished is set: its window has no end yet, and an operator Backup
206+
// stuck short of Complete, as one whose Job pod never starts is, would
207+
// otherwise contest every later run of the application for good. That is
208+
// the price of deleting a dump, since a run can upload its dump and prune
209+
// older ones through maxRetention before it completes. The endpoint is not
210+
// compared, since one has several spellings, and a false neighbour only
211+
// keeps a dump unattributed.
212+
func neighbourMariaDBRuns(ctx context.Context, reader client.Reader, b *mariadbtypes.Backup, withUnfinished bool) ([]mariadbRun, error) {
164213
list := &mariadbtypes.BackupList{}
165214
if err := reader.List(ctx, list); err != nil {
166215
return nil, err
@@ -177,6 +226,9 @@ func finishedMariaDBRuns(ctx context.Context, reader client.Reader, b *mariadbty
177226
}
178227
cond := apimeta.FindStatusCondition(other.Status.Conditions, mariadbtypes.ConditionTypeComplete)
179228
if cond == nil || cond.Status != metav1.ConditionTrue {
229+
if withUnfinished {
230+
runs = append(runs, newMariaDBRun(other, other.CreationTimestamp.Time, mariadbUnfinishedRunEnd))
231+
}
180232
continue
181233
}
182234
runs = append(runs, newMariaDBRun(other, other.CreationTimestamp.Time, cond.LastTransitionTime.Time))

0 commit comments

Comments
 (0)