{"record":{"id":"135b38bd80238903","repo":"kubernetes/kops","slug":"clustername-is-required-135b38","errorCode":null,"errorMessage":"ClusterName is required","messagePattern":"ClusterName is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/helpers/kubectl_auth.go","lineNumber":93,"sourceCode":"\n\t\t\terr := RunKubectlAuthHelper(ctx, f, out, options)\n\t\t\tif err != nil {\n\t\t\t\tcommandutils.ExitWithError(err)\n\t\t\t}\n\t\t},\n\t}\n\n\tcmd.Flags().StringVar(&options.APIVersion, \"api-version\", options.APIVersion, \"version of client.authentication.k8s.io schema in use\")\n\tcmd.Flags().StringVar(&options.ClusterName, \"cluster\", options.ClusterName, \"cluster to target\")\n\tcmd.Flags().DurationVar(&options.Lifetime, \"lifetime\", options.Lifetime, \"lifetime of the credential to issue\")\n\n\treturn cmd\n}\n\n// RunKubectlAuthHelper implements the kubectl auth helper, which creates an authentication token\nfunc RunKubectlAuthHelper(ctx context.Context, f *util.Factory, out io.Writer, options *HelperKubectlAuthOptions) error {\n\tif options.ClusterName == \"\" {\n\t\treturn fmt.Errorf(\"ClusterName is required\")\n\t}\n\n\texecCredential := &ExecCredential{\n\t\tKind: \"ExecCredential\",\n\t}\n\n\tswitch options.APIVersion {\n\tcase \"\":\n\t\treturn fmt.Errorf(\"api-version must be specified\")\n\tcase \"v1alpha1\":\n\t\texecCredential.APIVersion = \"client.authentication.k8s.io/v1alpha1\"\n\tcase \"v1beta1\":\n\t\texecCredential.APIVersion = \"client.authentication.k8s.io/v1beta1\"\n\n\tdefault:\n\t\treturn fmt.Errorf(\"api-version %q is not supported\", options.APIVersion)\n\t}\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/helpers/kubectl_auth.go#L75-L111","documentation":"RunKubectlAuthHelper implements kOps' kubectl exec-credential auth helper, which emits a client.authentication.k8s.io ExecCredential. It refuses to run without knowing which cluster to target, so an empty options.ClusterName returns this error immediately before any state-store access. The --cluster flag populates ClusterName; nothing supplies a default.","triggerScenarios":"Calling RunKubectlAuthHelper (or the `kops helpers kubectl-auth` command) with HelperKubectlAuthOptions.ClusterName left as the zero value \"\" — i.e. the --cluster flag was not passed and no wrapper set the field.","commonSituations":"Running `kubectl-auth` manually without --cluster; embedding the helper in a kubeconfig exec block where args omit --cluster; scripting the command after stripping flags; using options struct in Go code without setting ClusterName.","solutions":["Pass --cluster <name> on the kubectl-auth command line.","If invoking in Go, set options.ClusterName before calling RunKubectlAuthHelper.","Check the kubeconfig exec credential plugin args include --cluster."],"exampleFix":"// before\nexec:\n  command: kops\n  args: [\"helpers\", \"kubectl-auth\"]\n// after\nexec:\n  command: kops\n  args: [\"helpers\", \"kubectl-auth\", \"--cluster\", \"mycluster.k8s.local\"]","handlingStrategy":"validation","validationCode":"if options.ClusterName == \"\" {\n    return fmt.Errorf(\"cannot run kubectl-auth: --cluster is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --cluster in the kubeconfig exec plugin args.","Validate options fields before calling RunKubectlAuthHelper in Go code.","Generate kubeconfig entries via `kops export kubecfg` instead of hand-writing exec blocks."],"tags":["cli","missing-flag","authentication"],"backgroundTag":"missing-required-argument","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"}