mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +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 {
|
||||
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
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ func getDefaultCNINetwork(confDir string, binDirs []string) (*cniNetwork, error)
|
||||
// all plugins of this config exist on disk
|
||||
caps, err := cniConfig.ValidateNetworkList(context.TODO(), confList)
|
||||
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
|
||||
}
|
||||
|
||||
@ -462,3 +462,13 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string
|
||||
|
||||
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