Commit e4c5802c authored by Dmitry Shulyak's avatar Dmitry Shulyak

Allow to specify socket for rudder grpc server

os args will be used to specify grpc server socket,
either --listen or -l can be used as an argument to rudder binary
parent 21c0391e
...@@ -26,9 +26,9 @@ import ( ...@@ -26,9 +26,9 @@ import (
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"github.com/spf13/pflag"
"k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/kube"
rudderAPI "k8s.io/helm/pkg/proto/hapi/rudder" rudderAPI "k8s.io/helm/pkg/proto/hapi/rudder"
"k8s.io/helm/pkg/rudder"
"k8s.io/helm/pkg/tiller" "k8s.io/helm/pkg/tiller"
"k8s.io/helm/pkg/version" "k8s.io/helm/pkg/version"
) )
...@@ -36,24 +36,43 @@ import ( ...@@ -36,24 +36,43 @@ import (
var kubeClient *kube.Client var kubeClient *kube.Client
var clientset internalclientset.Interface var clientset internalclientset.Interface
type options struct {
listen string
}
func (opts *options) registerFlags() {
pflag.StringVarP(&opts.listen, "listen", "l", "127.0.0.1:10001",
"Socket for rudder grpc server (default: 127.0.0.1:10001).")
}
func (opts *options) parseFlags() {
pflag.Parse()
}
func (opts *options) regAndParseFlags() {
opts.registerFlags()
opts.parseFlags()
}
func main() { func main() {
opts := new(options)
opts.regAndParseFlags()
var err error var err error
kubeClient = kube.New(nil) kubeClient = kube.New(nil)
clientset, err = kubeClient.ClientSet() clientset, err = kubeClient.ClientSet()
if err != nil { if err != nil {
grpclog.Fatalf("Cannot initialize Kubernetes connection: %s", err) grpclog.Fatalf("Cannot initialize Kubernetes connection: %s", err)
} }
grpclog.Printf("Creating tcp socket on %s\n", opts.listen)
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", rudder.GrpcPort)) lis, err := net.Listen("tcp", opts.listen)
if err != nil { if err != nil {
grpclog.Fatalf("failed to listen: %v", err) grpclog.Fatalf("failed to listen: %v", err)
} }
grpcServer := grpc.NewServer() grpcServer := grpc.NewServer()
rudderAPI.RegisterReleaseModuleServiceServer(grpcServer, &ReleaseModuleServiceServer{}) rudderAPI.RegisterReleaseModuleServiceServer(grpcServer, &ReleaseModuleServiceServer{})
grpclog.Print("Server starting") grpclog.Printf("Starting server on %s\n", opts.listen)
grpcServer.Serve(lis) grpcServer.Serve(lis)
grpclog.Print("Server started")
} }
// ReleaseModuleServiceServer provides implementation for rudderAPI.ReleaseModuleServiceServer // ReleaseModuleServiceServer provides implementation for rudderAPI.ReleaseModuleServiceServer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment