Replace glog with klog

This commit is contained in:
Manuel Alejandro de Brito Fontes 2018-12-05 13:27:55 -03:00
parent f4a4daed84
commit 2fa55eabf6
33 changed files with 353 additions and 327 deletions

View file

@ -28,7 +28,6 @@ import (
"syscall"
"time"
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -38,6 +37,7 @@ import (
"k8s.io/apiserver/pkg/server/healthz"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
"k8s.io/ingress-nginx/internal/file"
"k8s.io/ingress-nginx/internal/ingress/controller"
@ -59,6 +59,8 @@ const (
)
func main() {
klog.InitFlags(nil)
rand.Seed(time.Now().UnixNano())
fmt.Println(version.String())
@ -69,14 +71,14 @@ func main() {
}
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
nginxVersion()
fs, err := file.NewLocalFS()
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
kubeClient, err := createApiserverClient(conf.APIServerHost, conf.KubeConfigFile)
@ -87,24 +89,24 @@ func main() {
if len(conf.DefaultService) > 0 {
defSvcNs, defSvcName, err := k8s.ParseNameNS(conf.DefaultService)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
_, err = kubeClient.CoreV1().Services(defSvcNs).Get(defSvcName, metav1.GetOptions{})
if err != nil {
// TODO (antoineco): compare with error types from k8s.io/apimachinery/pkg/api/errors
if strings.Contains(err.Error(), "cannot get services in the namespace") {
glog.Fatal("✖ The cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally.")
klog.Fatal("✖ The cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally.")
}
glog.Fatalf("No service with name %v found: %v", conf.DefaultService, err)
klog.Fatalf("No service with name %v found: %v", conf.DefaultService, err)
}
glog.Infof("Validated %v as the default backend.", conf.DefaultService)
klog.Infof("Validated %v as the default backend.", conf.DefaultService)
}
if conf.Namespace != "" {
_, err = kubeClient.CoreV1().Namespaces().Get(conf.Namespace, metav1.GetOptions{})
if err != nil {
glog.Fatalf("No namespace with name %v found: %v", conf.Namespace, err)
klog.Fatalf("No namespace with name %v found: %v", conf.Namespace, err)
}
}
@ -112,7 +114,7 @@ func main() {
defCert, defKey := ssl.GetFakeSSLCert()
c, err := ssl.AddOrUpdateCertAndKey(fakeCertificate, defCert, defKey, []byte{}, fs)
if err != nil {
glog.Fatalf("Error generating self-signed certificate: %v", err)
klog.Fatalf("Error generating self-signed certificate: %v", err)
}
conf.FakeCertificatePath = c.PemFileName
@ -132,7 +134,7 @@ func main() {
if conf.EnableMetrics {
mc, err = metric.NewCollector(conf.ListenPorts.Status, reg)
if err != nil {
glog.Fatalf("Error creating prometheus collector: %v", err)
klog.Fatalf("Error creating prometheus collector: %v", err)
}
}
mc.Start()
@ -163,18 +165,18 @@ func handleSigterm(ngx *controller.NGINXController, exit exiter) {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGTERM)
<-signalChan
glog.Info("Received SIGTERM, shutting down")
klog.Info("Received SIGTERM, shutting down")
exitCode := 0
if err := ngx.Stop(); err != nil {
glog.Infof("Error during shutdown: %v", err)
klog.Infof("Error during shutdown: %v", err)
exitCode = 1
}
glog.Info("Handled quit, awaiting Pod deletion")
klog.Info("Handled quit, awaiting Pod deletion")
time.Sleep(10 * time.Second)
glog.Infof("Exiting with %v", exitCode)
klog.Infof("Exiting with %v", exitCode)
exit(exitCode)
}
@ -196,7 +198,7 @@ func createApiserverClient(apiserverHost, kubeConfig string) (*kubernetes.Client
cfg.Burst = defaultBurst
cfg.ContentType = "application/vnd.kubernetes.protobuf"
glog.Infof("Creating API client for %s", cfg.Host)
klog.Infof("Creating API client for %s", cfg.Host)
client, err := kubernetes.NewForConfig(cfg)
if err != nil {
@ -216,7 +218,7 @@ func createApiserverClient(apiserverHost, kubeConfig string) (*kubernetes.Client
var lastErr error
retries := 0
glog.V(2).Info("Trying to discover Kubernetes version")
klog.V(2).Info("Trying to discover Kubernetes version")
err = wait.ExponentialBackoff(defaultRetry, func() (bool, error) {
v, err = client.Discovery().ServerVersion()
@ -225,7 +227,7 @@ func createApiserverClient(apiserverHost, kubeConfig string) (*kubernetes.Client
}
lastErr = err
glog.V(2).Infof("Unexpected error discovering Kubernetes version (attempt %v): %v", retries, err)
klog.V(2).Infof("Unexpected error discovering Kubernetes version (attempt %v): %v", retries, err)
retries++
return false, nil
})
@ -237,10 +239,10 @@ func createApiserverClient(apiserverHost, kubeConfig string) (*kubernetes.Client
// this should not happen, warn the user
if retries > 0 {
glog.Warningf("Initial connection to the Kubernetes API server was retried %d times.", retries)
klog.Warningf("Initial connection to the Kubernetes API server was retried %d times.", retries)
}
glog.Infof("Running in Kubernetes cluster version v%v.%v (%v) - git (%v) commit %v - platform %v",
klog.Infof("Running in Kubernetes cluster version v%v.%v (%v) - git (%v) commit %v - platform %v",
v.Major, v.Minor, v.GitVersion, v.GitTreeState, v.GitCommit, v.Platform)
return client, nil
@ -248,7 +250,7 @@ func createApiserverClient(apiserverHost, kubeConfig string) (*kubernetes.Client
// Handler for fatal init errors. Prints a verbose error message and exits.
func handleFatalInitError(err error) {
glog.Fatalf("Error while initiating a connection to the Kubernetes API server. "+
klog.Fatalf("Error while initiating a connection to the Kubernetes API server. "+
"This could mean the cluster is misconfigured (e.g. it has invalid API server certificates "+
"or Service Accounts configuration). Reason: %s\n"+
"Refer to the troubleshooting guide for more information: "+
@ -266,7 +268,7 @@ func registerHandlers(mux *http.ServeMux) {
mux.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {
err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
if err != nil {
glog.Errorf("Unexpected error: %v", err)
klog.Errorf("Unexpected error: %v", err)
}
})
}
@ -312,5 +314,5 @@ func startHTTPServer(port int, mux *http.ServeMux) {
WriteTimeout: 300 * time.Second,
IdleTimeout: 120 * time.Second,
}
glog.Fatal(server.ListenAndServe())
klog.Fatal(server.ListenAndServe())
}