Skip to content

Moving Boards to the Huddo databases

After moving a Boards release into Huddo on Component Pack, Boards, user and licence keep their boards-* MongoDB databases and sign in as kudos-boards. That works indefinitely, and for a large install there is little to gain from moving.

This page is for when you want Boards on the huddo-* databases and the huddo user, the huddo-cp defaults, like every other Huddo service. It copies the data, so plan an outage of a few minutes plus the copy, and run it at a quiet time.

Before After
boards-app huddo-boards
boards-user huddo-user
boards-licence huddo-licence
boards-notification huddo-boards-notification (notification's collections) and huddo-boards-events (events' collections)
Signed in as kudos-boards Signed in as huddo

The Boards notification and events services shared one database. In huddo-cp each has its own, so the copy splits it by the service that owns each collection.


Before you start

  1. The huddo MongoDB user has huddo-boards, huddo-boards-notification and huddo-boards-events among its roles. See Creating the MongoDB user; add missing ones with grantRolesToUser.
  2. Save the current values: helm get values huddo-cp -n connections > huddo-values.yaml.

Step 1: Stop the Boards services

The outage starts here. Stop the services that write to these databases:

kubectl scale deploy -n connections --replicas=0 \
  huddo-cp-user huddo-cp-licence huddo-cp-boards-app huddo-cp-boards-notification \
  huddo-cp-boards-events huddo-cp-activity-migration

Sign-in is down for Boards and Huddo until Step 3.


Step 2: Copy the databases

Find the MongoDB primary as in Creating the MongoDB user, and use its pod (for example mongo7-1) below.

The script dumps the Boards databases to /tmp/boards-move in that pod, copies them to the huddo-* names, and checks that every collection has the same number of documents and indexes as its source. It never writes into or deletes an existing database: if huddo-boards, huddo-boards-notification, huddo-boards-events, huddo-user or huddo-licence already has collections, it stops before copying anything and names them. Look at what they hold. At starting point B, Huddo used the Boards user and licence services, so a huddo-user or huddo-licence database is usually a leftover from testing. Back it up and remove it yourself if you don't need it, then run the script again. The boards-* databases are left untouched.

Save it as move-boards-dbs.sh, set PRIMARY to the primary's host name, and run it:

#!/bin/sh
set -eu
PRIMARY=mongo7-1.mongo7.connections.svc.cluster.local
URI="mongodb://$PRIMARY:27017/?authMechanism=MONGODB-X509&authSource=%24external&tls=true&tlsCertificateKeyFile=%2Fetc%2Fca%2Fuser_admin.pem&tlsCAFile=%2Fetc%2Fca%2Finternal-ca-chain.cert.pem"
DIR=/tmp/boards-move
NOTIFICATION="events eventdefinitions notifications notifiers templates schemamigrations"
EVENTS="notifieds queueitems scheduledqueueitems triggers processedtriggers notificationpreferences"
shell() {
  mongosh --quiet --tls --tlsCertificateKeyFile /etc/ca/user_admin.pem \
    --tlsCAFile /etc/ca/internal-ca-chain.cert.pem --host "$PRIMARY" \
    --authenticationMechanism=MONGODB-X509 --authenticationDatabase '$external' \
    -u 'C=IE,ST=Ireland,L=Dublin,O=IBM,OU=Connections-Middleware-Clients,CN=admin,emailAddress=admin@mongodb' \
    --eval "$1"
}
restore() { mongorestore --quiet --uri "$URI" --dir "$DIR/dump" "$@"; }

shell 'if (!db.hello().isWritablePrimary) throw new Error("not the primary")'
shell 'const used = ["huddo-user","huddo-licence","huddo-boards","huddo-boards-notification","huddo-boards-events"]
  .filter(d => db.getSiblingDB(d).getCollectionNames().length);
  if (used.length) { print("STOP: already have collections: " + used.join(", ") + ". Nothing was copied."); quit(1); }'

rm -rf "$DIR" && mkdir -p "$DIR"
for db in boards-app boards-user boards-licence boards-notification; do
  mongodump --quiet --uri "$URI" --db "$db" --out "$DIR/dump"
done

restore --nsInclude 'boards-app.*'     --nsFrom 'boards-app.*'     --nsTo 'huddo-boards.*'
restore --nsInclude 'boards-user.*'    --nsFrom 'boards-user.*'    --nsTo 'huddo-user.*'
restore --nsInclude 'boards-licence.*' --nsFrom 'boards-licence.*' --nsTo 'huddo-licence.*'
args=""; for c in $NOTIFICATION; do args="$args --nsInclude boards-notification.$c"; done
restore $args --nsFrom 'boards-notification.*' --nsTo 'huddo-boards-notification.*'
args=""; for c in $EVENTS; do args="$args --nsInclude boards-notification.$c"; done
restore $args --nsFrom 'boards-notification.*' --nsTo 'huddo-boards-events.*'

shell '
  const n = "'"$NOTIFICATION"'".split(" "), e = "'"$EVENTS"'".split(" ");
  let bad = 0;
  for (const [from, to, only] of [["boards-app","huddo-boards"], ["boards-user","huddo-user"],
      ["boards-licence","huddo-licence"], ["boards-notification","huddo-boards-notification",n],
      ["boards-notification","huddo-boards-events",e]]) {
    const s = db.getSiblingDB(from), d = db.getSiblingDB(to);
    for (const c of only ?? s.getCollectionNames()) {
      const a = [s[c].countDocuments({}), s[c].getIndexes().length];
      const b = [d[c].countDocuments({}), d[c].getIndexes().length];
      if (a.join() !== b.join()) { bad++; print("MISMATCH", from + "." + c, a, to, b); }
    }
  }
  print(bad ? "FAILED" : "OK: every collection matches");'
kubectl exec -i mongo7-1 -c mongo7 -n connections -- sh -s < move-boards-dbs.sh

It must end with OK: every collection matches. Keep a copy of the dumps outside the pod, since /tmp is lost when the pod restarts:

kubectl exec mongo7-1 -c mongo7 -n connections -- tar -C /tmp/boards-move/dump -cf - . > boards-move.tar

Step 3: Drop the overrides and deploy

In your values, remove what Keep Boards on its databases added: every MONGO_DB and MONGO_CERT_USER: kudos-boards on user, licence, boards-app, boards-notification, boards-events and activity-migration, and S3_BUCKET on user if you have it. Remove a service's env: entirely if nothing is left in it: an empty env: would clear the chart's own settings.

Keep s3.persistence as it is: the files stay where they are.

helm upgrade huddo-cp oci://quay.io/huddo/huddo-cp --version <CHART_VERSION> \
  -f ./huddo-cp.yaml --namespace connections

This starts the stopped services on their huddo-* databases. The outage ends when they are ready.


Verify

  1. Each Boards service, user and licence is on its huddo-* database as huddo, and its log shows no not authorized:

    kubectl get deploy -n connections -l release=huddo-cp -o \
      jsonpath='{range .items[*]}{.metadata.name}{" "}{.spec.template.spec.containers[0].env[?(@.name=="MONGO_DB")].value}{"\n"}{end}'
    kubectl logs deploy/huddo-cp-boards-app -n connections | grep -i 'not authorized'
    
  2. In a browser that was signed in before, /boards opens without a new login. Open a board, and a card with an attachment.


Rolling back

The boards-* databases are untouched. Upgrade huddo-cp with huddo-values.yaml to put the services back on them. Anything users changed since Step 3 is lost.


Clean up

When you are happy, drop the old databases on the primary, by hand:

db.getSiblingDB("boards-app").dropDatabase()
db.getSiblingDB("boards-user").dropDatabase()
db.getSiblingDB("boards-licence").dropDatabase()
db.getSiblingDB("boards-notification").dropDatabase()

Then delete the dumps in the Mongo pod: rm -rf /tmp/boards-move. Leave the kudos-boards user alone: Component Pack's MongoDB sidecar owns it.