kubernetes/kops · error

unhandled field: %q

Error message

unhandled field: %q

What it means

SetInstancegroupFields requires each field in key=value form; a field without '=' makes strings.SplitN return one element and the function returns 'unhandled field: %q'. Same strict parser as SetClusterFields but for instance group fields.

Source

Thrown at pkg/commands/set_instancegroups.go:32

limitations under the License.
*/

package commands

import (
	"fmt"
	"strings"

	api "k8s.io/kops/pkg/apis/kops"
	"k8s.io/kops/util/pkg/reflectutils"
)

// SetInstancegroupFields sets field values in the instance group.
func SetInstancegroupFields(fields []string, instanceGroup *api.InstanceGroup) error {
	for _, field := range fields {
		kv := strings.SplitN(field, "=", 2)
		if len(kv) != 2 {
			return fmt.Errorf("unhandled field: %q", field)
		}

		key := kv[0]
		key = strings.TrimPrefix(key, "instancegroup.")

		if err := reflectutils.SetString(instanceGroup, key, kv[1]); err != nil {
			return err
		}
	}

	return nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Format every field as key=value, e.g. instancegroup.spec.machineType=t3.medium.
  2. Quote arguments containing spaces or ranges.
  3. Check the loop/script generating the fields array for empty or truncated entries.

Example fix

// before
fields := []string{"spec.machineType"}
err := SetInstancegroupFields(fields, ig) // unhandled field: "spec.machineType"
// after
fields := []string{"spec.machineType=t3.medium"}
err := SetInstancegroupFields(fields, ig)
Defensive patterns

Strategy: validation

Validate before calling

func validIGFields(fields []string) error {
	for _, f := range fields {
		if !strings.Contains(f, "=") {
			return fmt.Errorf("instance group field %q must be key=value", f)
		}
	}
	return nil
}

Type guard

func isKeyValue(s string) bool {
	parts := strings.SplitN(s, "=", 2)
	return len(parts) == 2 && parts[0] != ""
}

Try / catch

if err := SetInstancegroupFields(fields, instanceGroup); err != nil {
	if strings.HasPrefix(err.Error(), "unhandled field:") {
		return fmt.Errorf("each field needs key=value form; got %v", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling SetInstancegroupFields with entries like "spec.machineType" (no '=value'), e.g. a malformed --set on `kops edit ig`. TestSetInstanceGroupsBadInput covers this case.

Common situations: Omitting the value in shell scripting loops; copy-pasting kubectl label syntax; forgetting the instancegroup. prefix handling where key is trimmed before SetString.

Related errors


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