changeset 68:e0c969974635

get mongodb ip from k8s environment
author drewp@bigasterisk.com
date Fri, 06 Sep 2024 17:27:51 -0700
parents 1f84bd5ce8e0
children 72021e6e5c54
files calsync/mongoclient/mongoclient.go
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/calsync/mongoclient/mongoclient.go	Fri Sep 06 17:27:16 2024 -0700
+++ b/calsync/mongoclient/mongoclient.go	Fri Sep 06 17:27:51 2024 -0700
@@ -3,6 +3,7 @@
 import (
 	"context"
 	"log"
+	"os"
 	"time"
 
 	"go.mongodb.org/mongo-driver/mongo"
@@ -35,8 +36,9 @@
 }
 
 func New(ctx context.Context) (*MongoClient, error) {
-	log.Println("todo: using fixed ip")
-	mclient, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://10.43.98.221:27017"))
+	host := os.Getenv("MONGODB_SERVICE_HOST") + ":27017"
+	log.Println("connecting to mongodb at ", host)
+	mclient, err := mongo.Connect(ctx, options.Client().SetHosts([]string{host}))
 	if err != nil {
 		return nil, err
 	}