Use goflag instead of pflag for logs

Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
James Munnelly 2019-03-01 10:43:40 +00:00
parent eaeefdf5b2
commit 420ebfebe2
16 changed files with 25 additions and 33 deletions

View File

@ -17,10 +17,9 @@ limitations under the License.
package main
import (
"flag"
"log"
flag "github.com/spf13/pflag"
"github.com/jetstack/cert-manager/pkg/issuer/acme/http/solver"
"github.com/jetstack/cert-manager/pkg/logs"
)

View File

@ -27,13 +27,14 @@ import (
)
func main() {
logs.InitLogs(nil)
logs.InitLogs(flag.CommandLine)
defer logs.FlushLogs()
ctrl.SetLogger(logs.Log)
stopCh := ctrl.SetupSignalHandler()
stopCh := ctrl.SetupSignalHandler()
cmd := NewCommandStartInjectorController(os.Stdout, os.Stderr, stopCh)
cmd.Flags().AddGoFlagSet(flag.CommandLine)
flag.CommandLine.Parse([]string{})
if err := cmd.Execute(); err != nil {
klog.Fatal(err)

View File

@ -28,13 +28,13 @@ import (
)
func main() {
logf.InitLogs(flag.CommandLine)
defer logf.FlushLogs()
stopCh := SetupSignalHandler()
cmd := NewCommandStartCertManagerController(stopCh)
cmd.Flags().AddGoFlagSet(flag.CommandLine)
logf.InitLogs(cmd.Flags())
defer logf.FlushLogs()
flag.CommandLine.Parse([]string{})
if err := cmd.Execute(); err != nil {
klog.Fatal(err)

View File

@ -8,7 +8,6 @@ go_library(
deps = [
"//pkg/api:go_default_library",
"//vendor/github.com/go-logr/logr:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",

View File

@ -23,7 +23,6 @@ import (
"time"
"github.com/go-logr/logr"
"github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@ -43,7 +42,7 @@ var (
DebugLevel = 3
)
var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
var logFlushFreq = flag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
// GlogWriter serves as a bridge between the standard log package and the glog package.
type GlogWriter struct{}
@ -55,15 +54,11 @@ func (writer GlogWriter) Write(data []byte) (n int, err error) {
}
// InitLogs initializes logs the way we want for kubernetes.
func InitLogs(fs *pflag.FlagSet) {
func InitLogs(fs *flag.FlagSet) {
if fs == nil {
fs = pflag.CommandLine
fs = flag.CommandLine
}
gofs := &flag.FlagSet{}
klog.InitFlags(gofs)
fs.AddGoFlagSet(gofs)
klog.InitFlags(fs)
fs.Set("logtostderr", "true")
log.SetOutput(GlogWriter{})

View File

@ -55,7 +55,6 @@ go_test(
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
"//vendor/github.com/onsi/ginkgo/reporters:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
)

View File

@ -17,6 +17,7 @@ limitations under the License.
package e2e
import (
"flag"
"fmt"
"path"
"testing"
@ -26,7 +27,6 @@ import (
ginkgoconfig "github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/reporters"
"github.com/onsi/gomega"
flag "github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/wait"
"github.com/jetstack/cert-manager/pkg/logs"
@ -35,6 +35,9 @@ import (
)
func init() {
logs.InitLogs(flag.CommandLine)
framework.DefaultConfig.AddFlags(flag.CommandLine)
// Turn on verbose by default to get spec names
ginkgoconfig.DefaultReporterConfig.Verbose = true
// Turn on EmitSpecProgress to get spec progress (especially on interrupt)
@ -46,10 +49,7 @@ func init() {
}
func TestE2E(t *testing.T) {
logs.InitLogs(flag.CommandLine)
defer logs.FlushLogs()
framework.DefaultConfig.AddFlags(flag.CommandLine)
flag.Parse()
if err := framework.DefaultConfig.Validate(); err != nil {

View File

@ -17,7 +17,7 @@ limitations under the License.
package config
import (
flag "github.com/spf13/pflag"
"flag"
)
// Addons contains global configuration for instances of addons

View File

@ -17,10 +17,10 @@ limitations under the License.
package config
import (
"flag"
"fmt"
"os"
"github.com/spf13/pflag"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/tools/clientcmd"
)
@ -61,7 +61,7 @@ func (c *Config) Validate() error {
}
// Register flags common to all e2e test suites.
func (c *Config) AddFlags(fs *pflag.FlagSet) {
func (c *Config) AddFlags(fs *flag.FlagSet) {
// Kubernetes API server config
fs.StringVar(&c.KubeConfig, "kubernetes-config", os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to config containing embedded authinfo for kubernetes. Default value is from environment variable "+clientcmd.RecommendedConfigPathEnvVar)
fs.StringVar(&c.KubeContext, "kubernetes-context", "", "config context to use for kuberentes. If unset, will use value from 'current-context'")

View File

@ -17,7 +17,7 @@ limitations under the License.
package config
import (
flag "github.com/spf13/pflag"
"flag"
)
type Framework struct {

View File

@ -17,7 +17,7 @@ limitations under the License.
package config
import (
flag "github.com/spf13/pflag"
"flag"
)
type Ginkgo struct {

View File

@ -19,7 +19,7 @@ package config
import (
"fmt"
flag "github.com/spf13/pflag"
"flag"
)
type Helm struct {

View File

@ -19,7 +19,7 @@ package config
import (
"fmt"
flag "github.com/spf13/pflag"
"flag"
)
type Nginx struct {

View File

@ -17,7 +17,7 @@ limitations under the License.
package config
import (
flag "github.com/spf13/pflag"
"flag"
)
// Pebble global configuration for new Pebble instances

View File

@ -19,7 +19,7 @@ package config
import (
"os"
flag "github.com/spf13/pflag"
"flag"
)
type Suite struct {

View File

@ -17,9 +17,8 @@ limitations under the License.
package config
import (
"flag"
"fmt"
flag "github.com/spf13/pflag"
)
type Tiller struct {