Skip to content

Commit

Permalink
Migrate from glog to klog. Change some command line flags
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed Feb 12, 2019
1 parent 202b2ff commit ee83b7b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
5 changes: 0 additions & 5 deletions cmd/mysql-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ func main() {
os.Exit(1)
}

// for glog
if err := flag.Lookup("logtostderr").Value.Set("true"); err != nil {
fmt.Fprintf(os.Stderr, "failed to set glog to use stderr, err: %s", err)
}

// set logging
logf.SetLogger(customLog.ZapLogger())

Expand Down
2 changes: 1 addition & 1 deletion hack/charts/mysql-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
- --leader-election-namespace={{ .Release.Namespace }}
- --orchestrator-uri=http://{{ template "mysql-operator.orchestrator.fullname" . }}.{{ .Release.Namespace }}/api
{{- if .Values.sidecarImage }}
- --helper-image={{ .Values.sidecarImage }}
- --sidecar-image={{ .Values.sidecarImage }}
{{- end -}}
{{- range $arg := .Values.extraArgs }}
- {{ $arg }}
Expand Down
2 changes: 1 addition & 1 deletion hack/dev-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extraArgs:
- -v=3
- -v=1
- --debug

installCRDs: false
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/mysqlbackup/internal/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *jobSyncer) ensurePodSpec(in core.PodSpec) core.PodSpec {
in.RestartPolicy = core.RestartPolicyNever

in.Containers[0].Name = "backup"
in.Containers[0].Image = s.opt.HelperImage
in.Containers[0].Image = s.opt.SidecarImage
in.Containers[0].ImagePullPolicy = core.PullIfNotPresent
in.Containers[0].Args = []string{
"take-backup-to",
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/mysqlcluster/internal/syncer/statefullset.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ func (s *sfsSyncer) ensureInitContainersSpec() []core.Container {
return []core.Container{
// init container for configs
s.ensureContainer(containerInitName,
s.opt.HelperImage,
s.opt.SidecarImage,
[]string{"files-config"},
),

// clone container
s.ensureContainer(containerCloneName,
s.opt.HelperImage,
s.opt.SidecarImage,
[]string{"clone"},
),
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {

// SIDECAR container
sidecar := s.ensureContainer(containerSidecarName,
s.opt.HelperImage,
s.opt.SidecarImage,
[]string{"config-and-serve"},
)
sidecar.Ports = ensurePorts(core.ContainerPort{
Expand Down Expand Up @@ -393,7 +393,7 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {

// PT-HEARTBEAT container
heartbeat := s.ensureContainer(containerHeartBeatName,
s.opt.HelperImage,
s.opt.SidecarImage,
[]string{
"pt-heartbeat",
"--update", "--replace",
Expand Down Expand Up @@ -424,7 +424,7 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container {
command = append(command, getCliOptionsFromQueryLimits(s.cluster.Spec.QueryLimits)...)

killer := s.ensureContainer(containerKillerName,
s.opt.HelperImage,
s.opt.SidecarImage,
command,
)

Expand Down
8 changes: 4 additions & 4 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getFromEnvOrDefault(key, def string) string {

// Options is the data structure that contains information about mysql operator configuration
type Options struct {
HelperImage string
SidecarImage string

MetricsExporterImage string

Expand Down Expand Up @@ -93,13 +93,13 @@ const (
)

var (
defaultHelperImage = "quay.io/presslabs/mysql-helper:" + util.AppVersion
defaultSidecarImage = "quay.io/presslabs/mysql-operator-sidecar:" + util.AppVersion
defaultJobGraceTime = 24 * time.Hour
)

// AddFlags registers all mysql-operator needed flags
func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.HelperImage, "helper-image", defaultHelperImage,
fs.StringVar(&o.SidecarImage, "sidecar-image", defaultSidecarImage,
"The image that instrumentate mysql.")

fs.StringVar(&o.MetricsExporterImage, "metrics-exporter-image", defaultExporterImage,
Expand Down Expand Up @@ -135,7 +135,7 @@ var once sync.Once
func GetOptions() *Options {
once.Do(func() {
instance = &Options{
HelperImage: defaultHelperImage,
SidecarImage: defaultSidecarImage,
MetricsExporterImage: defaultExporterImage,

ImagePullPolicy: defaultImagePullPolicy,
Expand Down
19 changes: 13 additions & 6 deletions pkg/util/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ package log
import (
"flag"
"log"
"strconv"

"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"k8s.io/klog"
)

var debug = false
var logLevel = 0

func init() {
flag.BoolVar(&debug, "debug", false, "set logger in debug mode")
flag.BoolVar(&debug, "debug", false, "Set logger in debug mode")
flag.IntVar(&logLevel, "v", 0, "Set verbosity level")

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
klogFlags.Set("logtostderr", "true") // nolint: errcheck
klogFlags.Set("alsologtostderr", "false") // nolint: errcheck
}

// ZapLogger returns a configured logged based on command line flags -v and --debug
Expand All @@ -51,11 +58,11 @@ func ZapLogger() logr.Logger {

// get the v value from flags and then set the logger value
level := zapcore.WarnLevel
if strLevel, err := strconv.Atoi(flag.Lookup("v").Value.String()); err == nil {
if strLevel > maxLevel {
strLevel = maxLevel
if logLevel > 0 {
if logLevel > maxLevel {
logLevel = maxLevel
}
level = zapcore.Level(-1 * strLevel)
level = zapcore.Level(-1 * logLevel)
}

// set debugger level
Expand Down
1 change: 1 addition & 0 deletions test/e2e-values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extraArgs:
- -v=1
- --debug

orchestrator:
topologyPassword: password1
Expand Down

0 comments on commit ee83b7b

Please sign in to comment.