mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
migrate cmd/kube-proxy/app logs to structured logging
This commit is contained in:
parent
33aba7ee02
commit
38239d3025
@ -49,7 +49,7 @@ func (rct realConntracker) SetMax(max int) error {
|
||||
if err := rct.setIntSysCtl("nf_conntrack_max", max); err != nil {
|
||||
return err
|
||||
}
|
||||
klog.Infof("Setting nf_conntrack_max to %d", max)
|
||||
klog.InfoS("Setting nf_conntrack_max", "nf_conntrack_max", max)
|
||||
|
||||
// Linux does not support writing to /sys/module/nf_conntrack/parameters/hashsize
|
||||
// when the writer process is not in the initial network namespace
|
||||
@ -80,7 +80,7 @@ func (rct realConntracker) SetMax(max int) error {
|
||||
return errReadOnlySysFS
|
||||
}
|
||||
// TODO: generify this and sysctl to a new sysfs.WriteInt()
|
||||
klog.Infof("Setting conntrack hashsize to %d", max/4)
|
||||
klog.InfoS("Setting conntrack hashsize", "conntrack hashsize", max/4)
|
||||
return writeIntStringFile("/sys/module/nf_conntrack/parameters/hashsize", max/4)
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ func (realConntracker) setIntSysCtl(name string, value int) error {
|
||||
|
||||
sys := sysctl.New()
|
||||
if val, _ := sys.GetSysctl(entry); val != value {
|
||||
klog.Infof("Set sysctl '%v' to %v", entry, value)
|
||||
klog.InfoS("Set sysctl", "entry", entry, "value", value)
|
||||
if err := sys.SetSysctl(entry, value); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -112,7 +112,7 @@ func isSysFSWritable() (bool, error) {
|
||||
m := mount.New("" /* default mount path */)
|
||||
mountPoints, err := m.List()
|
||||
if err != nil {
|
||||
klog.Errorf("failed to list mount points: %v", err)
|
||||
klog.ErrorS(err, "Failed to list mount points")
|
||||
return false, err
|
||||
}
|
||||
|
||||
@ -124,8 +124,7 @@ func isSysFSWritable() (bool, error) {
|
||||
if len(mountPoint.Opts) > 0 && mountPoint.Opts[0] == permWritable {
|
||||
return true, nil
|
||||
}
|
||||
klog.Errorf("sysfs is not writable: %+v (mount options are %v)",
|
||||
mountPoint, mountPoint.Opts)
|
||||
klog.ErrorS(nil, "Sysfs is not writable", "mountPoint", mountPoint, "mountOptions", mountPoint.Opts)
|
||||
return false, errReadOnlySysFS
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ func NewOptions() *Options {
|
||||
// Complete completes all the required options.
|
||||
func (o *Options) Complete() error {
|
||||
if len(o.ConfigFile) == 0 && len(o.WriteConfigTo) == 0 {
|
||||
klog.Warning("WARNING: all flags other than --config, --write-config-to, and --cleanup are deprecated. Please begin using a config file ASAP.")
|
||||
klog.InfoS("WARNING: all flags other than --config, --write-config-to, and --cleanup are deprecated. Please begin using a config file ASAP")
|
||||
o.config.HealthzBindAddress = addressFromDeprecatedFlags(o.config.HealthzBindAddress, o.healthzPort)
|
||||
o.config.MetricsBindAddress = addressFromDeprecatedFlags(o.config.MetricsBindAddress, o.metricsPort)
|
||||
}
|
||||
@ -366,7 +366,7 @@ func (o *Options) writeConfigFile() (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
klog.Infof("Wrote configuration to: %s\n", o.WriteConfigTo)
|
||||
klog.InfoS("Wrote configuration", "WriteConfigTo", o.WriteConfigTo)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -432,7 +432,7 @@ func (o *Options) loadConfig(data []byte) (*kubeproxyconfig.KubeProxyConfigurati
|
||||
}
|
||||
|
||||
// Continue with the v1alpha1 object that was decoded leniently, but emit a warning.
|
||||
klog.Warningf("using lenient decoding as strict decoding failed: %v", err)
|
||||
klog.InfoS("Using lenient decoding as strict decoding failed", "err", err)
|
||||
}
|
||||
|
||||
proxyConfig, ok := configObj.(*kubeproxyconfig.KubeProxyConfiguration)
|
||||
@ -479,15 +479,21 @@ with the apiserver API to configure the proxy.`,
|
||||
cliflag.PrintFlags(cmd.Flags())
|
||||
|
||||
if err := initForOS(opts.WindowsService); err != nil {
|
||||
klog.Fatalf("failed OS init: %v", err)
|
||||
klog.ErrorS(err, "Failed OS init")
|
||||
// ACTION REQUIRED: Exit code changed from 255 to 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := opts.Complete(); err != nil {
|
||||
klog.Fatalf("failed complete: %v", err)
|
||||
klog.ErrorS(err, "Failed complete")
|
||||
// ACTION REQUIRED: Exit code changed from 255 to 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := opts.Validate(); err != nil {
|
||||
klog.Fatalf("failed validate: %v", err)
|
||||
klog.ErrorS(err, "Failed validate")
|
||||
// ACTION REQUIRED: Exit code changed from 255 to 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := opts.Run(); err != nil {
|
||||
@ -507,7 +513,9 @@ with the apiserver API to configure the proxy.`,
|
||||
var err error
|
||||
opts.config, err = opts.ApplyDefaults(opts.config)
|
||||
if err != nil {
|
||||
klog.Fatalf("unable to create flag defaults: %v", err)
|
||||
klog.ErrorS(err, "Unable to create flag defaults")
|
||||
// ACTION REQUIRED: Exit code changed from 255 to 1
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
opts.AddFlags(cmd.Flags())
|
||||
@ -550,7 +558,7 @@ func createClients(config componentbaseconfig.ClientConnectionConfiguration, mas
|
||||
var err error
|
||||
|
||||
if len(config.Kubeconfig) == 0 && len(masterOverride) == 0 {
|
||||
klog.Info("Neither kubeconfig file nor master URL was specified. Falling back to in-cluster config.")
|
||||
klog.InfoS("Neither kubeconfig file nor master URL was specified. Falling back to in-cluster config")
|
||||
kubeConfig, err = rest.InClusterConfig()
|
||||
} else {
|
||||
// This creates a client, first loading any specified kubeconfig
|
||||
@ -589,7 +597,7 @@ func serveHealthz(hz healthcheck.ProxierHealthUpdater, errCh chan error) {
|
||||
fn := func() {
|
||||
err := hz.Run()
|
||||
if err != nil {
|
||||
klog.Errorf("healthz server failed: %v", err)
|
||||
klog.ErrorS(err, "Healthz server failed")
|
||||
if errCh != nil {
|
||||
errCh <- fmt.Errorf("healthz server failed: %v", err)
|
||||
// if in hardfail mode, never retry again
|
||||
@ -597,7 +605,7 @@ func serveHealthz(hz healthcheck.ProxierHealthUpdater, errCh chan error) {
|
||||
<-blockCh
|
||||
}
|
||||
} else {
|
||||
klog.Errorf("healthz server returned without error")
|
||||
klog.ErrorS(nil, "Healthz server returned without error")
|
||||
}
|
||||
}
|
||||
go wait.Until(fn, 5*time.Second, wait.NeverStop)
|
||||
@ -646,14 +654,14 @@ func serveMetrics(bindAddress, proxyMode string, enableProfiling bool, errCh cha
|
||||
// TODO: At the moment, Run() cannot return a nil error, otherwise it's caller will never exit. Update callers of Run to handle nil errors.
|
||||
func (s *ProxyServer) Run() error {
|
||||
// To help debugging, immediately log version
|
||||
klog.Infof("Version: %+v", version.Get())
|
||||
klog.InfoS("Version info", "version", version.Get())
|
||||
|
||||
// TODO(vmarmol): Use container config for this.
|
||||
var oomAdjuster *oom.OOMAdjuster
|
||||
if s.OOMScoreAdj != nil {
|
||||
oomAdjuster = oom.NewOOMAdjuster()
|
||||
if err := oomAdjuster.ApplyOOMScoreAdj(0, int(*s.OOMScoreAdj)); err != nil {
|
||||
klog.V(2).Info(err)
|
||||
klog.V(2).InfoS("Failed to apply OOMScore", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -792,10 +800,10 @@ func getConntrackMax(config kubeproxyconfig.KubeProxyConntrackConfiguration) (in
|
||||
}
|
||||
scaled := int(*config.MaxPerCore) * detectNumCPU()
|
||||
if scaled > floor {
|
||||
klog.V(3).Infof("getConntrackMax: using scaled conntrack-max-per-core")
|
||||
klog.V(3).InfoS("GetConntrackMax: using scaled conntrack-max-per-core")
|
||||
return scaled, nil
|
||||
}
|
||||
klog.V(3).Infof("getConntrackMax: using conntrack-min")
|
||||
klog.V(3).InfoS("GetConntrackMax: using conntrack-min")
|
||||
return floor, nil
|
||||
}
|
||||
return 0, nil
|
||||
|
@ -106,7 +106,7 @@ func newProxyServer(
|
||||
ipsetInterface = utilipset.New(execer)
|
||||
canUseIPVS, err := ipvs.CanUseIPVSProxier(kernelHandler, ipsetInterface, config.IPVS.Scheduler)
|
||||
if string(config.Mode) == proxyModeIPVS && err != nil {
|
||||
klog.Errorf("Can't use the IPVS proxier: %v", err)
|
||||
klog.ErrorS(err, "Can't use the IPVS proxier")
|
||||
}
|
||||
|
||||
if canUseIPVS {
|
||||
@ -137,7 +137,7 @@ func newProxyServer(
|
||||
}
|
||||
|
||||
nodeIP := detectNodeIP(client, hostname, config.BindAddress)
|
||||
klog.Infof("Detected node IP %s", nodeIP.String())
|
||||
klog.InfoS("Detected node IP", "address", nodeIP.String())
|
||||
|
||||
// Create event recorder
|
||||
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1()})
|
||||
@ -166,15 +166,15 @@ func newProxyServer(
|
||||
|
||||
var nodeInfo *v1.Node
|
||||
if detectLocalMode == proxyconfigapi.LocalModeNodeCIDR {
|
||||
klog.Infof("Watching for node %s, awaiting podCIDR allocation", hostname)
|
||||
klog.InfoS("Watching for node, awaiting podCIDR allocation", "hostname", hostname)
|
||||
nodeInfo, err = waitForPodCIDR(client, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
klog.Infof("NodeInfo PodCIDR: %v, PodCIDRs: %v", nodeInfo.Spec.PodCIDR, nodeInfo.Spec.PodCIDRs)
|
||||
klog.InfoS("NodeInfo", "PodCIDR", nodeInfo.Spec.PodCIDR, "PodCIDRs", nodeInfo.Spec.PodCIDRs)
|
||||
}
|
||||
|
||||
klog.V(2).Info("DetectLocalMode: '", string(detectLocalMode), "'")
|
||||
klog.V(2).InfoS("DetectLocalMode", "LocalMode", string(detectLocalMode))
|
||||
|
||||
primaryProtocol := utiliptables.ProtocolIPv4
|
||||
if utilsnet.IsIPv6(nodeIP) {
|
||||
@ -209,14 +209,14 @@ func newProxyServer(
|
||||
}
|
||||
|
||||
if proxyMode == proxyModeIPTables {
|
||||
klog.V(0).Info("Using iptables Proxier.")
|
||||
klog.V(0).InfoS("Using iptables Proxier")
|
||||
if config.IPTables.MasqueradeBit == nil {
|
||||
// MasqueradeBit must be specified or defaulted.
|
||||
return nil, fmt.Errorf("unable to read IPTables MasqueradeBit from config")
|
||||
}
|
||||
|
||||
if dualStack {
|
||||
klog.V(0).Info("creating dualStackProxier for iptables.")
|
||||
klog.V(0).InfoS("Creating dualStackProxier for iptables")
|
||||
|
||||
// Always ordered to match []ipt
|
||||
var localDetectors [2]proxyutiliptables.LocalTrafficDetector
|
||||
@ -271,9 +271,9 @@ func newProxyServer(
|
||||
}
|
||||
proxymetrics.RegisterMetrics()
|
||||
} else if proxyMode == proxyModeIPVS {
|
||||
klog.V(0).Info("Using ipvs Proxier.")
|
||||
klog.V(0).InfoS("Using ipvs Proxier")
|
||||
if dualStack {
|
||||
klog.V(0).Info("creating dualStackProxier for ipvs.")
|
||||
klog.V(0).InfoS("Creating dualStackProxier for ipvs")
|
||||
|
||||
nodeIPs := nodeIPTuple(config.BindAddress)
|
||||
|
||||
@ -345,7 +345,7 @@ func newProxyServer(
|
||||
}
|
||||
proxymetrics.RegisterMetrics()
|
||||
} else {
|
||||
klog.V(0).Info("Using userspace Proxier.")
|
||||
klog.V(0).InfoS("Using userspace Proxier")
|
||||
|
||||
// TODO this has side effects that should only happen when Run() is invoked.
|
||||
proxier, err = userspace.NewProxier(
|
||||
@ -446,7 +446,7 @@ func getDetectLocalMode(config *proxyconfigapi.KubeProxyConfiguration) (proxycon
|
||||
if strings.TrimSpace(mode.String()) != "" {
|
||||
return mode, fmt.Errorf("unknown detect-local-mode: %v", mode)
|
||||
}
|
||||
klog.V(4).Info("Defaulting detect-local-mode to ", string(proxyconfigapi.LocalModeClusterCIDR))
|
||||
klog.V(4).InfoS("Defaulting detect-local-mode", "LocalModeClusterCIDR", string(proxyconfigapi.LocalModeClusterCIDR))
|
||||
return proxyconfigapi.LocalModeClusterCIDR, nil
|
||||
}
|
||||
}
|
||||
@ -455,18 +455,18 @@ func getLocalDetector(mode proxyconfigapi.LocalMode, config *proxyconfigapi.Kube
|
||||
switch mode {
|
||||
case proxyconfigapi.LocalModeClusterCIDR:
|
||||
if len(strings.TrimSpace(config.ClusterCIDR)) == 0 {
|
||||
klog.Warning("detect-local-mode set to ClusterCIDR, but no cluster CIDR defined")
|
||||
klog.InfoS("Detect-local-mode set to ClusterCIDR, but no cluster CIDR defined")
|
||||
break
|
||||
}
|
||||
return proxyutiliptables.NewDetectLocalByCIDR(config.ClusterCIDR, ipt)
|
||||
case proxyconfigapi.LocalModeNodeCIDR:
|
||||
if len(strings.TrimSpace(nodeInfo.Spec.PodCIDR)) == 0 {
|
||||
klog.Warning("detect-local-mode set to NodeCIDR, but no PodCIDR defined at node")
|
||||
klog.InfoS("Detect-local-mode set to NodeCIDR, but no PodCIDR defined at node")
|
||||
break
|
||||
}
|
||||
return proxyutiliptables.NewDetectLocalByCIDR(nodeInfo.Spec.PodCIDR, ipt)
|
||||
}
|
||||
klog.V(0).Info("detect-local-mode: ", string(mode), " , defaulting to no-op detect-local")
|
||||
klog.V(0).InfoS("Defaulting to no-op detect-local", "detect-local-mode", string(mode))
|
||||
return proxyutiliptables.NewNoOpLocalDetector(), nil
|
||||
}
|
||||
|
||||
@ -476,14 +476,14 @@ func getDualStackLocalDetectorTuple(mode proxyconfigapi.LocalMode, config *proxy
|
||||
switch mode {
|
||||
case proxyconfigapi.LocalModeClusterCIDR:
|
||||
if len(strings.TrimSpace(config.ClusterCIDR)) == 0 {
|
||||
klog.Warning("detect-local-mode set to ClusterCIDR, but no cluster CIDR defined")
|
||||
klog.InfoS("Detect-local-mode set to ClusterCIDR, but no cluster CIDR defined")
|
||||
break
|
||||
}
|
||||
|
||||
clusterCIDRs := cidrTuple(config.ClusterCIDR)
|
||||
|
||||
if len(strings.TrimSpace(clusterCIDRs[0])) == 0 {
|
||||
klog.Warning("detect-local-mode set to ClusterCIDR, but no IPv4 cluster CIDR defined, defaulting to no-op detect-local for IPv4")
|
||||
klog.InfoS("Detect-local-mode set to ClusterCIDR, but no IPv4 cluster CIDR defined, defaulting to no-op detect-local for IPv4")
|
||||
} else {
|
||||
localDetectors[0], err = proxyutiliptables.NewDetectLocalByCIDR(clusterCIDRs[0], ipt[0])
|
||||
if err != nil { // don't loose the original error
|
||||
@ -492,14 +492,14 @@ func getDualStackLocalDetectorTuple(mode proxyconfigapi.LocalMode, config *proxy
|
||||
}
|
||||
|
||||
if len(strings.TrimSpace(clusterCIDRs[1])) == 0 {
|
||||
klog.Warning("detect-local-mode set to ClusterCIDR, but no IPv6 cluster CIDR defined, , defaulting to no-op detect-local for IPv6")
|
||||
klog.InfoS("Detect-local-mode set to ClusterCIDR, but no IPv6 cluster CIDR defined, , defaulting to no-op detect-local for IPv6")
|
||||
} else {
|
||||
localDetectors[1], err = proxyutiliptables.NewDetectLocalByCIDR(clusterCIDRs[1], ipt[1])
|
||||
}
|
||||
return localDetectors, err
|
||||
case proxyconfigapi.LocalModeNodeCIDR:
|
||||
if nodeInfo == nil || len(strings.TrimSpace(nodeInfo.Spec.PodCIDR)) == 0 {
|
||||
klog.Warning("No node info available to configure detect-local-mode NodeCIDR")
|
||||
klog.InfoS("No node info available to configure detect-local-mode NodeCIDR")
|
||||
break
|
||||
}
|
||||
// localDetectors, like ipt, need to be of the order [IPv4, IPv6], but PodCIDRs is setup so that PodCIDRs[0] == PodCIDR.
|
||||
@ -523,9 +523,9 @@ func getDualStackLocalDetectorTuple(mode proxyconfigapi.LocalMode, config *proxy
|
||||
}
|
||||
return localDetectors, err
|
||||
default:
|
||||
klog.Warningf("unknown detect-local-mode: %v", mode)
|
||||
klog.InfoS("Unknown detect-local-mode", "detect-local-mode", mode)
|
||||
}
|
||||
klog.Warning("detect-local-mode: ", string(mode), " , defaulting to no-op detect-local")
|
||||
klog.InfoS("Defaulting to no-op detect-local", "detect-local-mode", string(mode))
|
||||
return localDetectors, nil
|
||||
}
|
||||
|
||||
@ -562,7 +562,7 @@ func getProxyMode(proxyMode string, canUseIPVS bool, kcompat iptables.KernelComp
|
||||
case proxyModeIPVS:
|
||||
return tryIPVSProxy(canUseIPVS, kcompat)
|
||||
}
|
||||
klog.Warningf("Unknown proxy mode %q, assuming iptables proxy", proxyMode)
|
||||
klog.InfoS("Unknown proxy mode, assuming iptables proxy", "proxyMode", proxyMode)
|
||||
return tryIPTablesProxy(kcompat)
|
||||
}
|
||||
|
||||
@ -572,7 +572,7 @@ func tryIPVSProxy(canUseIPVS bool, kcompat iptables.KernelCompatTester) string {
|
||||
}
|
||||
|
||||
// Try to fallback to iptables before falling back to userspace
|
||||
klog.V(1).Infof("Can't use ipvs proxier, trying iptables proxier")
|
||||
klog.V(1).InfoS("Can't use ipvs proxier, trying iptables proxier")
|
||||
return tryIPTablesProxy(kcompat)
|
||||
}
|
||||
|
||||
@ -587,6 +587,6 @@ func tryIPTablesProxy(kcompat iptables.KernelCompatTester) string {
|
||||
return proxyModeIPTables
|
||||
}
|
||||
// Fallback.
|
||||
klog.V(1).Infof("Can't use iptables proxy, using userspace proxier")
|
||||
klog.V(1).InfoS("Can't use iptables proxy, using userspace proxier")
|
||||
return proxyModeUserspace
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user