Skip to content

Commit

Permalink
implemented glog wrapper for use in delegated commands
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <[email protected]>
  • Loading branch information
stevekuznetsov committed Apr 20, 2016
1 parent 433ceb1 commit 1b7ba72
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/server/admin/create_keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (o CreateKeyPairOptions) Validate(args []string) error {
return errors.New("--private-key must be provided")
}
if o.PublicKeyFile == o.PrivateKeyFile {
return errors.New("--public-key and --private-key must be different")
return errors.New("--public-key and --writePrivateKeyFile-key must be different")
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type AllInOneOptions struct {
NodeConfigFile string
PrintIP bool
ServiceNetworkCIDR string
Output io.Writer
}

const allInOneLong = `
Expand All @@ -59,7 +60,7 @@ You may also pass --kubeconfig=<path> to connect to an external Kubernetes clust

// NewCommandStartAllInOne provides a CLI handler for 'start' command
func NewCommandStartAllInOne(basename string, out io.Writer) (*cobra.Command, *AllInOneOptions) {
options := &AllInOneOptions{MasterOptions: &MasterOptions{Output: out}}
options := &AllInOneOptions{Output: out, MasterOptions: &MasterOptions{Output: out}}
options.MasterOptions.DefaultsFromName(basename)

cmds := &cobra.Command{
Expand Down Expand Up @@ -227,7 +228,7 @@ func (o AllInOneOptions) StartAllInOne() error {
if err != nil {
return err
}
fmt.Fprintf(o.MasterOptions.Output, "%s\n", host)
fmt.Fprintf(o.Output, "%s\n", host)
return nil
}
masterOptions := *o.MasterOptions
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (o MasterOptions) CreateCerts() error {
APIServerCAFiles: o.MasterArgs.APIServerCAFiles,
CABundleFile: admin.DefaultCABundleFile(o.MasterArgs.ConfigDir.Value()),
PublicAPIServerURL: publicMasterAddr.String(),
Output: o.Output,
Output: cmdutil.NewGLogWriterV(3),
}
if err := mintAllCertsOptions.Validate(nil); err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/server/start/start_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
configapi "github.com/openshift/origin/pkg/cmd/server/api"
configapilatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
"github.com/openshift/origin/pkg/cmd/server/api/validation"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/docker"
utilflags "github.com/openshift/origin/pkg/cmd/util/flags"
"github.com/openshift/origin/pkg/version"
Expand Down Expand Up @@ -257,7 +258,7 @@ func (o NodeOptions) CreateNodeConfig() error {
APIServerCAFiles: []string{admin.DefaultCABundleFile(o.NodeArgs.MasterCertDir)},

NodeClientCAFile: getSignerOptions.CertFile,
Output: o.Output,
Output: cmdutil.NewGLogWriterV(3),
}

if err := createNodeConfigOptions.Validate(nil); err != nil {
Expand Down
26 changes: 25 additions & 1 deletion pkg/cmd/util/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package util

import "github.com/golang/glog"
import (
"io"

"github.com/golang/glog"
)

// GetLogLevel returns the current glog log level
func GetLogLevel() (level int) {
Expand All @@ -11,3 +15,23 @@ func GetLogLevel() (level int) {
}
return
}

// NewGLogWriterV returns a new Writer that delegates to `glog.Info` at the
// desired level of verbosity
func NewGLogWriterV(level int) io.Writer {
return &gLogWriter{
level: glog.Level(level),
}
}

// gLogWriter is a Writer that writes by delegating to `glog.Info`
type gLogWriter struct {
// level is the default level to log at
level glog.Level
}

func (w *gLogWriter) Write(p []byte) (n int, err error) {
glog.V(w.level).InfoDepth(2, string(p))

return len(p), nil
}

0 comments on commit 1b7ba72

Please sign in to comment.