Skip to content

Commit 3202bc1

Browse files
authored
Merge pull request kubernetes#83896 from mars1024/modify/cni_log
modify error output in cniNetworkPlugin
2 parents b0c26e5 + fe50e90 commit 3202bc1

File tree

1 file changed

+12
-2
lines changed
  • pkg/kubelet/dockershim/network/cni

1 file changed

+12
-2
lines changed

pkg/kubelet/dockershim/network/cni/cni.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ func getDefaultCNINetwork(confDir string, binDirs []string) (*cniNetwork, error)
191191
}
192192
}
193193
if len(confList.Plugins) == 0 {
194-
klog.Warningf("CNI config list %s has no networks, skipping", confFile)
194+
klog.Warningf("CNI config list %s has no networks, skipping", string(confList.Bytes[:maxStringLengthInLog(len(confList.Bytes))]))
195195
continue
196196
}
197197

198198
// Before using this CNI config, we have to validate it to make sure that
199199
// all plugins of this config exist on disk
200200
caps, err := cniConfig.ValidateNetworkList(context.TODO(), confList)
201201
if err != nil {
202-
klog.Warningf("Error validating CNI config %v: %v", confList, err)
202+
klog.Warningf("Error validating CNI config list %s: %v", string(confList.Bytes[:maxStringLengthInLog(len(confList.Bytes))]), err)
203203
continue
204204
}
205205

@@ -462,3 +462,13 @@ func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string
462462

463463
return rt, nil
464464
}
465+
466+
func maxStringLengthInLog(length int) int {
467+
// we allow no more than 4096-length strings to be logged
468+
const maxStringLength = 4096
469+
470+
if length < maxStringLength {
471+
return length
472+
}
473+
return maxStringLength
474+
}

0 commit comments

Comments
 (0)