From c681f7021d6bd989a45b55d092fd175e03b80928 Mon Sep 17 00:00:00 2001
From: Garet Halliday <me@garet.holiday>
Date: Wed, 13 Sep 2023 18:11:35 -0500
Subject: [PATCH] works

---
 cmd/cgat/main.go | 57 ++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/cmd/cgat/main.go b/cmd/cgat/main.go
index bb3bde63..753f4995 100644
--- a/cmd/cgat/main.go
+++ b/cmd/cgat/main.go
@@ -3,9 +3,12 @@ package main
 import (
 	"net/http"
 	_ "net/http/pprof"
+	"os"
 
 	"tuxpa.in/a/zlog/log"
 
+	"pggat/lib/gat/modes/pgbouncer"
+	"pggat/lib/gat/modes/zalando"
 	"pggat/lib/gat/modes/zalando_operator_discovery"
 )
 
@@ -16,34 +19,23 @@ func main() {
 
 	log.Printf("Starting pggat...")
 
-	conf, err := zalando_operator_discovery.Load()
-	if err != nil {
-		panic(err)
-	}
-
-	err = conf.ListenAndServe()
-	if err != nil {
-		panic(err)
-	}
-
-	/*
-		if len(os.Args) == 2 {
-			log.Printf("running in pgbouncer compatibility mode")
-			conf, err := pgbouncer.Load(os.Args[1])
-			if err != nil {
-				panic(err)
-			}
-
-			err = conf.ListenAndServe()
-			if err != nil {
-				panic(err)
-			}
-			return
+	if os.Getenv("KUBERNETES_SERVICE_HOST") != "" && os.Getenv("KUBERNETES_SERVICE_PORT") != "" {
+		log.Printf("Running in zalando operator discovery mode")
+		conf, err := zalando_operator_discovery.Load()
+		if err != nil {
+			panic(err)
 		}
 
-		log.Printf("running in zalando compatibility mode")
+		err = conf.ListenAndServe()
+		if err != nil {
+			panic(err)
+		}
+		return
+	}
 
-		conf, err := zalando.Load()
+	if len(os.Args) == 2 {
+		log.Printf("running in pgbouncer compatibility mode")
+		conf, err := pgbouncer.Load(os.Args[1])
 		if err != nil {
 			panic(err)
 		}
@@ -52,5 +44,18 @@ func main() {
 		if err != nil {
 			panic(err)
 		}
-	*/
+		return
+	}
+
+	log.Printf("running in zalando compatibility mode")
+
+	conf, err := zalando.Load()
+	if err != nil {
+		panic(err)
+	}
+
+	err = conf.ListenAndServe()
+	if err != nil {
+		panic(err)
+	}
 }
-- 
GitLab