kubernetes/kops · error

one or more key=value pairs are malformed: %s :%w

Error message

one or more key=value pairs are malformed:
%s
:%w

What it means

parseCloudLabels splits a CSV of key=value records (with newline substitution for CSV parsing); this aggregates all records that the CSV reader could not parse, listing them in the error. It is a pure input-validation failure on the --cloud-labels value.

Source

Thrown at cmd/kops/create_cluster.go:956

}

// parseCloudLabels takes a CSV list of key=value records and parses them into a map. Nested '='s are supported via
// quoted strings (eg `foo="bar=baz"` parses to map[string]string{"foo":"bar=baz"}. Nested commas are not supported.
func parseCloudLabels(s string) (map[string]string, error) {
	// Replace commas with newlines to allow a single pass with csv.Reader.
	// We can't use csv.Reader for the initial split because it would see each key=value record as a single field
	// and significantly complicates using quoted fields as keys or values.
	records := strings.ReplaceAll(s, ",", "\n")

	// Let the CSV library do the heavy-lifting in handling nested ='s
	r := csv.NewReader(strings.NewReader(records))
	r.Comma = '='
	r.FieldsPerRecord = 2
	r.LazyQuotes = false
	r.TrimLeadingSpace = true
	kvPairs, err := r.ReadAll()
	if err != nil {
		return nil, fmt.Errorf("one or more key=value pairs are malformed:\n%s\n:%w", records, err)
	}

	m := make(map[string]string, len(kvPairs))
	for _, pair := range kvPairs {
		m[pair[0]] = pair[1]
	}
	return m, nil
}

func loadSSHPublicKeys(sshPublicKey string) (map[string][]byte, error) {
	sshPublicKeys := make(map[string][]byte)
	if sshPublicKey != "" {
		sshPublicKey = utils.ExpandPath(sshPublicKey)
		authorized, err := os.ReadFile(sshPublicKey)
		if err != nil {
			return nil, err
		}
		sshPublicKeys[fi.SecretNameSSHPrimary] = authorized

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the malformed key=value records shown in the error message
  2. Quote values containing '=' e.g. foo="bar=baz"
  3. Ensure records are comma-separated without stray quotes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cmd/kops/create_cluster.go:956 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/09302e8efb5b4dc3. Report an issue: GitHub.