Skip to content

Commit

Permalink
Provide a runtime API
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed May 13, 2021
1 parent 49fedfa commit 3e118d1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ clusters:
# insecure: set true when the cluster CA is self-signed
insecure_disable_certificate_verify: false

api: # optional
enabled: false # set true to enable api to get insights
address: "localhost:6655" # default, optional

bgp:
router_id: "10.0.1.1"
local_as: 45678
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/bio-routing/bio-rd v0.0.3-pre7
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.4.2
google.golang.org/grpc v1.28.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.21.0
k8s.io/client-go v0.21.0
Expand Down
32 changes: 32 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@ package main
import (
"context"
"flag"
"net"
"os"
"os/signal"
"syscall"

bnet "github.com/bio-routing/bio-rd/net"
bgpapi "github.com/bio-routing/bio-rd/protocols/bgp/api"
bgp "github.com/bio-routing/bio-rd/protocols/bgp/server"
"github.com/ffddorf/kube-route-reflector/reflector"
"github.com/ffddorf/kube-route-reflector/watcher"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"gopkg.in/yaml.v2"
)

type APIConfig struct {
Enabled bool `yaml:"enabled"`
Address string `yaml:"address"`
}

type Config struct {
Clusters []watcher.KubernetesConfig `yaml:"clusters"`
BGP reflector.BGPConfig `yaml:"bgp"`
API APIConfig `yaml:"api"`
}

func loadConfig(path string) (*Config, error) {
Expand Down Expand Up @@ -60,6 +69,11 @@ func main() {
"[::]:179",
"0.0.0.0:179",
})
if conf.API.Enabled {
if err := startBGPAPI(bgpServer, conf.API.Address); err != nil {
log.WithError(err).Fatal("failed to start api server")
}
}

server := reflector.NewServer(log.WithField("component", "reflector"), bgpServer, conf.BGP)
if err := server.Start(log); err != nil {
Expand All @@ -72,3 +86,21 @@ func main() {

watcher.WatchClusters(ctx, log, conf.Clusters, server)
}

func startBGPAPI(server bgp.BGPServer, address string) error {
grpcServer := grpc.NewServer()

api := bgp.NewBGPAPIServer(server)
bgpapi.RegisterBgpServiceServer(grpcServer, api)

if address == "" {
address = "localhost:5566"
}

lis, err := net.Listen("tcp", address)
if err != nil {
return err
}
go grpcServer.Serve(lis)
return nil
}

0 comments on commit 3e118d1

Please sign in to comment.