From d8979950b8525f3284b98067a4e0f0fb81334d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20=C5=81askawiec?= Date: Wed, 27 Sep 2023 10:35:44 +0200 Subject: [PATCH] CLOUDP-202214 Error on MDB 7 --- controllers/replica_set_controller.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/controllers/replica_set_controller.go b/controllers/replica_set_controller.go index a83925e6a..e26c5b5e1 100644 --- a/controllers/replica_set_controller.go +++ b/controllers/replica_set_controller.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" "fmt" + "github.com/blang/semver" + "github.com/mongodb/mongodb-kubernetes-operator/pkg/util/envvar" "os" "strconv" "strings" @@ -52,6 +54,8 @@ const ( lastSuccessfulConfiguration = "mongodb.com/v1.lastSuccessfulConfiguration" lastAppliedMongoDBVersion = "mongodb.com/v1.lastAppliedMongoDBVersion" + + ignoreMdb7ErrorEnvVar = "IGNORE_MDB_7_ERROR" ) func init() { @@ -622,7 +626,16 @@ func (r *ReplicaSetReconciler) buildService(mdb mdbv1.MongoDBCommunity, portMana // it checks that the attempted Spec is valid in relation to the Spec that resulted from that last successful configuration. // The validation also returns the lastSuccessFulConfiguration Spec as mdbv1.MongoDBCommunitySpec. func (r ReplicaSetReconciler) validateSpec(mdb mdbv1.MongoDBCommunity) (error, *mdbv1.MongoDBCommunitySpec) { - + if !envvar.ReadBool(ignoreMdb7ErrorEnvVar) { + semverVersion, err := semver.Make(mdb.Spec.Version) + if err != nil { + r.log.Warnf("could not parse version %v", mdb.Spec.Version) + } else { + if semverVersion.Major >= 7 { + return fmt.Errorf("monggodb >= 7 is not supported"), nil + } + } + } lastSuccessfulConfigurationSaved, ok := mdb.Annotations[lastSuccessfulConfiguration] if !ok { // First version of Spec