{"record":{"id":"a74404204c04177a","repo":"kubernetes/kubernetes","slug":"can-t-adopt-replicaset-v-v-v-v","errorCode":null,"errorMessage":"can't adopt ReplicaSet %v/%v (%v): %v","messagePattern":"can't adopt ReplicaSet (.+?)/(.+?) \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/controller/controller_ref_manager.go","lineNumber":350,"sourceCode":"\n\tfor _, rs := range sets {\n\t\tok, err := m.ClaimObject(ctx, rs, match, adopt, release)\n\t\tif err != nil {\n\t\t\terrlist = append(errlist, err)\n\t\t\tcontinue\n\t\t}\n\t\tif ok {\n\t\t\tclaimed = append(claimed, rs)\n\t\t}\n\t}\n\treturn claimed, utilerrors.NewAggregate(errlist)\n}\n\n// AdoptReplicaSet sends a patch to take control of the ReplicaSet. It returns\n// the error if the patching fails.\nfunc (m *ReplicaSetControllerRefManager) AdoptReplicaSet(ctx context.Context, rs *apps.ReplicaSet) error {\n\tif err := m.CanAdopt(ctx); err != nil {\n\t\treturn fmt.Errorf(\"can't adopt ReplicaSet %v/%v (%v): %v\", rs.Namespace, rs.Name, rs.UID, err)\n\t}\n\t// Note that ValidateOwnerReferences() will reject this patch if another\n\t// OwnerReference exists with controller=true.\n\tpatchBytes, err := ownerRefControllerPatch(m.Controller, m.controllerKind, rs.UID)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn m.rsControl.PatchReplicaSet(ctx, rs.Namespace, rs.Name, patchBytes)\n}\n\n// ReleaseReplicaSet sends a patch to free the ReplicaSet from the control of the Deployment controller.\n// It returns the error if the patching fails. 404 and 422 errors are ignored.\nfunc (m *ReplicaSetControllerRefManager) ReleaseReplicaSet(ctx context.Context, replicaSet *apps.ReplicaSet) error {\n\tlogger := klog.FromContext(ctx)\n\tlogger.V(2).Info(\"Patching ReplicaSet to remove its controllerRef\", \"replicaSet\", klog.KObj(replicaSet), \"gvk\", m.controllerKind, \"controller\", m.Controller.GetName())\n\tpatchBytes, err := GenerateDeleteOwnerRefStrategicMergeBytes(replicaSet.UID, []types.UID{m.Controller.GetUID()})\n\tif err != nil {\n\t\treturn err","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/kubernetes/kubernetes/blob/94c136764292cc5fac976c0de6587daaea56410f/pkg/controller/controller_ref_manager.go#L332-L368","documentation":"Returned by ReplicaSetControllerRefManager.AdoptReplicaSet when CanAdopt fails before the owner-reference patch is applied. Identical mechanism to Pod adoption: CanAdopt (often RecheckDeletionTimestamp) re-checks the parent and rejects adoption if the parent is being deleted or the re-GET errors. Bubbles up via ClaimReplicaSets as part of an aggregated error.","triggerScenarios":"ClaimReplicaSets -> ClaimObject -> adopt -> AdoptReplicaSet -> CanAdopt(ctx) errors. Typical: the parent Deployment is being deleted (DeletionTimestamp set) when the ReplicaSet controller tries to adopt orphaned ReplicaSets; or the parent GET fails.","commonSituations":"Deployment deletion in progress; parent (Deployment) UID mismatch because it was recreated; apiserver GET transient failure; multiple controllers (e.g., old and new deployment controller) racing.","solutions":["During parent Deployment deletion this is expected; the ReplicaSet controller will release rather than adopt.","If the parent flaps (rapid delete/recreate), stabilize the parent lifecycle.","Verify apiserver health if GET errors dominate.","Inspect the wrapped error to classify deletion vs network."],"exampleFix":"// before\nif err := m.CanAdopt(ctx); err != nil {\n    return fmt.Errorf(\"can't adopt ReplicaSet %v/%v (%v): %v\", rs.Namespace, rs.Name, rs.UID, err)\n}\n// after: log-and-skip during parent teardown to avoid noisy aggregated errors\nif err := m.CanAdopt(ctx); err != nil {\n    klog.FromContext(ctx).V(3).Info(\"Skipping ReplicaSet adoption\", \"rs\", klog.KObj(rs), \"reason\", err)\n    return fmt.Errorf(\"can't adopt ReplicaSet %v/%v (%v): %v\", rs.Namespace, rs.Name, rs.UID, err)\n}","handlingStrategy":"retry","validationCode":"// Pre-check parent Deployment is stable before adopting ReplicaSets\nparent, err := deploymentGetter.Get(ctx)\nif err != nil || parent.GetDeletionTimestamp() != nil {\n    return nil\n}","typeGuard":null,"tryCatchPattern":"claimed, err := m.ClaimReplicaSets(ctx, sets)\nif err != nil {\n    if isParentDeletionError(err) { return claimed, nil }\n    return claimed, err\n}","preventionTips":["Avoid deleting and immediately recreating parent Deployments.","Use RecheckDeletionTimestamp to gate ReplicaSet adoption.","Treat aggregated adoption errors containing 'has just been deleted' as expected during teardown."],"tags":["kubernetes-controller","owner-references","replicaset","adoption","garbage-collection"],"backgroundTag":null,"analyzedSha":"94c136764292cc5fac976c0de6587daaea56410f","analyzedAt":"2026-08-08T23:58:27.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}