mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
restrict max string length in log
Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
This commit is contained in:
parent
213c378562
commit
fe50e904eb
@ -191,7 +191,7 @@ func getDefaultCNINetwork(confDir string, binDirs []string) (*cniNetwork, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(confList.Plugins) == 0 {
|
if len(confList.Plugins) == 0 {
|
||||||
klog.Warningf("CNI config list %s has no networks, skipping", string(confList.Bytes))
|
klog.Warningf("CNI config list %s has no networks, skipping", string(confList.Bytes[:maxStringLengthInLog(len(confList.Bytes))]))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ func getDefaultCNINetwork(confDir string, binDirs []string) (*cniNetwork, error)
|
|||||||
// all plugins of this config exist on disk
|
// all plugins of this config exist on disk
|
||||||
caps, err := cniConfig.ValidateNetworkList(context.TODO(), confList)
|
caps, err := cniConfig.ValidateNetworkList(context.TODO(), confList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Warningf("Error validating CNI config list %s: %v", string(confList.Bytes), err)
|
klog.Warningf("Error validating CNI config list %s: %v", string(confList.Bytes[:maxStringLengthInLog(len(confList.Bytes))]), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,3 +462,13 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string
|
|||||||
|
|
||||||
return rt, nil
|
return rt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func maxStringLengthInLog(length int) int {
|
||||||
|
// we allow no more than 4096-length strings to be logged
|
||||||
|
const maxStringLength = 4096
|
||||||
|
|
||||||
|
if length < maxStringLength {
|
||||||
|
return length
|
||||||
|
}
|
||||||
|
return maxStringLength
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user