kubernetes/kops · error

unknown write option: %q

Error message

unknown write option: %q

What it means

writeConfig only recognizes vfs.WriteOptionNone and vfs.WriteOptionOnlyIfExists. Any other value hits the default branch and returns this error. It is a programming/API-misuse error in the caller, not an environment issue.

Source

Thrown at pkg/client/simple/vfsclientset/commonvfs.go:154

	if err != nil {
		return fmt.Errorf("error marshaling object: %v", err)
	}

	create := false
	for _, writeOption := range writeOptions {
		switch writeOption {
		case vfs.WriteOptionCreate:
			create = true
		case vfs.WriteOptionOnlyIfExists:
			_, err = configPath.ReadFile(ctx)
			if err != nil {
				if os.IsNotExist(err) {
					return fmt.Errorf("cannot update configuration file %s: does not exist", configPath)
				}
				return fmt.Errorf("error checking if configuration file %s exists already: %v", configPath, err)
			}
		default:
			return fmt.Errorf("unknown write option: %q", writeOption)
		}
	}

	acl, err := acls.GetACL(ctx, configPath, cluster)
	if err != nil {
		return err
	}

	rs := bytes.NewReader(data)
	if create {
		err = configPath.CreateFile(ctx, rs, acl)
	} else {
		err = configPath.WriteFile(ctx, rs, acl)
	}
	if err != nil {
		if create && os.IsExist(err) {
			klog.Warningf("failed to create file as already exists: %v", configPath)
			return err

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the writeOption value being passed and change it to vfs.WriteOptionNone or vfs.WriteOptionOnlyIfExists.
  2. If a new option is required, add a case for it in writeConfig in commonvfs.go.
  3. Ensure vfs and vfsclientset package versions are consistent (go mod tidy).

Example fix

// before
err := c.writeConfig(ctx, cluster, p, obj, vfs.WriteOptionIgnoreExisting)
// after
err := c.writeConfig(ctx, cluster, p, obj, vfs.WriteOptionNone)
Defensive patterns

Strategy: validation

Validate before calling

allowed := map[vfs.WriteOption]bool{vfs.WriteOptionNone: true, vfs.WriteOptionOnlyIfExists: true}
if !allowed[opt] {
    return fmt.Errorf("unsupported write option %v", opt)
}

Prevention

When it happens

Trigger: Code passes an unrecognized vfs.WriteOption value to Create, Update, create, or update on a VFS-backed clientset — e.g. a new vfs option not yet handled in writeConfig, or a typo'd constant.

Common situations: Upgrading the vfs package introduces a new WriteOption this vfsclientset does not handle; custom forks adding options; passing the wrong constant.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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