Skip to content

Commit

Permalink
db upgrage: upgrade postgres 15 to postgres 16
Browse files Browse the repository at this point in the history
Signed-off-by: Vinayak Hariharmath <[email protected]>
  • Loading branch information
vec-tr committed Oct 7, 2024
1 parent 6d82940 commit dfbcf15
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions deploy/internal/statefulset-postgres-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ spec:
- name: db
image: NOOBAA_DB_IMAGE
env:
- name: POSTGRESQL_UPGRADE
value: copy
- name: POSTGRESQL_DATABASE
value: nbcore
- name: LC_COLLATE
Expand Down
4 changes: 3 additions & 1 deletion pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5139,7 +5139,7 @@ spec:
resource: limits.memory
`

const Sha256_deploy_internal_statefulset_postgres_db_yaml = "37a6c36928ba426ca04fd89e1eb2685e10d1a5f65c63ebb40c68a4f5c37645de"
const Sha256_deploy_internal_statefulset_postgres_db_yaml = "46460879b565c80900a09017d145e835ca0491a0c9e465ff0c8b9172535843fe"

const File_deploy_internal_statefulset_postgres_db_yaml = `apiVersion: apps/v1
kind: StatefulSet
Expand Down Expand Up @@ -5169,6 +5169,8 @@ spec:
- name: db
image: NOOBAA_DB_IMAGE
env:
- name: POSTGRESQL_UPGRADE
value: copy
- name: POSTGRESQL_DATABASE
value: nbcore
- name: LC_COLLATE
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var NooBaaImage = ContainerImage

// DBImage is the default db image url
// it can be overridden for testing or different registry locations.
var DBImage = "quay.io/sclorg/postgresql-15-c9s"
var DBImage = "quay.io/sclorg/postgresql-16-c9s"

// Psql12Image is the default postgres12 db image url
// currently it can not be overridden.
Expand Down
27 changes: 27 additions & 0 deletions pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ func (r *Reconciler) SetDesiredServiceDBForPostgres() error {
return nil
}

// Check db update status and if already updated, remove the POSTGRES_UPDATE env from STS
func (r *Reconciler) checkAndRemovePGUpgradeEnvFromSTS() {
if r.NooBaa.Status.PostgresUpdatePhase == nbv1.UpgradePhaseFinished {
for i, container := range r.NooBaaPostgresDB.Spec.Template.Spec.Containers {
newEnvVars := []corev1.EnvVar{}
if container.Name == "db" {
for _, env := range container.Env {
if env.Name != "POSTGRESQL_UPGRADE" {
newEnvVars = append(newEnvVars, env)
}
}
r.NooBaaPostgresDB.Spec.Template.Spec.Containers[i].Env = newEnvVars
break
}
}
}
}

// SetDesiredNooBaaDB updates the NooBaaDB as desired for reconciling
func (r *Reconciler) SetDesiredNooBaaDB() error {
var NooBaaDBTemplate *appsv1.StatefulSet = nil
Expand All @@ -239,6 +257,9 @@ func (r *Reconciler) SetDesiredNooBaaDB() error {
NooBaaDB.Spec.ServiceName = r.ServiceDbPg.Name
NooBaaDBTemplate = util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet)

// Check db update status and if already updated, remove the POSTGRES_UPDATE env from STS
r.checkAndRemovePGUpgradeEnvFromSTS()

podSpec := &NooBaaDB.Spec.Template.Spec
podSpec.ServiceAccountName = "noobaa-db"
defaultUID := int64(10001)
Expand Down Expand Up @@ -1133,6 +1154,7 @@ func (r *Reconciler) ReconcileDB() error {

result, reconcilePostgresError := r.reconcileObjectAndGetResult(r.NooBaaPostgresDB, r.SetDesiredNooBaaDB, false)
if reconcilePostgresError != nil {

return reconcilePostgresError
}
if !r.isObjectUpdated(result) && (isDBConfUpdated) {
Expand All @@ -1143,6 +1165,11 @@ func (r *Reconciler) ReconcileDB() error {
}

}

if r.isObjectUpdated(result) {
r.NooBaa.Status.PostgresUpdatePhase = nbv1.UpgradePhaseFinished
}

return nil
}

Expand Down

0 comments on commit dfbcf15

Please sign in to comment.