restrict max string length in log

Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
This commit is contained in:
Bruce Ma 2019-11-05 17:52:13 +08:00
parent 213c378562
commit fe50e904eb

View File

@ -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
}