0.1.0 • Published 9 years ago

mongo-k8s-connstr v0.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

mongo-k8s-connstr

Simple node module to provide a mongo connection string when using mongo in Kubernetes. It takes a set of kubernetes labels which is used to query the kubernetes api for matching pods.

Environment Variables

The library depends on the following environment variables.

NameDescriptionExample
LL_MONGO_URLIf you want to set the mongo connection string manuallymongodb://127.0.0.1/shipping
LL_MONGO_POD_LABELSPod labels used to select all the mongo servers, should be a comma separated list of key valuesname=mongo,environment=dev
LL_MONGO_DBNAMEName of the database you want to connect toshipping
LL_MONGO_REPLICASETName of the mongo replicasetrs0
LL_MONGO_REPLICASET_WWrite concern value (defaults to '1')majority
LL_MONGO_REPLICASET_READPREFRead preference value (defaults to 'primary')primaryPreferred

How it works

If LL_MONGO_URL is set, no further manipulation is done and it is returned.

Otherwise it will check the kubernetes readonly API to return all the pods and then find the pods that match the supplied pod labels.

TODO

  • handle if the mongo pods aren't up and assigned an IP yet
  • tests
  • filter the pods via the API