Minor refactorings (#368)

* Split vkubelet funcitons into separate files.

* Minor re-org for cmd/census*

* refactor run loop
This commit is contained in:
Brian Goff
2018-10-12 17:36:37 -07:00
committed by Robbie Zhang
parent 05e6069cde
commit 3c8ce3fb4a
3 changed files with 15 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ func init() {
RegisterTracingExporter("jaeger", NewJaegerExporter) RegisterTracingExporter("jaeger", NewJaegerExporter)
} }
// NewJaegerExporter creates a new opencensus tracing exporter.
func NewJaegerExporter(opts TracingExporterOptions) (trace.Exporter, error) { func NewJaegerExporter(opts TracingExporterOptions) (trace.Exporter, error) {
jOpts := jaeger.Options{ jOpts := jaeger.Options{
Endpoint: os.Getenv("JAEGER_ENDPOINT"), Endpoint: os.Getenv("JAEGER_ENDPOINT"),

16
root.go
View File

@@ -18,9 +18,11 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"os/signal"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/cpuguy83/strongerrors" "github.com/cpuguy83/strongerrors"
@@ -71,7 +73,8 @@ var RootCmd = &cobra.Command{
backend implementation allowing users to create kubernetes nodes without running the kubelet. backend implementation allowing users to create kubernetes nodes without running the kubelet.
This allows users to schedule kubernetes workloads on nodes that aren't running Kubernetes.`, This allows users to schedule kubernetes workloads on nodes that aren't running Kubernetes.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background() ctx, cancel := context.WithCancel(context.Background())
f, err := vkubelet.New(ctx, vkubelet.Config{ f, err := vkubelet.New(ctx, vkubelet.Config{
Client: k8sClient, Client: k8sClient,
Namespace: kubeNamespace, Namespace: kubeNamespace,
@@ -85,7 +88,16 @@ This allows users to schedule kubernetes workloads on nodes that aren't running
if err != nil { if err != nil {
log.L.WithError(err).Fatal("Error initializing virtual kubelet") log.L.WithError(err).Fatal("Error initializing virtual kubelet")
} }
if err := f.Run(ctx); err != nil {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sig
cancel()
f.Stop()
}()
if err := f.Run(ctx); err != nil && errors.Cause(err) != context.Canceled {
log.L.Fatal(err) log.L.Fatal(err)
} }
}, },