kubernetes/kops · error

error storing InstanceGroup: %v

Error message

error storing InstanceGroup: %v

What it means

Without --dry-run, the command creates each generated InstanceGroup via clientset.InstanceGroupsFor(cluster).Create. Any API-server rejection (auth, conflict, invalid spec, unreachable server) is wrapped as this error. The cluster itself already exists; only the InstanceGroup write failed.

Source

Thrown at cmd/kops/toolbox_instance-selector.go:347

			case OutputYaml:
				if err := fullOutputYAML(out, ig); err != nil {
					return fmt.Errorf("error writing cluster yaml to stdout: %v", err)
				}
			case OutputJSON:
				if err := fullOutputJSON(out, true, ig); err != nil {
					return fmt.Errorf("error writing cluster json to stdout: %v", err)
				}
			default:
				return fmt.Errorf("unsupported output type %q", options.Output)
			}
		}
		return nil
	}

	for _, ig := range newInstanceGroups {
		_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})
		if err != nil {
			return fmt.Errorf("error storing InstanceGroup: %v", err)
		}

		if err := fullOutputYAML(out, ig); err != nil {
			return fmt.Errorf("error writing cluster yaml to stdout: %v", err)
		}
	}

	return nil
}

func processAndValidateFlags(commandline *cli.CommandLineInterface) error {
	if err := commandline.SetUntouchedFlagValuesToNil(); err != nil {
		return err
	}

	if err := commandline.ProcessFlags(); err != nil {
		return err
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped cause: AlreadyExists means an IG with that name exists — use a different --name prefix or delete the old IG.
  2. Verify kubectl auth to the cluster: `kops export kubecfg <cluster>` then `kubectl get instancegroups`.
  3. Check RBAC allows creating instancesgroups in the cluster.
  4. Confirm connectivity to the cluster API server (VPN/DNS) before rerunning.

Example fix

// before (collision)
kops toolbox instance-selector --name nodes ...
// after
kops toolbox instance-selector --name nodes2 ...
# or delete stale group first:
kops delete instancegroup nodes1 --yes
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: does an IG with the target name already exist?
igs, _ := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
for _, ig := range igs.Items {
	if strings.HasPrefix(ig.Name, options.InstanceGroupName) {
		return fmt.Errorf("instance group %s already exists", ig.Name)
	}
}

Try / catch

if _, err := clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{}); err != nil {
	if apierrors.IsAlreadyExists(err) {
		log.Printf("IG %s exists; skipping", ig.Name); continue
	}
	return fmt.Errorf("error storing InstanceGroup: %v", err)
}

Prevention

When it happens

Trigger: Create() returns an error: 401/403 from bad kubeconfig or RBAC, 409 AlreadyExists for a duplicate IG name, 422 validation failure of the IG spec, or connection errors to the API server.

Common situations: Re-running the command after a partial run (IG names already exist); stale KUBE_CONTEXT pointing at the wrong cluster; RBAC lacking create on instancegroups; running instance groups named 'nodes1' colliding with existing 'nodes1'.

Related errors


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