Skip to content

Commit

Permalink
Merge pull request #563 from k82cn/glog_klog
Browse files Browse the repository at this point in the history
Update to klog.
  • Loading branch information
k82cn authored Nov 27, 2019
2 parents 024f005 + ba3f278 commit f21a227
Show file tree
Hide file tree
Showing 59 changed files with 519 additions and 2,092 deletions.
9 changes: 0 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ required = [
"k8s.io/code-generator/cmd/defaulter-gen",
]

[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/onsi/ginkgo"
version = "1.7.0"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ generate-code:
./hack/update-gencode.sh

unit-test:
go clean -testcache
go list ./... | grep -v e2e | xargs go test -v -race

e2e-test-kind:
Expand Down
11 changes: 5 additions & 6 deletions cmd/admission/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ import (
"flag"
"fmt"

"github.com/golang/glog"

"k8s.io/api/admissionregistration/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
admissionregistrationv1beta1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1"
"k8s.io/klog"
)

const (
Expand Down Expand Up @@ -235,13 +234,13 @@ func registerMutateWebhook(client admissionregistrationv1beta1.MutatingWebhookCo
return err
}
if err == nil && existing != nil {
glog.Infof("Updating MutatingWebhookConfiguration %v", hook)
klog.Infof("Updating MutatingWebhookConfiguration %v", hook)
existing.Webhooks = hook.Webhooks
if _, err := client.Update(existing); err != nil {
return err
}
} else {
glog.Infof("Creating MutatingWebhookConfiguration %v", hook)
klog.Infof("Creating MutatingWebhookConfiguration %v", hook)
if _, err := client.Create(&hook); err != nil {
return err
}
Expand All @@ -259,12 +258,12 @@ func registerValidateWebhook(client admissionregistrationv1beta1.ValidatingWebho
}
if err == nil && existing != nil {
existing.Webhooks = hook.Webhooks
glog.Infof("Updating ValidatingWebhookConfiguration %v", hook)
klog.Infof("Updating ValidatingWebhookConfiguration %v", hook)
if _, err := client.Update(existing); err != nil {
return err
}
} else {
glog.Infof("Creating ValidatingWebhookConfiguration %v", hook)
klog.Infof("Creating ValidatingWebhookConfiguration %v", hook)
if _, err := client.Create(&hook); err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/admission/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package app
import (
"crypto/tls"

"github.com/golang/glog"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/klog"

"volcano.sh/volcano/cmd/admission/app/options"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)
Expand All @@ -31,7 +31,7 @@ import (
func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return clientset
}
Expand All @@ -40,7 +40,7 @@ func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
func GetVolcanoClient(restConfig *rest.Config) *versioned.Clientset {
clientset, err := versioned.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return clientset
}
Expand All @@ -52,7 +52,7 @@ func ConfigTLS(config *options.Config, restConfig *rest.Config) *tls.Config {
if len(config.CertFile) != 0 && len(config.KeyFile) != 0 {
sCert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}

return &tls.Config{
Expand All @@ -63,14 +63,14 @@ func ConfigTLS(config *options.Config, restConfig *rest.Config) *tls.Config {
if len(restConfig.CertData) != 0 && len(restConfig.KeyData) != 0 {
sCert, err := tls.X509KeyPair(restConfig.CertData, restConfig.KeyData)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}

return &tls.Config{
Certificates: []tls.Certificate{sCert},
}
}

glog.Fatal("tls: failed to find any tls config data")
klog.Fatal("tls: failed to find any tls config data")
return &tls.Config{}
}
15 changes: 7 additions & 8 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"strconv"
"syscall"

"github.com/golang/glog"

"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

"volcano.sh/volcano/cmd/admission/app"
"volcano.sh/volcano/cmd/admission/app/options"
Expand Down Expand Up @@ -55,13 +54,13 @@ func main() {
http.HandleFunc(admission.MutateJobPath, serveMutateJobs)

if err := config.CheckPortOrDie(); err != nil {
glog.Fatalf("Configured port is invalid: %v", err)
klog.Fatalf("Configured port is invalid: %v", err)
}
addr := ":" + strconv.Itoa(config.Port)

restConfig, err := clientcmd.BuildConfigFromFlags(config.Master, config.Kubeconfig)
if err != nil {
glog.Fatalf("Unable to build k8s config: %v", err)
klog.Fatalf("Unable to build k8s config: %v", err)
}

admission.VolcanoClientSet = app.GetVolcanoClient(restConfig)
Expand All @@ -70,12 +69,12 @@ func main() {

caBundle, err := ioutil.ReadFile(config.CaCertFile)
if err != nil {
glog.Fatalf("Unable to read cacert file: %v", err)
klog.Fatalf("Unable to read cacert file: %v", err)
}

err = options.RegisterWebhooks(config, app.GetClient(restConfig), caBundle)
if err != nil {
glog.Fatalf("Unable to register webhook configs: %v", err)
klog.Fatalf("Unable to register webhook configs: %v", err)
}

stopChannel := make(chan os.Signal)
Expand All @@ -89,15 +88,15 @@ func main() {
go func() {
err = server.ListenAndServeTLS("", "")
if err != nil && err != http.ErrServerClosed {
glog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
klog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
close(webhookServeError)
}
}()

select {
case <-stopChannel:
if err := server.Close(); err != nil {
glog.Fatalf("Close admission server failed: %v", err)
klog.Fatalf("Close admission server failed: %v", err)
}
return
case <-webhookServeError:
Expand Down
10 changes: 6 additions & 4 deletions cmd/cli/vcctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"os"
"time"

"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"

"volcano.sh/volcano/pkg/version"
)
Expand All @@ -34,9 +34,11 @@ var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum
func main() {
// flag.InitFlags()

// The default glog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(glog.Flush, *logFlushFreq, wait.NeverStop)
defer glog.Flush()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vcctl",
Expand Down
4 changes: 2 additions & 2 deletions cmd/controllers/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"time"

"github.com/golang/glog"
"k8s.io/klog"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/uuid"
Expand Down Expand Up @@ -129,7 +129,7 @@ func Run(opt *options.ServerOption) error {
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: run,
OnStoppedLeading: func() {
glog.Fatalf("leaderelection lost")
klog.Fatalf("leaderelection lost")
},
},
})
Expand Down
9 changes: 5 additions & 4 deletions cmd/controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"os"
"time"

"github.com/golang/glog"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/klog"

"volcano.sh/volcano/cmd/controllers/app"
"volcano.sh/volcano/cmd/controllers/app/options"
Expand All @@ -38,6 +38,7 @@ func main() {
s.AddFlags(pflag.CommandLine)

flag.InitFlags()
klog.InitFlags(nil)

if s.PrintVersion {
version.PrintVersionAndExit()
Expand All @@ -46,9 +47,9 @@ func main() {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
// The default glog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(glog.Flush, *logFlushFreq, wait.NeverStop)
defer glog.Flush()
// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

if err := app.Run(s); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/scheduler/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"time"

"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus/promhttp"

"volcano.sh/volcano/cmd/scheduler/app/options"
Expand All @@ -36,6 +35,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/klog"

// Register gcp auth
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Expand Down Expand Up @@ -95,7 +95,7 @@ func Run(opt *options.ServerOption) error {

go func() {
http.Handle("/metrics", promhttp.Handler())
glog.Fatalf("Prometheus Http Server failed %s", http.ListenAndServe(opt.ListenAddress, nil))
klog.Fatalf("Prometheus Http Server failed %s", http.ListenAndServe(opt.ListenAddress, nil))
}()

if err := helpers.StartHealthz(opt.HealthzBindAddress, "volcano-scheduler"); err != nil {
Expand Down Expand Up @@ -149,7 +149,7 @@ func Run(opt *options.ServerOption) error {
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: run,
OnStoppedLeading: func() {
glog.Fatalf("leaderelection lost")
klog.Fatalf("leaderelection lost")
},
},
})
Expand Down
8 changes: 5 additions & 3 deletions cmd/scheduler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
// init pprof server
_ "net/http/pprof"

"github.com/golang/glog"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/klog"

"volcano.sh/volcano/cmd/scheduler/app"
"volcano.sh/volcano/cmd/scheduler/app/options"
Expand All @@ -46,6 +46,8 @@ var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

klog.InitFlags(nil)

s := options.NewServerOption()
s.AddFlags(pflag.CommandLine)
s.RegisterOptions()
Expand All @@ -56,8 +58,8 @@ func main() {
os.Exit(1)
}

go wait.Until(glog.Flush, *logFlushFreq, wait.NeverStop)
defer glog.Flush()
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

if err := app.Run(s); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/admission/admission_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package admission
import (
"fmt"

"github.com/golang/glog"
"github.com/hashicorp/go-multierror"

"k8s.io/api/admission/v1beta1"
Expand All @@ -29,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/apis/core/validation"

batchv1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
Expand Down Expand Up @@ -97,7 +97,7 @@ func addToScheme(scheme *runtime.Scheme) {

//ToAdmissionResponse updates the admission response with the input error
func ToAdmissionResponse(err error) *v1beta1.AdmissionResponse {
glog.Error(err)
klog.Error(err)
return &v1beta1.AdmissionResponse{
Result: &metav1.Status{
Message: err.Error(),
Expand All @@ -120,7 +120,7 @@ func DecodeJob(object runtime.RawExtension, resource metav1.GroupVersionResource
if _, _, err := deserializer.Decode(raw, nil, &job); err != nil {
return job, err
}
glog.V(3).Infof("the job struct is %+v", job)
klog.V(3).Infof("the job struct is %+v", job)

return job, nil
}
Expand Down
Loading

0 comments on commit f21a227

Please sign in to comment.