Commit 51d6429a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #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 ```
parents cb26eb60 65080ea1
......@@ -608,7 +608,7 @@ func BuildPodFullName(name, namespace string) string {
// Parse the pod full name.
func ParsePodFullName(podFullName string) (string, string, error) {
parts := strings.Split(podFullName, "_")
if len(parts) != 2 {
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
return "", "", fmt.Errorf("failed to parse the pod full name %q", podFullName)
}
return parts[0], parts[1], nil
......
......@@ -32,7 +32,7 @@ func TestParsePodFullName(t *testing.T) {
"bar.org_foo.com": {Name: "bar.org", Namespace: "foo.com"},
"bar-bar_foo": {Name: "bar-bar", Namespace: "foo"},
}
failedCases := []string{"barfoo", "bar_foo_foo", ""}
failedCases := []string{"barfoo", "bar_foo_foo", "", "bar_", "_foo"}
for podFullName, expected := range successfulCases {
name, namespace, err := kubecontainer.ParsePodFullName(podFullName)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment