kubernetes/kubernetes · error
the argument must have both a key and a value
Error message
the argument must have both a key and a value
What it means
Returned by parseArgument when, after stripping '--' and splitting on '=' with SplitN(.,=,2), the result does not yield exactly two parts. In practice this is guarded by the earlier '=' presence check, so it covers an edge-case where splitting still fails to produce a key/value pair.
Source
Thrown at cmd/kubeadm/app/util/arguments.go:105
return args
}
// parseArgument parses the argument "--foo=bar" to "foo" and "bar"
func parseArgument(arg string) (string, string, error) {
if !strings.HasPrefix(arg, "--") {
return "", "", errors.New("the argument should start with '--'")
}
if !strings.Contains(arg, "=") {
return "", "", errors.New("the argument should have a '=' between the flag and the value")
}
// Remove the starting --
arg = strings.TrimPrefix(arg, "--")
// Split the string on =. Return only two substrings, since we want only key/value, but the value can include '=' as well
keyvalSlice := strings.SplitN(arg, "=", 2)
// Make sure both a key and value is present
if len(keyvalSlice) != 2 {
return "", "", errors.New("the argument must have both a key and a value")
}
if len(keyvalSlice[0]) == 0 {
return "", "", errors.New("the argument must have a key")
}
return keyvalSlice[0], keyvalSlice[1], nil
}
// sortArgsSlice sorts a slice of Args alpha-numerically.
func sortArgsSlice(argsPtr *[]kubeadmapi.Arg) {
args := *argsPtr
sort.Slice(args, func(i, j int) bool {
if args[i].Name == args[j].Name {
return args[i].Value < args[j].Value
}
return args[i].Name < args[j].Name
})
}View on GitHub (pinned to b882c60b40)
Solutions
- Rewrite the token in canonical '--key=value' form.
- Remove stray characters/whitespace around the '=' in kubeadm-flags.env or extraArgs.
- If reproducing, isolate the exact token and report it; this branch is defensive and seldom reached.
Example fix
# before (malformed token) KUBELET_KUBEADM_ARGS="--=value" # after KUBELET_KUBEADM_ARGS="--real-key=value"
Defensive patterns
Strategy: validation
Validate before calling
parts := strings.SplitN(strings.TrimPrefix(a, "--"), "=", 2)
if len(parts) != 2 {
return fmt.Errorf("argument %q must have both key and value", a)
} Type guard
func isKeyValuePair(a string) bool {
parts := strings.SplitN(strings.TrimPrefix(a, "--"), "=", 2)
return len(parts) == 2
} Prevention
- Canonicalize all args to '--key=value' before persistence.
- Reject malformed args at generation time rather than relying on parse-time warnings.
- Add a config-lint step in CI for kubeadm-flags.env.
When it happens
Trigger: A token that passes the '--' prefix and '=' presence checks but SplitN(arg,'=',2) returns something other than two elements (defensive branch; rarely hit given the prior checks).
Common situations: Extremely unusual inputs; effectively a defensive guard. If hit, the token is structurally malformed despite containing '='.
Related errors
- the argument should start with '--'
- the argument should have a '=' between the flag and the valu
- the argument must have a key
- the --old-config flag is mandatory
- cannot use --certificate-key without --print-join-command
AI-assisted analysis of kubernetes/kubernetes@b882c60b40 (2026-08-07).
Data as JSON: /api/errors/a6507474094fe53e.
Report an issue: GitHub.