{"record":{"id":"64371b6fda2a4737","repo":"kubernetes/kops","slug":"name-is-required-64371b","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/get_instancegroups.go","lineNumber":74,"sourceCode":"\t*GetOptions\n\tInstanceGroupNames []string\n}\n\nfunc NewCmdGetInstanceGroups(f *util.Factory, out io.Writer, getOptions *GetOptions) *cobra.Command {\n\toptions := GetInstanceGroupsOptions{\n\t\tGetOptions: getOptions,\n\t}\n\n\tcmd := &cobra.Command{\n\t\tUse:     \"instancegroups [INSTANCE_GROUP]...\",\n\t\tAliases: []string{\"instancegroup\", \"ig\"},\n\t\tShort:   getInstancegroupsShort,\n\t\tLong:    getInstancegroupsLong,\n\t\tExample: getInstancegroupsExample,\n\t\tArgs: func(cmd *cobra.Command, args []string) error {\n\t\t\toptions.ClusterName = rootCommand.ClusterName(true)\n\t\t\tif options.ClusterName == \"\" {\n\t\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t\t}\n\n\t\t\toptions.InstanceGroupNames = args\n\t\t\treturn nil\n\t\t},\n\t\tValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\t\t\treturn completeInstanceGroup(f, &args, nil)(cmd, nil, toComplete)\n\t\t},\n\t\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\t\treturn RunGetInstanceGroups(cmd.Context(), f, out, &options)\n\t\t},\n\t}\n\n\treturn cmd\n}\n\nfunc RunGetInstanceGroups(ctx context.Context, f commandutils.Factory, out io.Writer, options *GetInstanceGroupsOptions) error {\n\tclientset, err := f.KopsClient()","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/get_instancegroups.go#L56-L92","documentation":"`kops get instancegroups` requires a target cluster, resolved from the global --name flag (or KOPS_CLUSTER_NAME env) via rootCommand.ClusterName(true). The Args validator returns '--name is required' when neither is set, because instance groups can only be listed within a specific cluster.","triggerScenarios":"`kops get instancegroups` (optionally with group names) run without --name and without KOPS_CLUSTER_NAME exported.","commonSituations":"Forgetting to export KOPS_CLUSTER_NAME in scripts; running the command in a fresh shell/CI job; using the kubecfg current-context expectation where kops actually needs an explicit name.","solutions":["Pass the cluster explicitly: `kops get instancegroups --name mycluster.example.com`.","Export KOPS_CLUSTER_NAME=mycluster.example.com for the session/script.","Set --state together with --name if the cluster lives in a non-default state store."],"exampleFix":"// before\nkops get instancegroups\n// after\nkops get instancegroups --name mycluster.example.com","handlingStrategy":"validation","validationCode":"[ -n \"${KOPS_CLUSTER_NAME:-}\" ] || set -- \"--name\" \"${1:-$(kops get clusters -o json | jq -r '.items[0].metadata.name')}\"\nkops get instancegroups \"$@\"","typeGuard":"null","tryCatchPattern":"if ! kops get instancegroups 2>err.txt; then\n  grep -q -- '--name is required' err.txt && \\\n    echo \"pass --name <cluster> or export KOPS_CLUSTER_NAME\"\nfi","preventionTips":["Export KOPS_CLUSTER_NAME at the top of scripts that target one cluster.","Always pass --name explicitly in CI where environment state is unreliable.","Run `kops get clusters` to confirm the exact name before instancegroup operations."],"tags":["cli","missing-flag","instancegroups"],"backgroundTag":"missing-required-flag","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}