Skip to content
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

reconciling mongo service if it exists regardless of DBType #626

Merged
merged 1 commit into from May 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 46 additions & 24 deletions pkg/system/phase2_creating.go
Expand Up @@ -103,22 +103,34 @@ func (r *Reconciler) ReconcilePhaseCreatingForMainClusters() error {
if err := r.ReconcileDB(); err != nil {
return err
}
if err := r.ReconcileObject(r.ServiceDb, r.SetDesiredServiceDB); err != nil {
return err

if r.NooBaa.Spec.DBType == "postgres" {
if err := r.ReconcileObject(r.ServiceDbPg, r.SetDesiredServiceDBForPostgres); err != nil {
return err
}
// fix for https://bugzilla.redhat.com/show_bug.cgi?id=1955328
// if DBType=postgres was passed in version 5.6 (OCS 4.6) the operator reconciled
// the mongo service with postgres values. see here:
// https://github.com/noobaa/noobaa-operator/blob/112c510650612b1a6b88582cf41c53b30068161c/pkg/system/phase2_creating.go#L121-L126
// to fix that, reconcile mongo service as well if it exists
if util.KubeCheck(r.ServiceDb) {
r.Logger.Infof("found existing mongo db service [%q] will reconcile", r.ServiceDb.Name)
if err := r.ReconcileObject(r.ServiceDb, r.SetDesiredServiceDBForMongo); err != nil {
r.Logger.Errorf("got error when trying to reconcile mongo service. %v", err)
return err
}
}

} else {
if err := r.ReconcileObject(r.ServiceDb, r.SetDesiredServiceDBForMongo); err != nil {
return err
}
}
}
if err := r.ReconcileObject(r.ServiceMgmt, r.SetDesiredServiceMgmt); err != nil {
return err
}
if r.NooBaa.Spec.DBType == "postgres" {
if err := r.ReconcileObject(r.ServiceDbPg, r.SetDesiredServiceDB); err != nil {
return err
}
} else {
if err := r.ReconcileObject(r.ServiceDb, r.SetDesiredServiceDB); err != nil {
return err
}
}

if r.NooBaa.Spec.DBType == "postgres" {
if err := r.UpgradeMigrateDB(); err != nil {
return err
Expand Down Expand Up @@ -160,19 +172,21 @@ func (r *Reconciler) SetDesiredServiceS3() error {
return nil
}

// SetDesiredServiceDB updates the ServiceS3 as desired for reconciling
func (r *Reconciler) SetDesiredServiceDB() error {
if r.NooBaa.Spec.DBType == "postgres" {
r.ServiceDbPg.Spec.Selector["noobaa-db"] = "postgres"
r.ServiceDbPg.Spec.Ports[0].Name = "postgres"
r.ServiceDbPg.Spec.Ports[0].Port = 5432
r.ServiceDbPg.Spec.Ports[0].TargetPort = intstr.FromInt(5432)
} else {
r.ServiceDb.Spec.Selector["noobaa-db"] = r.Request.Name
r.ServiceDb.Spec.Ports[0].Name = "mongodb"
r.ServiceDb.Spec.Ports[0].Port = 27017
r.ServiceDb.Spec.Ports[0].TargetPort = intstr.FromInt(27017)
}
// SetDesiredServiceDBForMongo updates the mongodb service
func (r *Reconciler) SetDesiredServiceDBForMongo() error {
r.ServiceDb.Spec.Selector["noobaa-db"] = r.Request.Name
r.ServiceDb.Spec.Ports[0].Name = "mongodb"
r.ServiceDb.Spec.Ports[0].Port = 27017
r.ServiceDb.Spec.Ports[0].TargetPort = intstr.FromInt(27017)
return nil
}

// SetDesiredServiceDBForPostgres updates the postgres service
func (r *Reconciler) SetDesiredServiceDBForPostgres() error {
r.ServiceDbPg.Spec.Selector["noobaa-db"] = "postgres"
r.ServiceDbPg.Spec.Ports[0].Name = "postgres"
r.ServiceDbPg.Spec.Ports[0].Port = 5432
r.ServiceDbPg.Spec.Ports[0].TargetPort = intstr.FromInt(5432)
return nil
}

Expand Down Expand Up @@ -989,6 +1003,14 @@ func (r *Reconciler) UpgradeMigrateDB() error {
return fmt.Errorf("mongo is still alive")
}

if util.KubeCheck(r.ServiceDb) {
r.Logger.Infof("UpgradeMigrateDB:: deleting mongodb service")

if err := r.Client.Delete(r.Ctx, r.ServiceDb); err != nil && !errors.IsNotFound(err) {
r.Logger.Errorf("got error on mongo service deletion: %v", err)
return err
}
}
// set endpoints replica count to 1. this should enable HPA back again
if err := r.SetEndpointsDeploymentReplicas(1); err != nil {
r.Logger.Errorf("UpgradeMigrateDB::got error on endpoints deployment reconcile %v", err)
Expand Down