kubernetes/kops · error

unexpected boolean value: %q

Error message

unexpected boolean value: %q

What it means

parseBool wraps strconv.ParseBool failures when converting a cluster/spec string field (e.g. from the Spotinst config) into a *bool. It fires whenever a value that must be a boolean literal (1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False) is anything else. The message includes the offending string in %q so the bad value is visible.

Source

Thrown at pkg/model/awsmodel/spotinst.go:1101

	}

	return opts, nil
}

func (b *SpotInstanceGroupModelBuilder) buildInstanceMetadataOptions(ig *kops.InstanceGroup) *spotinsttasks.InstanceMetadataOptions {
	if ig.Spec.InstanceMetadata != nil {
		opt := new(spotinsttasks.InstanceMetadataOptions)
		opt.HTTPPutResponseHopLimit = new(fi.ValueOf(ig.Spec.InstanceMetadata.HTTPPutResponseHopLimit))
		opt.HTTPTokens = new(fi.ValueOf(ig.Spec.InstanceMetadata.HTTPTokens))
		return opt
	}
	return nil
}

func parseBool(str string) (*bool, error) {
	v, err := strconv.ParseBool(str)
	if err != nil {
		return nil, fmt.Errorf("unexpected boolean value: %q", str)
	}
	return &v, nil
}

func parseFloat(str string) (*float64, error) {
	v, err := strconv.ParseFloat(str, 64)
	if err != nil {
		return nil, fmt.Errorf("unexpected float value: %q", str)
	}
	return &v, nil
}

func parseInt(str string) (*int64, error) {
	v, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		return nil, fmt.Errorf("unexpected integer value: %q", str)
	}
	return &v, nil

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Locate the quoted value in the error message and change it to one of strconv.ParseBool's accepted literals: true/false (or 1/0, t/f, T/F, TRUE/FALSE).
  2. Strip whitespace and quotes from the config value before it reaches kOps (edit the cluster spec / userdata source).
  3. If the key should be absent when unset, delete the empty value rather than leaving ''.
  4. If you control the code, consider accepting YAML-style booleans via a more lenient parser before calling parseBool.

Example fix

// before (cluster spec / config value)
spotinst/ocean/autoscaler/down: "yes"
// after
spotinst/ocean/autoscaler/down: "true"
Defensive patterns

Strategy: validation

Validate before calling

func validBool(s string) bool {
	s = strings.TrimSpace(s)
	if s == "" { return false }
	_, err := strconv.ParseBool(s)
	return err == nil
}
// call before applying the spec:
if !validBool(cfg.Down) { return fmt.Errorf("config field must be a Go boolean literal (true/false/1/0/t/f), got %q", cfg.Down) }

Try / catch

if v, err := parseBool(raw); err != nil {
	return fmt.Errorf("field %q: %w", key, err) // inspect %q value in message
}

Prevention

When it happens

Trigger: Any buildElastigroup/buildOcean/buildLaunchSpec/buildAutoScalerOpts call reading a string config key parsed via parseBool where the value is not a valid Go boolean literal — e.g. 'yes', 'on', 'enabled', '1 ' with trailing space, or an empty string from a missing/blank field.

Common situations: Users set spotinst options like 'spotinst/hydrated: yes' or 'true' with whitespace/quotes in the cluster spec; YAML tools writing 'True' variants are fine, but 'yes'/'on' (valid YAML booleans) are not valid for strconv.ParseBool.

Related errors


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