Skip to main content

managed_lease

Function managed_lease 

Source
pub fn managed_lease(
    kind: RepositoryKind,
    namespace: &str,
    name: &str,
    cluster: Option<&str>,
) -> String
Expand description

The logical maintenance-lease string the operator uses for a repository’s DEFAULT-MANAGED Maintenance (ADR §3.7). Single derivation, shared by the managed-Maintenance projection and the bootstrap mover’s initial kopia owner stamp, so they cannot drift.

cluster is Repository/ClusterRepository.spec.identityDefaults.cluster (M1/M5): None keeps the original, pre-multi-cluster format (a same-named ClusterRepository/Repository in two clusters would otherwise derive the SAME lease and race each other’s maintenance on a shared repo — kopia has no cross-host maintenance lock of its own, only this owner lease); Some(c) inserts the cluster as the second path segment so each cluster claims a distinct lease (and, via kopia_lease_identity, a distinct kopia owner) for what is otherwise the same repository name.

use kopiur_api::common::RepositoryKind;
use kopiur_api::maintenance::managed_lease;

assert_eq!(
    managed_lease(RepositoryKind::Repository, "media", "nas", None),
    "kopiur/media/nas"
);
assert_eq!(
    managed_lease(RepositoryKind::Repository, "media", "nas", Some("east")),
    "kopiur/east/media/nas"
);
assert_eq!(
    managed_lease(RepositoryKind::ClusterRepository, "ignored", "shared", None),
    "kopiur/clusterrepository/shared"
);
assert_eq!(
    managed_lease(RepositoryKind::ClusterRepository, "ignored", "shared", Some("east")),
    "kopiur/east/clusterrepository/shared"
);