{"record":{"id":"2bbc5762cfc9c366","repo":"kubernetes/kops","slug":"cluster-not-found-q-2bbc57","errorCode":null,"errorMessage":"cluster not found %q","messagePattern":"cluster not found %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/helpers/kubectl_auth.go","lineNumber":240,"sourceCode":"\t\treturn nil, fmt.Errorf(\"no credentials in cached file\")\n\t}\n\n\treturn execCredential, nil\n}\n\nfunc buildCredentials(ctx context.Context, f *util.Factory, options *HelperKubectlAuthOptions) (*ExecCredentialStatus, error) {\n\tclientset, err := f.KopsClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcluster, err := clientset.GetCluster(ctx, options.ClusterName)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif cluster == nil {\n\t\treturn nil, fmt.Errorf(\"cluster not found %q\", options.ClusterName)\n\t}\n\n\tkeyStore, err := clientset.KeyStore(cluster)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get cluster keystore: %v\", err)\n\t}\n\n\tcn := \"kubecfg\"\n\tuser, err := user.Current()\n\tif err != nil || user == nil {\n\t\tklog.Infof(\"unable to get user: %v\", err)\n\t} else {\n\t\tcn += \"-\" + user.Name\n\t}\n\n\treq := pki.IssueCertRequest{\n\t\tSigner: fi.CertificateIDCA,\n\t\tType:   \"client\",","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/helpers/kubectl_auth.go#L222-L258","documentation":"buildCredentials fetches the cluster object from the kOps state store to locate its keystore. GetCluster returned nil,nil (no cluster with that name in the state store), so buildCredentials returns this 'cluster not found' error. This means the --cluster name does not match any cluster registered in the configured KOPS_STATE_STORE.","triggerScenarios":"Calling kubectl-auth with --cluster <name> where <name> doesn't exist in the state store: typo in cluster name, wrong KOPS_STATE_STORE (S3 bucket / GCS path) selected, or cluster deleted while kubeconfig still references it.","commonSituations":"Old kubeconfig after cluster deletion; multiple state stores (prod vs dev buckets) with the same cluster name in only one; renamed cluster; pointing at an empty local state store with KOPS_STATE_STORE=file://....","solutions":["Run `kops get clusters` to list valid names and fix the --cluster value.","Verify KOPS_STATE_STORE points to the bucket containing the cluster.","Recreate the kubeconfig with `kops export kubecfg <cluster>` if the cluster was deleted or renamed."],"exampleFix":"// before\nkops helpers kubectl-auth --cluster myclster.example.com\n// after\nkops helpers kubectl-auth --cluster mycluster.example.com","handlingStrategy":"validation","validationCode":"// verify the cluster exists before invoking the helper\nif err := exec.Command(\"kops\", \"get\", \"cluster\", clusterName).Run(); err != nil {\n    return fmt.Errorf(\"cluster %q not present in KOPS_STATE_STORE=%s\", clusterName, os.Getenv(\"KOPS_STATE_STORE\"))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify cluster names with `kops get clusters` before configuring kubeconfig.","Pin KOPS_STATE_STORE explicitly in profiles/scripts for each environment.","Refresh kubeconfig after deleting or renaming clusters (`kops export kubecfg`)."],"tags":["state-store","cluster","configuration"],"backgroundTag":"cluster-not-found","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"}