[bitnami/mongodb-sharded] Update libmongodb.sh : mongodb_is_primary_node_up() function : grep check to find if mongod instance changed from secondary to primary (#55910)

* Update libmongodb.sh : mongodb_is_primary_node_up() function : grep check to find if mongod instance changed from secondary to primary

In the Bitnami script file libmongodb.sh, in mongodb_is_primary_node_up(), the grep chec to see if the MongoDB instance has turned from secondary to primary has bug.

Reason : The problem is in the line grep -q "true" <<<"$result". As part of the $result output, MongoDB gives a connection string which also has the string "true".

Hence even when it is secondary, i.e. output of db.isMaster().ismaster is false, the grep -q "true" <<<"$result" check passes and it proceeds to create the root user. When it tries to create a root user during the secondary state, the root user creation fails. In faster systems, it turns into primary quickly and this bug in the code doesn't matter.

Changing the grep check into a more specific one like the following helps to check if the mongodb instance turns into primary and then the root user gets created successfully and Authentication passes.

grep -q "\[direct: primary\] admin> true" <<<"$result"

Signed-off-by: Sasidharan Ekambavanan <esasidharan@gmail.com>

* Update libmongodb.sh

Changing grep check to a more generic one to support any string within [direct: ]

Signed-off-by: Sasidharan Ekambavanan <esasidharan@gmail.com>

* Update libmongodb.sh

Fixing typo.

Signed-off-by: Sasidharan Ekambavanan <esasidharan@gmail.com>

* Update bitnami/mongodb-sharded/7.0/debian-11/rootfs/opt/bitnami/scripts/libmongodb.sh

Signed-off-by: Gonzalo Gómez Gracia <gongomgra@users.noreply.github.com>

---------

Signed-off-by: Sasidharan Ekambavanan <esasidharan@gmail.com>
Signed-off-by: Gonzalo Gómez Gracia <gongomgra@users.noreply.github.com>
Co-authored-by: Gonzalo Gómez Gracia <gongomgra@users.noreply.github.com>
This commit is contained in:
Sasidharan Ekambavanan 2024-02-20 14:13:57 +05:30 committed by GitHub
parent a157dc52f4
commit b35a6dcf83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -1052,7 +1052,7 @@ mongodb_is_primary_node_up() {
db.isMaster().ismaster
EOF
)
grep -q "true" <<<"$result"
grep -qE ".*\[direct:\s?\S+\]\s+admin>\s+true" <<<"$result"
}
########################