Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an source to all log statements #103

Merged
merged 1 commit into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package main

import (
"strings"
"time"
"os"
"path/filepath"
"strings"
"time"

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/client/clientset/versioned"
Expand All @@ -28,7 +28,6 @@ import (
"agones.dev/agones/pkg/util/runtime"
"agones.dev/agones/pkg/util/signals"
"agones.dev/agones/pkg/util/webhooks"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
extclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
Expand All @@ -46,15 +45,15 @@ const (
keyFileFlag = "key-file"
)

func init() {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
var (
logger = runtime.NewLoggerWithSource("main")
)

// main starts the operator for the gameserver CRD
func main() {
exec, err := os.Executable()
if err != nil {
logrus.WithError(err).Fatal("Could not get executable path")
logger.WithError(err).Fatal("Could not get executable path")
}

base := filepath.Dir(exec)
Expand Down Expand Up @@ -87,7 +86,7 @@ func main() {
keyFile := viper.GetString(keyFileFlag)
certFile := viper.GetString(certFileFlag)

logrus.WithField(sidecarFlag, sidecarImage).
logger.WithField(sidecarFlag, sidecarImage).
WithField("minPort", minPort).
WithField("maxPort", maxPort).
WithField(keyFileFlag, keyFile).
Expand All @@ -96,29 +95,29 @@ func main() {
WithField("Version", pkg.Version).Info("starting gameServer operator...")

if minPort <= 0 || maxPort <= 0 {
logrus.Fatal("Min Port and Max Port values are required.")
logger.Fatal("Min Port and Max Port values are required.")
} else if maxPort < minPort {
logrus.Fatal("Max Port cannot be set less that the Min Port")
logger.Fatal("Max Port cannot be set less that the Min Port")
}

config, err := rest.InClusterConfig()
if err != nil {
logrus.WithError(err).Fatal("Could not create in cluster config")
logger.WithError(err).Fatal("Could not create in cluster config")
}

kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
logrus.WithError(err).Fatal("Could not create the kubernetes clientset")
logger.WithError(err).Fatal("Could not create the kubernetes clientset")
}

extClient, err := extclientset.NewForConfig(config)
if err != nil {
logrus.WithError(err).Fatal("Could not create the api extension clientset")
logger.WithError(err).Fatal("Could not create the api extension clientset")
}

agonesClient, err := versioned.NewForConfig(config)
if err != nil {
logrus.WithError(err).Fatal("Could not create the agones api clientset")
logger.WithError(err).Fatal("Could not create the agones api clientset")
}

agonesInformerFactory := externalversions.NewSharedInformerFactory(agonesClient, 30*time.Second)
Expand All @@ -134,14 +133,14 @@ func main() {

go func() {
if err := wh.Run(stop); err != nil { // nolint: vetshadow
logrus.WithError(err).Fatal("could not run webhook server")
logger.WithError(err).Fatal("could not run webhook server")
}
}()

err = c.Run(2, stop)
if err != nil {
logrus.WithError(err).Fatal("Could not run gameserver controller")
logger.WithError(err).Fatal("Could not run gameserver controller")
}

logrus.Info("Shut down gameserver controller")
logger.Info("Shut down gameserver controller")
}
21 changes: 10 additions & 11 deletions cmd/sdk-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"agones.dev/agones/pkg/gameservers"
"agones.dev/agones/pkg/sdk"
"agones.dev/agones/pkg/util/runtime"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand All @@ -51,9 +50,9 @@ const (
healthFailureThresholdFlag = "health-failure-threshold"
)

func init() {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
var (
logger = runtime.NewLoggerWithSource("main")
)

func main() {
viper.SetDefault(localFlag, false)
Expand Down Expand Up @@ -92,15 +91,15 @@ func main() {
healthInitialDelay := time.Duration(viper.GetInt64(healthInitialDelayFlag)) * time.Second
healthFailureThreshold := viper.GetInt64(healthFailureThresholdFlag)

logrus.WithField(localFlag, isLocal).WithField("version", pkg.Version).
logger.WithField(localFlag, isLocal).WithField("version", pkg.Version).
WithField("port", port).WithField(addressFlag, address).
WithField(healthDisabledFlag, healthDisabled).WithField(healthTimeoutFlag, healthTimeout).
WithField(healthFailureThresholdFlag, healthFailureThreshold).
WithField(healthInitialDelayFlag, healthInitialDelay).Info("Starting sdk sidecar")

lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", address, port))
if err != nil {
logrus.WithField("port", port).WithField("address", address).Fatalf("Could not listen on port")
logger.WithField("port", port).WithField("address", address).Fatalf("Could not listen on port")
}
grpcServer := grpc.NewServer()

Expand All @@ -109,24 +108,24 @@ func main() {
} else {
config, err := rest.InClusterConfig()
if err != nil {
logrus.WithError(err).Fatal("Could not create in cluster config")
logger.WithError(err).Fatal("Could not create in cluster config")
}

kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
logrus.WithError(err).Fatal("Could not create the kubernetes clientset")
logger.WithError(err).Fatal("Could not create the kubernetes clientset")
}

agonesClient, err := versioned.NewForConfig(config)
if err != nil {
logrus.WithError(err).Fatalf("Could not create the agones api clientset")
logger.WithError(err).Fatalf("Could not create the agones api clientset")
}

var s *gameservers.SDKServer
s, err = gameservers.NewSDKServer(viper.GetString(gameServerNameEnv), viper.GetString(podNamespaceEnv),
healthDisabled, healthTimeout, healthFailureThreshold, healthInitialDelay, kubeClient, agonesClient)
if err != nil {
logrus.WithError(err).Fatalf("Could not start sidecar")
logger.WithError(err).Fatalf("Could not start sidecar")
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -137,6 +136,6 @@ func main() {

err = grpcServer.Serve(lis)
if err != nil {
logrus.WithError(err).Error("Could not serve grpc server")
logger.WithError(err).Error("Could not serve grpc server")
}
}
2 changes: 0 additions & 2 deletions pkg/apis/stable/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"testing"

"agones.dev/agones/pkg/apis/stable"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -218,7 +217,6 @@ func TestGameServerPod(t *testing.T) {
assert.Equal(t, fixture.Spec.HostPort, pod.Spec.Containers[0].Ports[0].HostPort)
assert.Equal(t, fixture.Spec.ContainerPort, pod.Spec.Containers[0].Ports[0].ContainerPort)
assert.Equal(t, corev1.Protocol("UDP"), pod.Spec.Containers[0].Ports[0].Protocol)
logrus.SetFormatter(&logrus.JSONFormatter{})
assert.True(t, metav1.IsControlledBy(pod, fixture))

sidecar := corev1.Container{Name: "sidecar", Image: "container/sidecar"}
Expand Down
Loading