kubernetes/kops · error
creating discovery client
Error message
creating discovery client: %w
What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
if cfg.Host == "" {
return fmt.Errorf("rest.Config.Host is empty")
}
u, err := url.Parse(cfg.Host)
if err != nil || (u.Scheme != "https" && u.Scheme != "http") {
return fmt.Errorf("invalid rest.Config.Host %q", cfg.Host)
}
if _, err := dynamic.NewForConfig(cfg); err != nil {
return fmt.Errorf("config rejected by client construction: %w", err)
} Try / catch
if err := dumper.DumpResources(ctx); err != nil {
var ce *url.Error
if strings.Contains(err.Error(), "creating discovery client") {
// config construction problem: log rest.Config (redact secrets) and fix Host/TLS
}
_ = ce
return err
} Prevention
- 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.
When it happens
Trigger: d.k8sConfig has a malformed Host, invalid TLS/cert configuration, or other fields that rest.RESTClientFor rejects during client construction.
Common situations: 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.
Related errors
- building kubernetes client
- building kubernetes client
- cannot build kube client for
- cannot build kube client
- cannot load kubecfg settings for
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/2db569f0bc84602d.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/dump/resourcedumper.go:110
artifactsDir: artifactsDir,
}, nil
}
func (d *resourceDumper) DumpResources(ctx context.Context) error {
klog.Info("Dumping k8s resources")
clientSet, err := kubernetes.NewForConfig(d.k8sConfig)
if err != nil {
return fmt.Errorf("creating clientset: %w", err)
}
namespaces, err := clientSet.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("listing namespaces: %w", err)
}
discoveryClient, err := discovery.NewDiscoveryClientForConfig(d.k8sConfig)
if err != nil {
return fmt.Errorf("creating discovery client: %w", err)
}
resourceLists, err := discoveryClient.ServerPreferredResources()
var discoveryErr *discovery.ErrGroupDiscoveryFailed
if errors.As(err, &discoveryErr) {
klog.Warningf("using incomplete list of API groups: %v", discoveryErr)
} else if err != nil {
return fmt.Errorf("listing server preferred resources: %w", err)
}
gvrNamespaces, err := getGVRNamespaces(resourceLists, namespaces.Items)
if err != nil {
return fmt.Errorf("getting GVR namespaces: %w", err)
}
jobs := make(chan gvrNamespace, len(gvrNamespaces))
results := make(chan resourceDumpResult, len(gvrNamespaces))
View on GitHub (pinned to 4c8573c808)