Skip to content

Commit 51d6429

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#45658 from zhangxiaoyu-zidif/add-strong-to-parsepodfulname
Automatic merge from submit-queue (batch tested with PRs 41331, 45591, 45600, 45176, 45658) ParsePodFullName():code robustness **What this PR does / why we need it**: ParsePodFullName():code robustness if pod name or namespace name is null, the function can handle it. Meanwhile update unit test **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
2 parents cb26eb6 + 65080ea commit 51d6429

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pkg/kubelet/container/runtime.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ func BuildPodFullName(name, namespace string) string {
608608
// Parse the pod full name.
609609
func ParsePodFullName(podFullName string) (string, string, error) {
610610
parts := strings.Split(podFullName, "_")
611-
if len(parts) != 2 {
611+
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
612612
return "", "", fmt.Errorf("failed to parse the pod full name %q", podFullName)
613613
}
614614
return parts[0], parts[1], nil

pkg/kubelet/pod/mirror_client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestParsePodFullName(t *testing.T) {
3232
"bar.org_foo.com": {Name: "bar.org", Namespace: "foo.com"},
3333
"bar-bar_foo": {Name: "bar-bar", Namespace: "foo"},
3434
}
35-
failedCases := []string{"barfoo", "bar_foo_foo", ""}
35+
failedCases := []string{"barfoo", "bar_foo_foo", "", "bar_", "_foo"}
3636

3737
for podFullName, expected := range successfulCases {
3838
name, namespace, err := kubecontainer.ParsePodFullName(podFullName)

0 commit comments

Comments
 (0)