use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::pack::PackMetadata;
use crate::values::Values;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Release {
pub name: String,
pub namespace: String,
pub revision: u32,
pub status: ReleaseStatus,
pub pack: PackMetadata,
pub values: Values,
pub manifest: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[non_exhaustive]
pub enum ReleaseStatus {
#[default]
Unknown,
Deployed,
Uninstalled,
Superseded,
Failed,
Uninstalling,
PendingInstall,
PendingUpgrade,
PendingRollback,
}
impl std::fmt::Display for ReleaseStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Unknown => "unknown",
Self::Deployed => "deployed",
Self::Uninstalled => "uninstalled",
Self::Superseded => "superseded",
Self::Failed => "failed",
Self::Uninstalling => "uninstalling",
Self::PendingInstall => "pending-install",
Self::PendingUpgrade => "pending-upgrade",
Self::PendingRollback => "pending-rollback",
};
write!(f, "{}", s)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReleaseInfo {
pub name: String,
pub namespace: String,
pub revision: u32,
pub is_install: bool,
pub is_upgrade: bool,
pub service: String,
}
impl ReleaseInfo {
pub fn for_install(name: &str, namespace: &str) -> Self {
Self {
name: name.to_string(),
namespace: namespace.to_string(),
revision: 1,
is_install: true,
is_upgrade: false,
service: "Sherpack".to_string(),
}
}
pub fn for_upgrade(name: &str, namespace: &str, revision: u32) -> Self {
Self {
name: name.to_string(),
namespace: namespace.to_string(),
revision,
is_install: false,
is_upgrade: true,
service: "Sherpack".to_string(),
}
}
}