Migrate to structured logging (klog)
This commit is contained in:
parent
93ac8d5a21
commit
108637bb1c
31 changed files with 161 additions and 171 deletions
|
|
@ -187,7 +187,7 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
|||
flag.CommandLine.Parse([]string{})
|
||||
|
||||
pflag.VisitAll(func(flag *pflag.Flag) {
|
||||
klog.V(2).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
|
||||
klog.V(2).InfoS("FLAG", flag.Name, flag.Value)
|
||||
})
|
||||
|
||||
if *showVersion {
|
||||
|
|
@ -202,12 +202,12 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
|||
}
|
||||
|
||||
if *ingressClass != "" {
|
||||
klog.Infof("Watching for Ingress class: %s", *ingressClass)
|
||||
klog.InfoS("Watching for Ingress", "class", *ingressClass)
|
||||
|
||||
if *ingressClass != class.DefaultClass {
|
||||
klog.Warningf("Only Ingresses with class %q will be processed by this Ingress controller", *ingressClass)
|
||||
} else {
|
||||
klog.Warning("Ingresses with an empty class will also be processed by this Ingress controller", *ingressClass)
|
||||
klog.Warning("Ingresses with an empty class will also be processed by this Ingress controller")
|
||||
}
|
||||
|
||||
class.IngressClass = *ingressClass
|
||||
|
|
@ -248,10 +248,6 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
|||
return false, nil, fmt.Errorf("port %v is already in use. Please check the flag --ssl-passthrough-proxy-port", *sslProxyPort)
|
||||
}
|
||||
|
||||
if !*enableSSLChainCompletion {
|
||||
klog.Warningf("SSL certificate chain completion is disabled (--enable-ssl-chain-completion=false)")
|
||||
}
|
||||
|
||||
if *publishSvc != "" && *publishStatusAddress != "" {
|
||||
return false, nil, fmt.Errorf("flags --publish-service and --publish-status-address are mutually exclusive")
|
||||
}
|
||||
|
|
@ -307,9 +303,9 @@ https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-g
|
|||
if err := nginx.ValidateGeoLite2DBEditions(); err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
klog.Info("downloading maxmind GeoIP2 databases...")
|
||||
klog.InfoS("downloading maxmind GeoIP2 databases")
|
||||
if err := nginx.DownloadGeoLite2DB(); err != nil {
|
||||
klog.Errorf("unexpected error downloading GeoIP2 database: %v", err)
|
||||
klog.ErrorS(err, "unexpected error downloading GeoIP2 database")
|
||||
}
|
||||
config.MaxmindEditionFiles = nginx.MaxmindEditionFiles
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func main() {
|
|||
klog.Fatal(err)
|
||||
}
|
||||
|
||||
klog.Infof("Validated %v as the default backend.", conf.DefaultService)
|
||||
klog.InfoS("Valid default backend", "service", conf.DefaultService)
|
||||
}
|
||||
|
||||
if len(conf.PublishService) > 0 {
|
||||
|
|
@ -102,7 +102,7 @@ func main() {
|
|||
}
|
||||
|
||||
conf.FakeCertificate = ssl.GetFakeSSLCert()
|
||||
klog.Infof("SSL fake certificate created %v", conf.FakeCertificate.PemFileName)
|
||||
klog.InfoS("SSL fake certificate created", "file", conf.FakeCertificate.PemFileName)
|
||||
|
||||
k8s.IsNetworkingIngressAvailable, k8s.IsIngressV1Ready = k8s.NetworkingIngressAvailable(kubeClient)
|
||||
if !k8s.IsNetworkingIngressAvailable {
|
||||
|
|
@ -110,7 +110,7 @@ func main() {
|
|||
}
|
||||
|
||||
if k8s.IsIngressV1Ready {
|
||||
klog.Infof("Enabling new Ingress features available since Kubernetes v1.18")
|
||||
klog.InfoS("Enabling new Ingress features available since Kubernetes v1.18")
|
||||
k8s.IngressClass, err = kubeClient.NetworkingV1beta1().IngressClasses().
|
||||
Get(context.TODO(), class.IngressClass, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
|
|
@ -119,7 +119,7 @@ func main() {
|
|||
klog.Fatalf("Error searching IngressClass: %v", err)
|
||||
}
|
||||
|
||||
klog.Errorf("Unexpected error searching IngressClass: %v", err)
|
||||
klog.ErrorS(err, "Searching IngressClass", "class", class.IngressClass)
|
||||
}
|
||||
|
||||
klog.Warningf("No IngressClass resource with name %v found. Only annotation will be used.", class.IngressClass)
|
||||
|
|
@ -181,18 +181,18 @@ func handleSigterm(ngx *controller.NGINXController, exit exiter) {
|
|||
signalChan := make(chan os.Signal, 1)
|
||||
signal.Notify(signalChan, syscall.SIGTERM)
|
||||
<-signalChan
|
||||
klog.Info("Received SIGTERM, shutting down")
|
||||
klog.InfoS("Received SIGTERM, shutting down")
|
||||
|
||||
exitCode := 0
|
||||
if err := ngx.Stop(); err != nil {
|
||||
klog.Infof("Error during shutdown: %v", err)
|
||||
klog.Warningf("Error during shutdown: %v", err)
|
||||
exitCode = 1
|
||||
}
|
||||
|
||||
klog.Info("Handled quit, awaiting Pod deletion")
|
||||
klog.InfoS("Handled quit, awaiting Pod deletion")
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
klog.Infof("Exiting with %v", exitCode)
|
||||
klog.InfoS("Exiting", "code", exitCode)
|
||||
exit(exitCode)
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ func createApiserverClient(apiserverHost, rootCAFile, kubeConfig string) (*kuber
|
|||
tlsClientConfig := rest.TLSClientConfig{}
|
||||
|
||||
if _, err := certutil.NewPool(rootCAFile); err != nil {
|
||||
klog.Errorf("Expected to load root CA config from %s, but got err: %v", rootCAFile, err)
|
||||
klog.ErrorS(err, "Loading CA config", "file", rootCAFile)
|
||||
} else {
|
||||
tlsClientConfig.CAFile = rootCAFile
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ func createApiserverClient(apiserverHost, rootCAFile, kubeConfig string) (*kuber
|
|||
cfg.TLSClientConfig = tlsClientConfig
|
||||
}
|
||||
|
||||
klog.Infof("Creating API client for %s", cfg.Host)
|
||||
klog.InfoS("Creating API client", "host", cfg.Host)
|
||||
|
||||
client, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
|
|
@ -253,7 +253,7 @@ func createApiserverClient(apiserverHost, rootCAFile, kubeConfig string) (*kuber
|
|||
|
||||
var lastErr error
|
||||
retries := 0
|
||||
klog.V(2).Info("Trying to discover Kubernetes version")
|
||||
klog.V(2).InfoS("Trying to discover Kubernetes version")
|
||||
err = wait.ExponentialBackoff(defaultRetry, func() (bool, error) {
|
||||
v, err = client.Discovery().ServerVersion()
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ func createApiserverClient(apiserverHost, rootCAFile, kubeConfig string) (*kuber
|
|||
}
|
||||
|
||||
lastErr = err
|
||||
klog.V(2).Infof("Unexpected error discovering Kubernetes version (attempt %v): %v", retries, err)
|
||||
klog.V(2).ErrorS(err, "Unexpected error discovering Kubernetes version", "attempt", retries)
|
||||
retries++
|
||||
return false, nil
|
||||
})
|
||||
|
|
@ -277,8 +277,14 @@ func createApiserverClient(apiserverHost, rootCAFile, kubeConfig string) (*kuber
|
|||
klog.Warningf("Initial connection to the Kubernetes API server was retried %d times.", retries)
|
||||
}
|
||||
|
||||
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)
|
||||
klog.InfoS("Running in Kubernetes cluster",
|
||||
"major", v.Major,
|
||||
"minor", v.Minor,
|
||||
"git", v.GitVersion,
|
||||
"state", v.GitTreeState,
|
||||
"commit", v.GitCommit,
|
||||
"platform", v.Platform,
|
||||
)
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
|
@ -310,7 +316,6 @@ func registerMetrics(reg *prometheus.Registry, mux *http.ServeMux) {
|
|||
promhttp.HandlerFor(reg, promhttp.HandlerOpts{}),
|
||||
),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func registerProfiler() {
|
||||
|
|
@ -355,7 +360,7 @@ func checkService(key string, kubeClient *kubernetes.Clientset) error {
|
|||
_, err = kubeClient.CoreV1().Services(ns).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if errors.IsUnauthorized(err) || errors.IsForbidden(err) {
|
||||
return fmt.Errorf("✖ The cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally.")
|
||||
return fmt.Errorf("✖ the cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally")
|
||||
}
|
||||
|
||||
if errors.IsNotFound(err) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import (
|
|||
func main() {
|
||||
err := exec.Command("bash", "-c", "pkill -SIGTERM -f nginx-ingress-controller").Run()
|
||||
if err != nil {
|
||||
klog.Errorf("unexpected error terminating ingress controller: %v", err)
|
||||
klog.ErrorS(err, "terminating ingress controller")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue