{"record":{"id":"15d3fcb413602cf5","repo":"derailed/k9s","slug":"expecting-statefulset-resource-15d3fc","errorCode":null,"errorMessage":"expecting Statefulset resource","messagePattern":"expecting Statefulset resource","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dao/sts.go","lineNumber":71,"sourceCode":"\treturn scaleRes(ctx, s.getFactory(), client.StsGVR, path, replicas)\n}\n\n// Restart a StatefulSet rollout.\nfunc (s *StatefulSet) Restart(ctx context.Context, path string, opts *metav1.PatchOptions) error {\n\treturn restartRes[*appsv1.StatefulSet](ctx, s.getFactory(), client.StsGVR, path, opts)\n}\n\n// GetInstance returns a statefulset instance.\nfunc (*StatefulSet) GetInstance(f Factory, fqn string) (*appsv1.StatefulSet, error) {\n\to, err := f.Get(client.StsGVR, fqn, true, labels.Everything())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar sts appsv1.StatefulSet\n\terr = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &sts)\n\tif err != nil {\n\t\treturn nil, errors.New(\"expecting Statefulset resource\")\n\t}\n\n\treturn &sts, nil\n}\n\n// TailLogs tail logs for all pods represented by this StatefulSet.\nfunc (s *StatefulSet) TailLogs(ctx context.Context, opts *LogOptions) ([]LogChan, error) {\n\tsts, err := s.getStatefulSet(opts.Path)\n\tif err != nil {\n\t\treturn nil, errors.New(\"expecting StatefulSet resource\")\n\t}\n\tif sts.Spec.Selector == nil || len(sts.Spec.Selector.MatchLabels) == 0 {\n\t\treturn nil, fmt.Errorf(\"no valid selector found on statefulset: %s\", opts.Path)\n\t}\n\n\treturn podLogs(ctx, sts.Spec.Selector.MatchLabels, opts)\n}\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/sts.go#L53-L89","documentation":"StatefulSet.GetInstance fetches the object via the factory and converts the unstructured payload into a typed appsv1.StatefulSet with runtime.DefaultUnstructuredConverter.FromUnstructured. If the returned object's shape does not satisfy the StatefulSet schema, the conversion error is replaced by this sentinel message. Typical root causes are an apiVersion mismatch (apps/v1 vs beta) or schema drift between the cached object and the compiled-in type.","triggerScenarios":"GetInstance called on an object served under a different apiVersion/kind than appsv1.StatefulSet (e.g. leftovers from apps/v1beta2 clusters, or a CRD shadowing the sts GVR); conversion of unknown/renamed fields fails.","commonSituations":"Clusters upgraded from old Kubernetes versions where statefulsets existed in beta apiGroups; aggregated APIs or mutating webhooks that inject fields the typed struct rejects; stale informer cache after a CRD/CR version change.","solutions":["Check the object's apiVersion/kind first: it must be apps/v1 StatefulSet for the conversion to succeed.","Refresh the cache (restart k9s / re-list) if the cluster was just upgraded or the CRD changed.","Wrap the conversion with the underlying err (fmt.Errorf with %w) to see exactly which field failed instead of the generic message."],"exampleFix":"// before\nerr = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &sts)\nif err != nil { return nil, errors.New(\"expecting Statefulset resource\") }\n// after\nif err != nil { return nil, fmt.Errorf(\"expecting Statefulset resource: %w\", err) }","handlingStrategy":"type-guard","validationCode":"u, ok := o.(*unstructured.Unstructured)\nif !ok || u.GetKind() != \"StatefulSet\" || u.GetAPIVersion() != \"apps/v1\" {\n    return nil, fmt.Errorf(\"unexpected kind %s/%s\", u.GetAPIVersion(), u.GetKind())\n}","typeGuard":"func isStatefulSet(o runtime.Object) bool {\n    u, ok := o.(*unstructured.Unstructured)\n    return ok && u.GetKind() == \"StatefulSet\" && u.GetAPIVersion() == \"apps/v1\"\n}","tryCatchPattern":"sts, err := stsDAO.GetInstance(f, fqn)\nif err != nil {\n    if strings.Contains(err.Error(), \"expecting Statefulset resource\") {\n        // check apiVersion/schema drift or stale cache before retrying\n    }\n    return err\n}","preventionTips":["Check apiVersion/kind before conversion.","Keep k9s (and its k8s.io/api) aligned with the cluster version.","Wrap conversion errors with %w to expose the failing field."],"tags":["go","kubernetes","statefulset","conversion","dao"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}