{"record":{"id":"4d18afe729c455e3","repo":"ahmetb/kubectx","slug":"failed-to-initialize-k8s-rest-client-w","errorCode":null,"errorMessage":"failed to initialize k8s REST client: %w","messagePattern":"failed to initialize k8s REST client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kubens/list.go","lineNumber":85,"sourceCode":"\n\tfor _, c := range ns {\n\t\ts := c\n\t\tif c == curNs {\n\t\t\ts = printer.ActiveItemColor.Sprint(c)\n\t\t}\n\t\tfmt.Fprintf(w, \"%s\\n\", s)\n\t}\n\treturn nil\n}\n\nfunc queryNamespaces(kc *kubeconfig.Kubeconfig) ([]string, error) {\n\tif os.Getenv(\"_MOCK_NAMESPACES\") != \"\" {\n\t\treturn []string{\"ns1\", \"ns2\"}, nil\n\t}\n\n\tclientset, err := newKubernetesClientSet(kc)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to initialize k8s REST client: %w\", err)\n\t}\n\n\tvar out []string\n\tvar next string\n\tfor {\n\t\tlist, err := clientset.CoreV1().Namespaces().List(\n\t\t\tcontext.Background(),\n\t\t\tmetav1.ListOptions{\n\t\t\t\tLimit:    500,\n\t\t\t\tContinue: next,\n\t\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to list namespaces from k8s API: %w\", err)\n\t\t}\n\t\tnext = list.Continue\n\t\tout = slices.Grow(out, len(list.Items))\n\t\tfor _, it := range list.Items {\n\t\t\tout = append(out, it.Name)","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/ahmetb/kubectx/blob/12ad6fb22e8c546ee2b54e7de38aa51c906832f7/cmd/kubens/list.go#L67-L103","documentation":"newKubernetesClientSet failed to build a client-go clientset from the kubeconfig: either client-go could not load the config (broken/invalid kubeconfig content beyond what kyaml accepted) or REST config construction failed for the current context's cluster/user.","triggerScenarios":"Thrown at cmd/kubens/list.go:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run kubectl config view to see if client-go can parse the same config","Check the cluster and user entries of the current context for missing/invalid fields","Regenerate the context with the provider tool (e.g. gcloud/eks ctl) if entries are corrupt"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12ad6fb22e8c546ee2b54e7de38aa51c906832f7","analyzedAt":"2026-09-02T12:23:10.107Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}