-
Notifications
You must be signed in to change notification settings - Fork 151
K8SPSMDB-1219: Fix upgrade to v1.20.0 if multiple storages are defined #1910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
"github.com/pkg/errors" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore" | ||
"k8s.io/apimachinery/pkg/types" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
"github.com/percona/percona-backup-mongodb/pbm/config" | ||
|
@@ -188,6 +189,56 @@ func isResyncNeeded(currentCfg *config.Config, newCfg *config.Config) bool { | |
return false | ||
} | ||
|
||
func (r *ReconcilePerconaServerMongoDB) reconcilePiTRStorageLegacy( | ||
ctx context.Context, | ||
pbm backup.PBM, | ||
cr *psmdbv1.PerconaServerMongoDB, | ||
) error { | ||
log := logf.FromContext(ctx) | ||
|
||
if len(cr.Spec.Backup.Storages) != 1 { | ||
log.Info("Expected exactly one storage for PiTR in legacy version", "configured", len(cr.Spec.Backup.Storages)) | ||
return nil | ||
} | ||
|
||
// if PiTR is enabled user can configure only one storage | ||
var storage psmdbv1.BackupStorageSpec | ||
for name, stg := range cr.Spec.Backup.Storages { | ||
storage = stg | ||
log.Info("Configuring PBM with storage", "storage", name) | ||
break | ||
} | ||
|
||
var secretName string | ||
switch storage.Type { | ||
case psmdbv1.BackupStorageS3: | ||
secretName = storage.S3.CredentialsSecret | ||
case psmdbv1.BackupStorageAzure: | ||
secretName = storage.Azure.CredentialsSecret | ||
} | ||
|
||
if secretName != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can push this validation inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but in this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general |
||
exists, err := secretExists(ctx, r.client, types.NamespacedName{Name: secretName, Namespace: cr.Namespace}) | ||
if err != nil { | ||
return errors.Wrap(err, "check storage credentials secret") | ||
} | ||
|
||
if !exists { | ||
log.Error(nil, "Storage credentials secret does not exist", "secret", secretName) | ||
return nil | ||
} | ||
} | ||
|
||
err := pbm.GetNSetConfigLegacy(ctx, r.client, cr, storage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still wondering why this function is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah the reason is it generates the PBM config according to values in cr.yaml and sets it |
||
if err != nil { | ||
return errors.Wrap(err, "set PBM config") | ||
} | ||
|
||
log.Info("Configured PBM storage") | ||
|
||
return nil | ||
} | ||
|
||
func (r *ReconcilePerconaServerMongoDB) reconcilePiTRConfig(ctx context.Context, cr *psmdbv1.PerconaServerMongoDB) error { | ||
log := logf.FromContext(ctx) | ||
|
||
|
@@ -209,10 +260,17 @@ func (r *ReconcilePerconaServerMongoDB) reconcilePiTRConfig(ctx context.Context, | |
return nil | ||
} | ||
|
||
stgName, _, err := cr.Spec.Backup.MainStorage() | ||
if err != nil { | ||
// no storage found | ||
return nil | ||
var stgName string | ||
for name := range cr.Spec.Backup.Storages { | ||
stgName = name | ||
break | ||
} | ||
if cr.CompareVersion("1.20.0") >= 0 { | ||
stgName, _, err = cr.Spec.Backup.MainStorage() | ||
if err != nil { | ||
// no storage found | ||
return nil | ||
} | ||
} | ||
|
||
if cr.Spec.Backup.PITR.Enabled && !cr.Spec.Backup.PITR.OplogOnly { | ||
|
@@ -236,6 +294,15 @@ func (r *ReconcilePerconaServerMongoDB) reconcilePiTRConfig(ctx context.Context, | |
defer pbm.Close(ctx) | ||
|
||
if err := enablePiTRIfNeeded(ctx, pbm, cr); err != nil { | ||
if backup.IsErrNoDocuments(err) { | ||
if cr.CompareVersion("1.20.0") < 0 { | ||
if err := r.reconcilePiTRStorageLegacy(ctx, pbm, cr); err != nil { | ||
return errors.Wrap(err, "reconcile pitr storage") | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
return errors.Wrap(err, "enable pitr if needed") | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here we want to say
storage
instead ofbucket
. Maybe we can use the following version of the log with a little different meaning:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a very old log and it'll be removed soon, i am not sure if we should change it