{"record":{"id":"55386d83d2df297d","repo":"kubernetes/kops","slug":"getting-clientset-v","errorCode":null,"errorMessage":"getting clientset: %v","messagePattern":"getting clientset: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/promote_keypair.go","lineNumber":128,"sourceCode":"\t}\n\n\treturn cmd\n}\n\n// RunPromoteKeypair promotes a keypair.\nfunc RunPromoteKeypair(ctx context.Context, f *util.Factory, out io.Writer, options *PromoteKeypairOptions) error {\n\tif !rotatableKeysetFilter(options.Keyset, nil) {\n\t\treturn fmt.Errorf(\"promoting keypairs for %q is not supported\", options.Keyset)\n\t}\n\n\tcluster, err := GetCluster(ctx, f, options.ClusterName)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting cluster: %q: %v\", options.ClusterName, err)\n\t}\n\n\tclientSet, err := f.KopsClient()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting clientset: %v\", err)\n\t}\n\n\tkeyStore, err := clientSet.KeyStore(cluster)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting keystore: %v\", err)\n\t}\n\n\tif options.Keyset != \"all\" {\n\t\treturn promoteKeypair(ctx, out, options.Keyset, options.KeypairID, keyStore)\n\t}\n\n\tkeysets, err := keyStore.ListKeysets()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"listing keysets: %v\", err)\n\t}\n\n\tfor name := range keysets {\n\t\tif rotatableKeysetFilter(name, nil) {","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/promote_keypair.go#L110-L146","documentation":"RunPromoteKeypair obtains the kops clientset via f.KopsClient(); this wraps that call failing - typically missing/invalid state store configuration or registry setup errors, before any keyset operation begins.","triggerScenarios":"`kops promote keypair` run when the kops client cannot be built — typically invalid or missing kubeconfig, or in-cluster config unavailable when running inside a cluster.","commonSituations":"KUBECONFIG pointing at a nonexistent/stale file; running kops inside a pod without a service account token; corrupt kubeconfig after a context switch.","solutions":["Verify kubeconfig validity: `kubectl config view` and fix KUBECONFIG","Run from an environment where the cluster API is reachable (VPN, correct region)","If running in-cluster, ensure the pod's service account allows building the client","Re-create the kubeconfig entry for the cluster (kops export kubecfg)"],"exampleFix":"// before\nexport KUBECONFIG=/stale/path/config\n// after\nkops export kubecfg mycluster.k8s.local --admin\nexport KUBECONFIG=~/.kube/config","handlingStrategy":"validation","validationCode":"kubectl config current-context && kubectl cluster-info || { echo \"kubeconfig broken\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := RunPromoteKeypair(ctx, f, out, opts); err != nil {\n\tif strings.Contains(err.Error(), \"getting clientset\") {\n\t\tlog.Printf(\"fix KUBECONFIG / API reachability: %v\", err)\n\t}\n}","preventionTips":["Run `kops export kubecfg` after cluster changes","Validate kubeconfig with kubectl before kops operations","Ensure in-cluster runs have a mounted service-account token"],"tags":["cli","kubeconfig","clientset"],"backgroundTag":"invalid-kubeconfig","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}