cmd/dex: add logging config and serve logger for different modules.

This commit is contained in:
rithu john
2016-11-22 15:35:46 -08:00
parent 79c51f2983
commit 2e22a948cf
20 changed files with 191 additions and 43 deletions

View File

@@ -21,6 +21,7 @@ import (
"strings"
"time"
"github.com/Sirupsen/logrus"
"github.com/ghodss/yaml"
"github.com/gtank/cryptopasta"
"golang.org/x/net/context"
@@ -33,6 +34,7 @@ type client struct {
client *http.Client
baseURL string
namespace string
logger logrus.FieldLogger
// Hash function to map IDs (which could span a large range) to Kubernetes names.
// While this is not currently upgradable, it could be in the future.
@@ -230,7 +232,7 @@ func (c *client) put(resource, name string, v interface{}) error {
return checkHTTPErr(resp, http.StatusOK)
}
func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string) (*client, error) {
func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string, logger logrus.FieldLogger) (*client, error) {
tlsConfig := cryptopasta.DefaultTLSConfig()
data := func(b string, file string) ([]byte, error) {
if b != "" {
@@ -303,6 +305,7 @@ func newClient(cluster k8sapi.Cluster, user k8sapi.AuthInfo, namespace string) (
hash: func() hash.Hash { return fnv.New64() },
namespace: namespace,
apiVersion: "oidc.coreos.com/v1",
logger: logger,
}, nil
}

View File

@@ -10,6 +10,7 @@ import (
"golang.org/x/net/context"
"github.com/Sirupsen/logrus"
"github.com/coreos/dex/storage"
"github.com/coreos/dex/storage/kubernetes/k8sapi"
)
@@ -39,8 +40,8 @@ type Config struct {
}
// Open returns a storage using Kubernetes third party resource.
func (c *Config) Open() (storage.Storage, error) {
cli, err := c.open()
func (c *Config) Open(logger logrus.FieldLogger) (storage.Storage, error) {
cli, err := c.open(logger)
if err != nil {
return nil, err
}
@@ -48,7 +49,7 @@ func (c *Config) Open() (storage.Storage, error) {
}
// open returns a client with no garbage collection.
func (c *Config) open() (*client, error) {
func (c *Config) open(logger logrus.FieldLogger) (*client, error) {
if c.InCluster && (c.KubeConfigFile != "") {
return nil, errors.New("cannot specify both 'inCluster' and 'kubeConfigFile'")
}
@@ -71,7 +72,7 @@ func (c *Config) open() (*client, error) {
return nil, err
}
cli, err := newClient(cluster, user, namespace)
cli, err := newClient(cluster, user, namespace, logger)
if err != nil {
return nil, fmt.Errorf("create client: %v", err)
}

View File

@@ -5,6 +5,7 @@ import (
"os"
"testing"
"github.com/Sirupsen/logrus"
"github.com/coreos/dex/storage"
"github.com/coreos/dex/storage/conformance"
)
@@ -22,7 +23,12 @@ func loadClient(t *testing.T) *client {
if config.KubeConfigFile == "" {
t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv)
}
s, err := config.open()
logger := &logrus.Logger{
Out: os.Stderr,
Formatter: &logrus.TextFormatter{DisableColors: true},
Level: logrus.DebugLevel,
}
s, err := config.open(logger)
if err != nil {
t.Fatal(err)
}