[VOL-4674] Connecting directly to the BBSim POD instead than to the service as that might round-robin to the old instance before it's gone

Change-Id: I79558af733ff29f0c7ee204015f1f64a7895a51c
diff --git a/VERSION b/VERSION
index 1c09c74..42045ac 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.3.3
+0.3.4
diff --git a/internal/core/sadis_if.go b/internal/core/sadis_if.go
index 60514c8..e2c1083 100644
--- a/internal/core/sadis_if.go
+++ b/internal/core/sadis_if.go
@@ -102,11 +102,11 @@
 	CBS int    `json:"cbs"`
 	CIR int    `json:"cir"`
 	// MEF attributes
-	AIR int    `json:"air,omitempty"`
-	EBS int    `json:"ebs,omitempty"`
-	EIR int    `json:"eir,omitempty"`
+	AIR int `json:"air,omitempty"`
+	EBS int `json:"ebs,omitempty"`
+	EIR int `json:"eir,omitempty"`
 	// IETF attributes
-	GIR int    `json:"gir,omitempty"`
-	PIR int    `json:"pir,omitempty"`
-	PBS int    `json:"pbs,omitempty"`
+	GIR int `json:"gir,omitempty"`
+	PIR int `json:"pir,omitempty"`
+	PBS int `json:"pbs,omitempty"`
 }
diff --git a/internal/core/store_test.go b/internal/core/store_test.go
index 0896b6d..5b55967 100644
--- a/internal/core/store_test.go
+++ b/internal/core/store_test.go
@@ -23,7 +23,7 @@
 	"testing"
 )
 
-func init()  {
+func init() {
 	SetupLogger(log.ErrorLevel, "console")
 }
 
@@ -31,7 +31,7 @@
 	store := NewStore()
 
 	bp := SadisBWPEntry{
-		ID: "test-bp",
+		ID:  "test-bp",
 		AIR: 20,
 	}
 
diff --git a/internal/core/watcher.go b/internal/core/watcher.go
index ba9b5f8..0a952dc 100644
--- a/internal/core/watcher.go
+++ b/internal/core/watcher.go
@@ -92,48 +92,34 @@
 			}
 
 			logger.Debugw(ctx, "received-event-for-bbsim-pod", log.Fields{"pod": pod.Name, "namespace": pod.Namespace,
-				"release": pod.Labels["release"], "ready": ready})
+				"release": pod.Labels["release"], "ready": ready, "podIp": pod.Status.PodIP})
 
 			// as soon as the pod is ready cache the sadis entries
 			if ready {
-				// note that we should one service
-				labelSelector := fmt.Sprintf("app=bbsim,release=%s", pod.Labels["release"])
-				services, err := w.client.CoreV1().Services(pod.Namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: labelSelector})
-
-				if err != nil {
-					logger.Fatalw(ctx, "error-while-listing-services", log.Fields{"err": err})
+				if err := w.queryPod(ctx, pod.Status.PodIP, 0); err != nil {
+					logger.Errorw(ctx, "failed-to-load-sadis-config-from-bbsim",
+						log.Fields{"pod": pod.Name, "namespace": pod.Namespace, "release": pod.Labels["release"], "err": err})
 				}
-
-				w.handleServices(ctx, services)
 			}
 		}
 
 	}
 }
 
-func (w *Watcher) handleServices(ctx context.Context, services *v1.ServiceList) {
-	// TODO if a service is removed we'll want to remove the related entries
-	for _, service := range services.Items {
-		go func(service v1.Service) {
-			if err := w.queryService(ctx, service, 0); err != nil {
-				logger.Errorw(ctx, "error-while-reading-from-service", log.Fields{"error": err.Error()})
-			}
-		}(service)
-	}
-}
-
-func (w *Watcher) queryService(ctx context.Context, service v1.Service, attempt int) error {
-	endpoint := fmt.Sprintf("%s.%s.svc:%d", service.Name, service.Namespace, w.config.BBsimSadisPort)
+func (w *Watcher) queryPod(ctx context.Context, ip string, attempt int) error {
+	endpoint := fmt.Sprintf("%s:%d", ip, w.config.BBsimSadisPort)
 	logger.Infow(ctx, "querying-service", log.Fields{"endpoint": endpoint})
 
-	res, err := http.Get(fmt.Sprintf("http://%s/v2/static", endpoint))
+	client := http.Client{Timeout: 5 * time.Second}
+
+	res, err := client.Get(fmt.Sprintf("http://%s/v2/static", endpoint))
 
 	if err != nil {
 		if attempt < attemptLimit {
 			logger.Warnw(ctx, "error-while-reading-from-service-retrying", log.Fields{"error": err.Error()})
 			// if there is an error and we have attempt left just retry later
 			time.Sleep(1 * time.Second)
-			return w.queryService(ctx, service, attempt+1)
+			return w.queryPod(ctx, ip, attempt+1)
 		}
 
 		return err
@@ -157,19 +143,6 @@
 		"bandwidthProfiles": len(result.BandwidthProfile.Entries),
 	})
 
-	//for _, entry := range result.Sadis.Entries {
-	//	switch entry.(type) {
-	//	case SadisOltEntry:
-	//	case *SadisOltEntry:
-	//		logger.Infow(ctx, "olt-entry", log.Fields{"entry": entry})
-	//	case SadisOnuEntryV2:
-	//	case *SadisOnuEntryV2:
-	//		logger.Infow(ctx, "onu-entry", log.Fields{"entry": entry})
-	//	default:
-	//		logger.Warnw(ctx, "unknown-entity", log.Fields{"entry": entry})
-	//	}
-	//}
-
 	for _, entry := range result.Sadis.Entries {
 		if entry.HardwareIdentifier != "" {
 			e := SadisOltEntry{
diff --git a/internal/utils/config.go b/internal/utils/config.go
index 303c22b..69b0ce4 100644
--- a/internal/utils/config.go
+++ b/internal/utils/config.go
@@ -37,9 +37,9 @@
 
 func NewConfigFlags() *ConfigFlags {
 	flags := &ConfigFlags{
-		LogLevel:   defaultLogLevel,
-		LogFormat:  defaultLogFormat,
-		Kubeconfig: "",
+		LogLevel:       defaultLogLevel,
+		LogFormat:      defaultLogFormat,
+		Kubeconfig:     "",
 		BBsimSadisPort: defaultBBsimSadisPort,
 	}
 	return flags