{"record":{"id":"2db569f0bc84602d","repo":"kubernetes/kops","slug":"creating-discovery-client-w","errorCode":null,"errorMessage":"creating discovery client: %w","messagePattern":"creating discovery client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dump/resourcedumper.go","lineNumber":110,"sourceCode":"\t\tartifactsDir:  artifactsDir,\n\t}, nil\n}\n\nfunc (d *resourceDumper) DumpResources(ctx context.Context) error {\n\tklog.Info(\"Dumping k8s resources\")\n\tclientSet, err := kubernetes.NewForConfig(d.k8sConfig)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating clientset: %w\", err)\n\t}\n\n\tnamespaces, err := clientSet.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"listing namespaces: %w\", err)\n\t}\n\n\tdiscoveryClient, err := discovery.NewDiscoveryClientForConfig(d.k8sConfig)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating discovery client: %w\", err)\n\t}\n\n\tresourceLists, err := discoveryClient.ServerPreferredResources()\n\tvar discoveryErr *discovery.ErrGroupDiscoveryFailed\n\tif errors.As(err, &discoveryErr) {\n\t\tklog.Warningf(\"using incomplete list of API groups: %v\", discoveryErr)\n\t} else if err != nil {\n\t\treturn fmt.Errorf(\"listing server preferred resources: %w\", err)\n\t}\n\n\tgvrNamespaces, err := getGVRNamespaces(resourceLists, namespaces.Items)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting GVR namespaces: %w\", err)\n\t}\n\n\tjobs := make(chan gvrNamespace, len(gvrNamespaces))\n\tresults := make(chan resourceDumpResult, len(gvrNamespaces))\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dump/resourcedumper.go#L92-L128","documentation":"After listing namespaces, DumpResources builds a discovery client via discovery.NewDiscoveryClientForConfig(d.k8sConfig) to query the server's preferred API resources. This error wraps a failure to construct the REST client itself, which is rare because construction only fails on invalid rest.Config (e.g. unparsable host URL, conflicting TLS settings) rather than on network problems.","triggerScenarios":"d.k8sConfig has a malformed Host, invalid TLS/cert configuration, or other fields that rest.RESTClientFor rejects during client construction.","commonSituations":"Programmatically mutated rest.Config (bad URL scheme, whitespace in host), a config assembled without setting Host at all, or a TLS key/cert pair that cannot be loaded into transport config.","solutions":["Inspect d.k8sConfig (Host, TLS fields) and fix invalid values before calling NewResourceDumper.","Build the config from a known-good source via clientcmd or rest.InClusterConfig instead of hand-constructing it.","Confirm NewResourceDumper's dynamic.NewForConfig succeeded (same config), isolating the field that discovery-specific construction rejects."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if cfg.Host == \"\" {\n\treturn fmt.Errorf(\"rest.Config.Host is empty\")\n}\nu, err := url.Parse(cfg.Host)\nif err != nil || (u.Scheme != \"https\" && u.Scheme != \"http\") {\n\treturn fmt.Errorf(\"invalid rest.Config.Host %q\", cfg.Host)\n}\nif _, err := dynamic.NewForConfig(cfg); err != nil {\n\treturn fmt.Errorf(\"config rejected by client construction: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := dumper.DumpResources(ctx); err != nil {\n\tvar ce *url.Error\n\tif strings.Contains(err.Error(), \"creating discovery client\") {\n\t\t// config construction problem: log rest.Config (redact secrets) and fix Host/TLS\n\t}\n\t_ = ce\n\treturn err\n}","preventionTips":["Construct rest.Config only via clientcmd or rest.InClusterConfig, never by hand.","Validate cfg.Host parses as an absolute https URL before creating clients.","Redact and inspect the config when construction errors occur; don't mutate the shared config across clients."],"tags":["kubernetes","client-go","config"],"backgroundTag":"invalid-rest-config","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"}