Skip to content

Commit b603a3e

Browse files
committed
fix: trim spaces from KubeletClientCertPath parts and include err in panic
Splitting on ',' without trimming caused a leading-space path when the config value used ', ' as separator, breaking cert-based kubelet client creation. Also surface the underlying error in the panic message so failures are easier to diagnose.
1 parent c40d7a9 commit b603a3e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

internal/pod/container_kubelet_sync.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ func ManagerInit(ctx *ManagerInitCtx) error {
166166
}
167167

168168
s := strings.Split(ctx.PodClientCertPath, ",")
169+
cert := strings.TrimSpace(s[0])
169170
if len(s) == 1 {
170-
ctx.podClientCertPath, ctx.podClientCertKey = s[0], s[0]
171+
ctx.podClientCertPath, ctx.podClientCertKey = cert, cert
171172
} else if len(s) >= 2 {
172-
ctx.podClientCertPath, ctx.podClientCertKey = s[0], s[1]
173+
ctx.podClientCertPath, ctx.podClientCertKey = cert, strings.TrimSpace(s[1])
173174
}
174175

175176
err := kubeletPodListPortCacheUpdate(ctx)
@@ -524,7 +525,10 @@ func kubeletConfigCacheUpdate(ctx *ManagerInitCtx) error {
524525

525526
config, err = kubeletConfigFileDefault()
526527
if err != nil {
527-
panic("we cannot find any cgroup driver of kubelet after requesting configz and default files")
528+
panic(fmt.Sprintf(
529+
"we cannot find any cgroup driver of kubelet after requesting configz and default files: %v",
530+
err,
531+
))
528532
}
529533

530534
return nil

0 commit comments

Comments
 (0)