derailed/k9s · error
expecting DaemonSet resource
Error message
expecting DaemonSet resource
What it means
k9s's DaemonSet DAO fetches a single DaemonSet from the shared informer cache as *unstructured.Unstructured and converts it into appsv1.DaemonSet via runtime.DefaultUnstructuredConverter.FromUnstructured (internal/dao/ds.go:133). The sentinel 'expecting DaemonSet resource' is returned when conversion fails, and the underlying converter error is discarded. It means the cached object under daemonsets.apps does not fit the k8s.io/api schema k9s was compiled against.
Source
Thrown at internal/dao/ds.go:133
ds, err := d.GetInstance(fqn)
if err != nil {
return "", err
}
return podFromSelector(d.Factory, ds.Namespace, ds.Spec.Selector.MatchLabels)
}
// GetInstance returns a daemonset instance.
func (d *DaemonSet) GetInstance(fqn string) (*appsv1.DaemonSet, error) {
o, err := d.getFactory().Get(d.gvr, fqn, true, labels.Everything())
if err != nil {
return nil, err
}
var ds appsv1.DaemonSet
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &ds)
if err != nil {
return nil, errors.New("expecting DaemonSet resource")
}
return &ds, nil
}
// ScanSA scans for serviceaccount refs.
func (d *DaemonSet) ScanSA(_ context.Context, fqn string, wait bool) (Refs, error) {
ns, n := client.Namespaced(fqn)
oo, err := d.getFactory().List(d.gvr, ns, wait, labels.Everything())
if err != nil {
return nil, err
}
refs := make(Refs, 0, len(oo))
for _, o := range oo {
var ds appsv1.DaemonSet
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &ds)
if err != nil {View on GitHub (pinned to 2d3ccc6ba2)
Solutions
- Inspect the object: kubectl get daemonset.apps <name> -n <ns> -o yaml and fix mistyped or unexpected fields.
- Upgrade k9s so its vendored k8s.io/* versions match the cluster minor version.
- Verify daemonsets.apps is served by the core apiserver and not shadowed by an aggregated service.
- Restart k9s to rebuild informer caches after cluster/webhook changes.
- If embedding, wrap the converter error with %w to expose the offending field.
Example fix
// before
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &ds)
if err != nil {
return nil, errors.New("expecting DaemonSet resource")
}
// after
u, ok := o.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("expected unstructured daemonset, got %T", o)
}
var ds appsv1.DaemonSet
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &ds); err != nil {
return nil, fmt.Errorf("daemonset %q does not match v1 schema: %w", fqn, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
o, err := factory.Get(client.DsGVR, fqn, true, labels.Everything())
if err != nil { return err }
u, ok := o.(*unstructured.Unstructured)
if !ok || u.GroupVersionKind().Kind != "DaemonSet" {
return fmt.Errorf("not a daemonset: %s", u.GroupVersionKind())
} Type guard
func isDaemonSet(o runtime.Object) bool {
u, ok := o.(*unstructured.Unstructured)
return ok && u.GroupVersionKind().Kind == "DaemonSet" && u.GroupVersionKind().Group == "apps"
} Try / catch
var ds appsv1.DaemonSet
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &ds); err != nil {
return nil, fmt.Errorf("daemonset %q conversion: %w", fqn, err)
} Prevention
- Align k9s builds with cluster versions; daemonset schemas drift across releases.
- Assert *unstructured.Unstructured and the GVK before converting in custom code.
- Wrap converter errors with %w instead of replacing them with sentinels.
- Restart k9s after cluster or webhook changes to rebuild caches.
When it happens
Trigger: Calling dao.DaemonSet.GetInstance(fqn) — the daemonset detail view, restart or rollout actions — when the stored object has fields whose JSON types cannot be assigned to the compiled appsv1.DaemonSet struct: apiserver version skew, an aggregated API shadowing daemonsets.apps, or webhook-written out-of-schema values.
Common situations: k9s builds with older k8s.io/* libraries against newer clusters; DaemonSets mutated by custom controllers or webhooks with legacy fields; cache staleness right after cluster upgrades; embedding the DAO layer with a custom factory.
Related errors
- expecting cronjob resource
- expecting Deployment resource
- expecting StatefulSet resource
- expecting Job resource
- expecting ServiceAccount resource
AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15).
Data as JSON: /api/errors/74b404ced74ffcbe.
Report an issue: GitHub.