Create Kubernetes Probes for API Server[VOL-1731]
Change-Id: Ie289ffce77af284f2b8f62603f8570d80a598e50
diff --git a/cmd/arouter/arouter.go b/cmd/arouter/arouter.go
index 6fd9dbf..73f8782 100644
--- a/cmd/arouter/arouter.go
+++ b/cmd/arouter/arouter.go
@@ -20,6 +20,7 @@
"fmt"
"github.com/opencord/voltha-api-server/internal/pkg/afrouter"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
+ "github.com/opencord/voltha-lib-go/v2/pkg/probe"
"github.com/opencord/voltha-lib-go/v2/pkg/version"
_ "github.com/opencord/voltha-protos/v2"
"google.golang.org/grpc/grpclog"
@@ -70,6 +71,18 @@
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, ioutil.Discard, ioutil.Discard))
}
+ /*
+ * Create and start the liveness and readiness container management probes. This
+ * is done in the main function so just in case the main starts multiple other
+ * objects there can be a single probe end point for the process.
+ */
+ p := &probe.Probe{}
+ go p.ListenAndServe(fmt.Sprintf("%s:%d", conf.Api.ProbeHost, conf.Api.ProbePort))
+
+ p.RegisterService(
+ "affinity-router-proxy",
+ )
+
// Install the signal and error handlers.
err = afrouter.InitExitHandler()
if err != nil {
@@ -78,7 +91,7 @@
}
// Create the affinity router proxy...
- if ap, err := afrouter.NewArouterProxy(conf); err != nil {
+ if ap, err := afrouter.NewArouterProxy(conf, p); err != nil {
log.Errorf("Failed to create the arouter proxy, exiting:%v", err)
return 1
// and start it.
diff --git a/cmd/arouterd/arouterd.go b/cmd/arouterd/arouterd.go
index eedfe5c..5452b97 100644
--- a/cmd/arouterd/arouterd.go
+++ b/cmd/arouterd/arouterd.go
@@ -17,21 +17,25 @@
package main
import (
+ "context"
"flag"
"fmt"
"github.com/opencord/voltha-api-server/internal/pkg/afrouterd"
+ "github.com/opencord/voltha-lib-go/v2/pkg/probe"
"github.com/opencord/voltha-lib-go/v2/pkg/version"
+ "math"
"os"
"path"
"github.com/opencord/voltha-lib-go/v2/pkg/log"
pb "github.com/opencord/voltha-protos/v2/go/afrouter"
- "golang.org/x/net/context"
)
var (
instanceID = afrouterd.GetStrEnv("HOSTNAME", "arouterd001")
afrouterApiAddress = afrouterd.GetStrEnv("AFROUTER_API_ADDRESS", "localhost:55554")
+ probeHost = afrouterd.GetStrEnv("PROBE_HOST", "")
+ probePort = afrouterd.GetIntEnv("PROBE_PORT", 0, math.MaxUint16, 8081)
)
type Configuration struct {
@@ -62,16 +66,26 @@
// Set up kubernetes api
clientset := afrouterd.K8sClientSet()
+ p := &probe.Probe{}
+ go p.ListenAndServe(fmt.Sprintf("%s:%d", probeHost, probePort))
+
+ p.RegisterService(
+ "affinity-router",
+ "message-bus",
+ )
+
for {
// Connect to the affinity router
conn, err := afrouterd.Connect(context.Background(), afrouterApiAddress) // This is a sidecar container so communicating over localhost
if err != nil {
panic(err)
}
+ p.UpdateStatus("affinity-router", probe.ServiceStatusRunning)
// monitor the connection status, end context if connection is lost
- ctx := afrouterd.ConnectionActiveContext(conn)
+ ctx := afrouterd.ConnectionActiveContext(conn, p)
+ probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p)
// set up the client
client := pb.NewConfigurationClient(conn)
@@ -79,10 +93,10 @@
// these two processes do the majority of the work
log.Info("Starting discovery monitoring")
- doneCh, _ := afrouterd.StartDiscoveryMonitor(ctx, client)
+ doneCh, _ := afrouterd.StartDiscoveryMonitor(probeCtx, client)
log.Info("Starting core monitoring")
- afrouterd.CoreMonitor(ctx, client, clientset)
+ afrouterd.CoreMonitor(probeCtx, client, clientset)
//ensure the discovery monitor to quit
<-doneCh