namespace EntKube.Web.Data; /// /// The lifecycle status of a managed CNPG cluster. Tracks where the cluster /// is in the provisioning/operational/teardown cycle. /// public enum CnpgClusterStatus { Creating, Running, Upgrading, Restoring, Failed, Deleting } /// /// A managed CloudNativePG cluster that EntKube provisions and controls. /// Each cluster lives on a Kubernetes cluster where the CNPG operator is installed. /// Optionally backed by a StorageLink (S3 bucket) for Barman backups and PITR. /// /// The cluster is represented as a CNPG Cluster CRD in Kubernetes. /// EntKube owns the full lifecycle: create, upgrade, backup, restore, delete. /// public class CnpgCluster { public Guid Id { get; set; } /// /// The tenant that owns this cluster. /// public Guid TenantId { get; set; } /// /// The Kubernetes cluster where this CNPG cluster runs. /// Must have the cloudnative-pg operator installed. /// public Guid KubernetesClusterId { get; set; } /// /// The name of the CNPG Cluster resource in Kubernetes (metadata.name). /// Lowercase, DNS-safe, max 63 chars. /// public required string Name { get; set; } /// /// The Kubernetes namespace where the cluster lives. /// public required string Namespace { get; set; } /// /// The major PostgreSQL version (e.g. "18", "17", "16"). /// Maps to the CNPG container image tag. /// public required string PostgresVersion { get; set; } /// /// Number of PostgreSQL instances (1 = standalone, 3 = HA with streaming replication). /// public int Instances { get; set; } = 3; /// /// PVC storage size for each instance (e.g. "10Gi", "50Gi"). /// public required string StorageSize { get; set; } /// /// Optional link to an S3 bucket for Barman backup/restore. /// When set, the cluster is configured with continuous WAL archiving /// and on-demand/scheduled base backups. /// public Guid? StorageLinkId { get; set; } /// /// Cron schedule for automated backups (e.g. "0 0 2 * * *" for daily at 2 AM). /// Null means no scheduled backups — only on-demand. /// public string? BackupSchedule { get; set; } /// /// Number of days to retain backups. The Barman Cloud Plugin uses this as the /// recovery window (e.g. "30d"). Expired backups are cleaned up automatically. /// public int RetentionDays { get; set; } = 30; /// /// Maximum number of completed Backup CRs to keep in Kubernetes. When exceeded /// during a cleanup, the oldest completed backups are deleted from K8s and the DB. /// Does not affect WAL archiving or Barman's own retention — use RetentionDays for that. /// public int MaxBackups { get; set; } = 20; /// /// True when the cluster was registered from an existing CNPG deployment (not provisioned by EntKube). /// Delete should offer "Unregister" (remove from EntKube only) in addition to full deletion. /// public bool IsExternal { get; set; } /// /// Current lifecycle status of the cluster. /// public CnpgClusterStatus Status { get; set; } = CnpgClusterStatus.Creating; /// /// The last error encountered during a lifecycle operation. /// Cleared on successful operations. /// public string? LastError { get; set; } public DateTime CreatedAt { get; set; } = DateTime.UtcNow; // Navigation public Tenant Tenant { get; set; } = null!; public KubernetesCluster KubernetesCluster { get; set; } = null!; public StorageLink? StorageLink { get; set; } public ICollection Databases { get; set; } = []; public ICollection Backups { get; set; } = []; }