Skip to content

Commit e5bedcd

Browse files
Added a workaround for postgres upgrade failures (#1396) (#1398)
If Postgres is not upgraded to postgres-15 and is still using postgres-12 image, continue to use postgres12 image, but set the noobaa CR as rejected. This is to prevent noobaa-db going into CLBO Signed-off-by: Danny Zaken <dannyzaken@gmail.com> (cherry picked from commit 992d39b) Co-authored-by: Danny Zaken <dannyzaken@gmail.com>
1 parent c9b7fdb commit e5bedcd

File tree

7 files changed

+52
-10
lines changed

7 files changed

+52
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ gen-olm: gen
156156

157157
gen-odf-package: cli
158158
rm -rf $(MANIFESTS)
159-
MANIFESTS="$(MANIFESTS)" CSV_NAME="$(csv-name)" SKIP_RANGE="$(skip-range)" REPLACES="$(replaces)" CORE_IMAGE="$(core-image)" DB_IMAGE="$(db-image)" OPERATOR_IMAGE="$(operator-image)" COSI_SIDECAR_IMAGE="$(cosi-sidecar-image)" OBC_CRD="$(obc-crd)" build/gen-odf-package.sh
159+
MANIFESTS="$(MANIFESTS)" CSV_NAME="$(csv-name)" SKIP_RANGE="$(skip-range)" REPLACES="$(replaces)" CORE_IMAGE="$(core-image)" DB_IMAGE="$(db-image)" OPERATOR_IMAGE="$(operator-image)" COSI_SIDECAR_IMAGE="$(cosi-sidecar-image)" OBC_CRD="$(obc-crd)" PSQL_12_IMAGE="$(psql-12-image)" build/gen-odf-package.sh
160160
@echo "✅ gen-odf-package"
161161
.PHONY: gen-odf-package
162162

build/gen-odf-package.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
if [ "${MANIFESTS}" == "" ] || [ "${CSV_NAME}" == "" ] || [ "${CORE_IMAGE}" == "" ] || [ "${DB_IMAGE}" == "" ] || [ "${OPERATOR_IMAGE}" == "" ] || [ "${COSI_SIDECAR_IMAGE}" == "" ]
3+
if [ "${MANIFESTS}" == "" ] || [ "${CSV_NAME}" == "" ] || [ "${CORE_IMAGE}" == "" ] || [ "${PSQL_12_IMAGE}" == "" ] || [ "${DB_IMAGE}" == "" ] || [ "${OPERATOR_IMAGE}" == "" ] || [ "${COSI_SIDECAR_IMAGE}" == "" ]
44
then
55
echo "gen-odf-package.sh: not all required envs were supplied"
66
exit 1
@@ -16,6 +16,7 @@ echo "--obc-crd=${OBC_CRD}"
1616
--replaces "${REPLACES}" \
1717
--noobaa-image ${CORE_IMAGE} \
1818
--db-image ${DB_IMAGE} \
19+
--psql-12-image ${PSQL_12_IMAGE} \
1920
--operator-image ${OPERATOR_IMAGE} \
2021
--cosi-sidecar-image ${COSI_SIDECAR_IMAGE} \
2122
--obc-crd=${OBC_CRD}
@@ -34,6 +35,8 @@ cat >> ${temp_csv} << EOF
3435
name: noobaa-core
3536
- image: ${DB_IMAGE}
3637
name: noobaa-db
38+
- image: ${PSQL_12_IMAGE}
39+
name: noobaa-psql-12
3740
- image: ${OPERATOR_IMAGE}
3841
name: noobaa-operator
3942
EOF

pkg/olm/olm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ func GenerateCSV(opConf *operator.Conf, csvParams *generateCSVParams) *operv1.Cl
297297
Name: "NOOBAA_DB_IMAGE",
298298
Value: options.DBImage,
299299
},
300+
corev1.EnvVar{
301+
Name: "NOOBAA_PSQL_12_IMAGE",
302+
Value: options.Psql12Image,
303+
},
300304
corev1.EnvVar{
301305
Name: "ENABLE_NOOBAA_ADMISSION",
302306
Value: "true",

pkg/options/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ var NooBaaImage = ContainerImage
7474
// it can be overridden for testing or different registry locations.
7575
var DBImage = "quay.io/sclorg/postgresql-15-c9s"
7676

77+
// Psql12Image is the default postgres12 db image url
78+
// currently it can not be overridden.
79+
var Psql12Image = "centos/postgresql-12-centos7"
80+
7781
// DBType is the default db image type
7882
// it can be overridden for testing or different types.
7983
var DBType = "postgres"
@@ -214,6 +218,10 @@ func init() {
214218
&DBImage, "db-image",
215219
DBImage, "The database container image",
216220
)
221+
FlagSet.StringVar(
222+
&Psql12Image, "psql-12-image",
223+
Psql12Image, "The database old container image",
224+
)
217225
FlagSet.StringVar(
218226
&CosiSideCarImage, "cosi-sidecar-image",
219227
CosiSideCarImage, "The cosi side car container image",

pkg/system/phase2_creating.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (r *Reconciler) SetDesiredNooBaaDB() error {
247247
for i := range podSpec.Containers {
248248
c := &podSpec.Containers[i]
249249
if c.Name == "db" {
250-
c.Image = GetDesiredDBImage(r.NooBaa)
250+
c.Image = GetDesiredDBImage(r.NooBaa, c.Image)
251251
if r.NooBaa.Spec.DBResources != nil {
252252
c.Resources = *r.NooBaa.Spec.DBResources
253253
}

pkg/system/reconciler.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,22 @@ func (r *Reconciler) Reconcile() (reconcile.Result, error) {
421421
log.Warnf("⏳ Temporary Error: %s", err)
422422
}
423423
} else {
424-
r.SetPhase(
425-
nbv1.SystemPhaseReady,
426-
"SystemPhaseReady",
427-
"noobaa operator completed reconcile - system is ready",
428-
)
429-
log.Infof("✅ Done")
424+
// Postgres upgrade failure workaround
425+
// if the system reconciliation has no other error, but the postgres image is still postresql-12 image, set the status to Rejected
426+
if IsPostgresql12Image(r.NooBaaPostgresDB.Spec.Template.Spec.Containers[0].Image) {
427+
r.SetPhase(nbv1.SystemPhaseRejected,
428+
"PostgresImageVersion",
429+
"Noobaa is using Postgresql-12 which indicates a failure to upgrade to Postgresql-15. Please contact support.")
430+
log.Errorf("❌ Postgres image version is set to postgresql-12. Indicates a failure to upgrade to Postgresql-15. Please contact support.")
431+
} else {
432+
r.SetPhase(
433+
nbv1.SystemPhaseReady,
434+
"SystemPhaseReady",
435+
"noobaa operator completed reconcile - system is ready",
436+
)
437+
log.Infof("✅ Done")
438+
}
439+
430440
}
431441

432442
err = r.UpdateStatus()

pkg/system/system.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,19 @@ func Connect(isExternal bool) (*Client, error) {
11161116
}
11171117

11181118
// GetDesiredDBImage returns the desired DB image according to spec or env or default (in options)
1119-
func GetDesiredDBImage(sys *nbv1.NooBaa) string {
1119+
func GetDesiredDBImage(sys *nbv1.NooBaa, currentImage string) string {
1120+
// Postgres upgrade failure workaround
1121+
// if the current Postgres image is a postgresql-12 image, use NOOBAA_PSQL12_IMAGE. otherwise use GetdesiredDBImage
1122+
if IsPostgresql12Image(currentImage) {
1123+
psql12Image, ok := os.LookupEnv("NOOBAA_PSQL_12_IMAGE")
1124+
util.Logger().Warnf("The current Postgres image is a postgresql-12 image. using (%s)", psql12Image)
1125+
if !ok {
1126+
psql12Image = currentImage
1127+
util.Logger().Warnf("NOOBAA_PSQL_12_IMAGE is not set. using the current image %s", currentImage)
1128+
}
1129+
return psql12Image
1130+
}
1131+
11201132
if sys.Spec.DBImage != nil {
11211133
return *sys.Spec.DBImage
11221134
}
@@ -1128,6 +1140,11 @@ func GetDesiredDBImage(sys *nbv1.NooBaa) string {
11281140
return options.DBImage
11291141
}
11301142

1143+
// IsPostgresql12Image checks if the image is a postgresql-12 image
1144+
func IsPostgresql12Image(image string) bool {
1145+
return strings.Contains(image, "postgresql-12")
1146+
}
1147+
11311148
// CheckSystem checks the state of the system and initializes its status fields
11321149
func CheckSystem(sys *nbv1.NooBaa) bool {
11331150
log := util.Logger()

0 commit comments

Comments
 (0)