mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
ParsePodFullName():code robustness
This commit is contained in:
parent
3fbfafdd0a
commit
65080ea1c1
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user