Replace glog with klog
This commit is contained in:
parent
f4a4daed84
commit
2fa55eabf6
33 changed files with 353 additions and 327 deletions
|
|
@ -70,7 +70,8 @@ func TestFlagConflict(t *testing.T) {
|
|||
defer func() { os.Args = oldArgs }()
|
||||
os.Args = []string{"cmd", "--publish-service", "namespace/test", "--http-port", "0", "--https-port", "0", "--publish-status-address", "1.1.1.1"}
|
||||
|
||||
_, _, err := parseFlags()
|
||||
_, c, err := parseFlags()
|
||||
t.Logf("%v", c)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error parsing flags but none returned")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/klog"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
||||
|
|
@ -168,7 +168,7 @@ Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not en
|
|||
flag.CommandLine.Parse([]string{})
|
||||
|
||||
pflag.VisitAll(func(flag *pflag.Flag) {
|
||||
glog.V(2).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
klog.V(2).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
})
|
||||
|
||||
if *showVersion {
|
||||
|
|
@ -176,10 +176,10 @@ Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not en
|
|||
}
|
||||
|
||||
if *ingressClass != "" {
|
||||
glog.Infof("Watching for Ingress class: %s", *ingressClass)
|
||||
klog.Infof("Watching for Ingress class: %s", *ingressClass)
|
||||
|
||||
if *ingressClass != class.DefaultClass {
|
||||
glog.Warningf("Only Ingresses with class %q will be processed by this Ingress controller", *ingressClass)
|
||||
klog.Warningf("Only Ingresses with class %q will be processed by this Ingress controller", *ingressClass)
|
||||
}
|
||||
|
||||
class.IngressClass = *ingressClass
|
||||
|
|
@ -209,7 +209,7 @@ Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not en
|
|||
}
|
||||
|
||||
if !*enableSSLChainCompletion {
|
||||
glog.Warningf("SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)")
|
||||
klog.Warningf("SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)")
|
||||
}
|
||||
|
||||
if *enableSSLChainCompletion && *dynamicCertificatesEnabled {
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,17 +18,18 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress/controller"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/file"
|
||||
"k8s.io/ingress-nginx/internal/ingress/controller"
|
||||
)
|
||||
|
||||
func TestCreateApiserverClient(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
func nginxVersion() {
|
||||
flag := "-v"
|
||||
|
||||
if glog.V(2) {
|
||||
if klog.V(2) {
|
||||
flag = "-V"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue