{"record":{"id":"e43a5d27bd1da505","repo":"derailed/k9s","slug":"can-not-rollback-current-replica","errorCode":null,"errorMessage":"can not rollback current replica","messagePattern":"can not rollback current replica","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/dao/rs.go","lineNumber":62,"sourceCode":"func (*ReplicaSet) Load(f Factory, path string) (*appsv1.ReplicaSet, error) {\n\to, err := f.Get(client.RsGVR, path, true, labels.Everything())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar rs appsv1.ReplicaSet\n\terr = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &rs)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &rs, nil\n}\n\nfunc getRSRevision(rs *appsv1.ReplicaSet) (int64, error) {\n\trevision := rs.Annotations[\"deployment.kubernetes.io/revision\"]\n\tif rs.Status.Replicas != 0 {\n\t\treturn 0, errors.New(\"can not rollback current replica\")\n\t}\n\tvers, err := strconv.Atoi(revision)\n\tif err != nil {\n\t\treturn 0, errors.New(\"revision conversion failed\")\n\t}\n\n\treturn int64(vers), nil\n}\n\nfunc controllerInfo(rs *appsv1.ReplicaSet) (name, kind, group string, err error) {\n\tfor _, ref := range rs.OwnerReferences {\n\t\tif ref.Controller == nil {\n\t\t\tcontinue\n\t\t}\n\t\tgroup, tokens := ref.APIVersion, strings.Split(ref.APIVersion, \"/\")\n\t\tif len(tokens) == 2 {\n\t\t\tgroup = tokens[0]\n\t\t}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/derailed/k9s/blob/2d3ccc6ba2ce98c3781bfc441bb3e884f072774f/internal/dao/rs.go#L44-L80","documentation":"getRSRevision backs the ReplicaSet rollback command (dao/rs.go:88 Rollback). Kubernetes refuses to roll a Deployment back to the revision that is currently active, so k9s checks rs.Status.Replicas: a non-zero count means this ReplicaSet is the live one and the attempt is rejected before contacting the API server. The error tells you to pick an older revision instead.","triggerScenarios":"Running the rollback action (:rollback) on the newest ReplicaSet of a Deployment while it still has running replicas (Status.Replicas > 0), i.e. trying to roll back to the current revision.","commonSituations":"Selecting the top/active RS row in the replicasets view instead of an older one; a Deployment that just rolled out and the old RS was scaled to 0 so users assume any row is rollback-able; automated scripts invoking Rollback on an arbitrary RS FQN.","solutions":["Select an older ReplicaSet (one with 0 replicas / not the revision annotated as current) and retry the rollback.","Confirm with `kubectl rollout history deployment/<name>` which revision is active, and target a previous one.","If you truly need to reapply the current revision, edit/apply the Deployment spec instead of using rollback."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func isRollbackable(rs *appsv1.ReplicaSet) bool {\n    return rs.Status.Replicas == 0\n}\n\nrs, _ := replicaSetDAO.Load(factory, fqn)\nif !isRollbackable(rs) {\n    // pick an older RS row; current revision cannot be a rollback target\n}","typeGuard":null,"tryCatchPattern":"if err := rsDAO.Rollback(fqn); err != nil {\n    if strings.Contains(err.Error(), \"can not rollback current replica\") {\n        flash.Warnf(\"Select an older replicaset to roll back\")\n    } else { /* surface err */ }\n}","preventionTips":["In UI code, only offer :rollback on rows with 0 replicas.","Teach users to check `kubectl rollout history` for valid targets.","Remember rolling back TO the active revision is a no-op by design."],"tags":["go","kubernetes","replicaset","rollback","deployment"],"backgroundTag":null,"analyzedSha":"2d3ccc6ba2ce98c3781bfc441bb3e884f072774f","analyzedAt":"2026-08-15T16:09:14.432Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}