Skip to content

Commit

Permalink
Update error names, error variant names, struct names
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Nov 20, 2023
1 parent 1d3b16a commit 7994db3
Show file tree
Hide file tree
Showing 26 changed files with 182 additions and 179 deletions.
32 changes: 16 additions & 16 deletions rust/stackable-cockpit/src/helm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct HelmRelease {

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HelmChart {
pub struct Chart {
pub release_name: String,
pub name: String,
pub repo: HelmChartRepo,
Expand All @@ -46,7 +46,7 @@ pub struct HelmRepoEntry {
}

#[derive(Debug, Snafu)]
pub enum HelmError {
pub enum Error {
#[snafu(display("failed to parse URL"))]
UrlParse { source: url::ParseError },

Expand Down Expand Up @@ -199,11 +199,11 @@ pub fn install_release_from_repo(
values_yaml: Option<&str>,
namespace: &str,
suppress_output: bool,
) -> Result<HelmInstallReleaseStatus, HelmError> {
) -> Result<HelmInstallReleaseStatus, Error> {
debug!("Install Helm release from repo");

if check_release_exists(release_name, namespace)? {
let release = get_release(release_name, namespace)?.ok_or(HelmError::InstallRelease {
let release = get_release(release_name, namespace)?.ok_or(Error::InstallRelease {
source: HelmInstallReleaseError::NoSuchRelease {
name: release_name.to_owned(),
},
Expand All @@ -222,7 +222,7 @@ pub fn install_release_from_repo(
},
);
} else {
return Err(HelmError::InstallRelease {
return Err(Error::InstallRelease {
source: HelmInstallReleaseError::ReleaseAlreadyInstalled {
requested_version: chart_version.into(),
name: release_name.into(),
Expand Down Expand Up @@ -271,7 +271,7 @@ fn install_release(
values_yaml: Option<&str>,
namespace: &str,
suppress_output: bool,
) -> Result<(), HelmError> {
) -> Result<(), Error> {
let result = helm_sys::install_helm_release(
release_name,
chart_name,
Expand All @@ -287,7 +287,7 @@ fn install_release(
error
);

return Err(HelmError::InstallRelease {
return Err(Error::InstallRelease {
source: HelmInstallReleaseError::HelmWrapperError { error },
});
}
Expand All @@ -301,7 +301,7 @@ pub fn uninstall_release(
release_name: &str,
namespace: &str,
suppress_output: bool,
) -> Result<HelmUninstallReleaseStatus, HelmError> {
) -> Result<HelmUninstallReleaseStatus, Error> {
debug!("Uninstall Helm release");

if check_release_exists(release_name, namespace)? {
Expand All @@ -313,7 +313,7 @@ pub fn uninstall_release(
err
);

return Err(HelmError::UninstallRelease { error: err });
return Err(Error::UninstallRelease { error: err });
}

return Ok(HelmUninstallReleaseStatus::Uninstalled(
Expand All @@ -333,7 +333,7 @@ pub fn uninstall_release(

/// Returns if a Helm release exists
#[instrument]
pub fn check_release_exists(release_name: &str, namespace: &str) -> Result<bool, HelmError> {
pub fn check_release_exists(release_name: &str, namespace: &str) -> Result<bool, Error> {
debug!("Check if Helm release exists");

// TODO (Techassi): Handle error
Expand All @@ -342,7 +342,7 @@ pub fn check_release_exists(release_name: &str, namespace: &str) -> Result<bool,

/// Returns a list of Helm releases
#[instrument]
pub fn list_releases(namespace: &str) -> Result<Vec<HelmRelease>, HelmError> {
pub fn list_releases(namespace: &str) -> Result<Vec<HelmRelease>, Error> {
debug!("List Helm releases");

let result = helm_sys::list_helm_releases(namespace);
Expand All @@ -353,15 +353,15 @@ pub fn list_releases(namespace: &str) -> Result<Vec<HelmRelease>, HelmError> {
err
);

return Err(HelmError::ListReleases { error: err });
return Err(Error::ListReleases { error: err });
}

serde_json::from_str(&result).context(DeserializeJsonSnafu)
}

/// Returns a single Helm release by `release_name`.
#[instrument]
pub fn get_release(release_name: &str, namespace: &str) -> Result<Option<HelmRelease>, HelmError> {
pub fn get_release(release_name: &str, namespace: &str) -> Result<Option<HelmRelease>, Error> {
debug!("Get Helm release");

Ok(list_releases(namespace)?
Expand All @@ -371,7 +371,7 @@ pub fn get_release(release_name: &str, namespace: &str) -> Result<Option<HelmRel

/// Adds a Helm repo with `repo_name` and `repo_url`.
#[instrument]
pub fn add_repo(repository_name: &str, repository_url: &str) -> Result<(), HelmError> {
pub fn add_repo(repository_name: &str, repository_url: &str) -> Result<(), Error> {
debug!("Add Helm repo");

let result = helm_sys::add_helm_repository(repository_name, repository_url);
Expand All @@ -382,15 +382,15 @@ pub fn add_repo(repository_name: &str, repository_url: &str) -> Result<(), HelmE
err
);

return Err(HelmError::AddRepo { error: err });
return Err(Error::AddRepo { error: err });
}

Ok(())
}

/// Retrieves the Helm index file from the repository URL.
#[instrument]
pub async fn get_helm_index<T>(repo_url: T) -> Result<HelmRepo, HelmError>
pub async fn get_helm_index<T>(repo_url: T) -> Result<HelmRepo, Error>
where
T: AsRef<str> + std::fmt::Debug,
{
Expand Down
10 changes: 5 additions & 5 deletions rust/stackable-cockpit/src/platform/demo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

use crate::common::list::{List, SpecIter};
use crate::common::list::SpecIter;

mod spec;

Expand All @@ -12,13 +12,13 @@ pub use spec::*;
#[serde(rename_all = "camelCase")]
pub struct DemosV2 {
#[serde(with = "serde_yaml::with::singleton_map_recursive")]
demos: IndexMap<String, DemoSpecV2>,
demos: IndexMap<String, DemoSpec>,
}

impl SpecIter<DemoSpecV2> for DemosV2 {
fn inner(&self) -> &IndexMap<String, DemoSpecV2> {
impl SpecIter<DemoSpec> for DemosV2 {
fn inner(&self) -> &IndexMap<String, DemoSpec> {
&self.demos
}
}

pub type DemoList = List<DemosV2, DemoSpecV2>;
pub type List = crate::common::list::List<DemosV2, DemoSpec>;
28 changes: 14 additions & 14 deletions rust/stackable-cockpit/src/platform/demo/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
common::manifest::ManifestSpec,
platform::{
cluster::{ResourceRequests, ResourceRequestsError},
release::ReleaseList,
stack::{StackError, StackList},
release::List,
stack,
},
utils::params::{Parameter, RawParameter, RawParameterParseError},
xfer::FileTransferClient,
Expand All @@ -21,21 +21,21 @@ pub type RawDemoParameter = RawParameter;
pub type DemoParameter = Parameter;

#[derive(Debug, Snafu)]
pub enum DemoError {
pub enum Error {
#[snafu(display("no stack named '{name}'"))]
NoSuchStack { name: String },

#[snafu(display("failed to install stack because some prerequisites failed"))]
StackPrerequisites { source: StackError },
StackPrerequisites { source: stack::Error },

#[snafu(display("failed to install release associated with stack"))]
StackInstallRelease { source: StackError },
StackInstallRelease { source: stack::Error },

#[snafu(display("failed to install stack manifests"))]
InstallStackManifests { source: StackError },
InstallStackManifests { source: stack::Error },

#[snafu(display("failed to install demo manifests"))]
InstallDemoManifests { source: StackError },
InstallDemoManifests { source: stack::Error },

#[snafu(display("demo resource requests error"), context(false))]
DemoResourceRequestsError { source: ResourceRequestsError },
Expand All @@ -51,7 +51,7 @@ pub enum DemoError {
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
pub struct DemoSpecV2 {
pub struct DemoSpec {
/// A short description of the demo
pub description: String,

Expand Down Expand Up @@ -84,20 +84,20 @@ pub struct DemoSpecV2 {
pub parameters: Vec<Parameter>,
}

impl DemoSpecV2 {
impl DemoSpec {
/// Checks if the prerequisites to run this demo are met. These checks
/// include:
///
/// - Does the demo support to be installed in the requested namespace?
/// - Does the cluster have enough resources available to run this demo?
#[instrument(skip_all)]
pub async fn check_prerequisites(&self, product_namespace: &str) -> Result<(), DemoError> {
pub async fn check_prerequisites(&self, product_namespace: &str) -> Result<(), Error> {
debug!("Checking prerequisites before installing demo");

// Returns an error if the demo doesn't support to be installed in the
// requested namespace
if !self.supports_namespace(product_namespace) {
return Err(DemoError::UnsupportedNamespace {
return Err(Error::UnsupportedNamespace {
requested: product_namespace.to_string(),
supported: self.supported_namespaces.clone(),
});
Expand All @@ -124,15 +124,15 @@ impl DemoSpecV2 {
#[allow(clippy::too_many_arguments)]
pub async fn install(
&self,
stack_list: StackList,
release_list: ReleaseList,
stack_list: stack::List,
release_list: List,
operator_namespace: &str,
product_namespace: &str,
stack_parameters: &[String],
demo_parameters: &[String],
transfer_client: &FileTransferClient,
skip_release: bool,
) -> Result<(), DemoError> {
) -> Result<(), Error> {
// Get the stack spec based on the name defined in the demo spec
let stack_spec = stack_list.get(&self.stack).context(NoSuchStackSnafu {
name: self.stack.clone(),
Expand Down
Loading

0 comments on commit 7994db3

Please sign in to comment.