Skip to content

Commit

Permalink
Update error variants
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Nov 28, 2023
1 parent da3bdad commit a050a37
Show file tree
Hide file tree
Showing 29 changed files with 260 additions and 239 deletions.
10 changes: 6 additions & 4 deletions rust/stackable-cockpit/src/engine/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ pub enum Error {
CommandErroredOut { error: String },

#[snafu(display("missing required binary: {binary}"))]
MissingBinaryError { binary: String },
MissingBinary { binary: String },

#[snafu(display("failed to determine if Docker is running"))]
DockerError { source: docker::Error },
DockerCheckCommand { source: docker::Error },

#[snafu(display("failed to covert kind config to YAML"))]
ConfigSerialization { source: serde_yaml::Error },
Expand Down Expand Up @@ -71,11 +71,13 @@ impl Cluster {

// Check if required binaries are present
if let Some(binary) = binaries_present_with_name(&["docker", "kind"]) {
return Err(Error::MissingBinaryError { binary });
return Err(Error::MissingBinary { binary });
}

// Check if Docker is running
check_if_docker_is_running().await.context(DockerSnafu)?;
check_if_docker_is_running()
.await
.context(DockerCheckCommandSnafu)?;

debug!("Creating kind cluster config");
let config = Config::new(self.node_count, self.cp_node_count);
Expand Down
10 changes: 6 additions & 4 deletions rust/stackable-cockpit/src/engine/minikube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub enum Error {
MissingBinary { binary: String },

#[snafu(display("failed to execute minikube command"))]
CommandError { source: std::io::Error },
MinikubeCommand { source: std::io::Error },

#[snafu(display("failed to determine if Docker is running"))]
DockerError { source: docker::Error },
DockerCheckCommand { source: docker::Error },
}

#[derive(Debug)]
Expand Down Expand Up @@ -55,7 +55,9 @@ impl Cluster {
}

// Check if Docker is running
check_if_docker_is_running().await.context(DockerSnafu)?;
check_if_docker_is_running()
.await
.context(DockerCheckCommandSnafu)?;

// Create local cluster via minikube
debug!("Creating minikube cluster");
Expand All @@ -66,7 +68,7 @@ impl Cluster {
.args(["-p", self.name.as_str()])
.status()
.await
.context(CommandSnafu)?;
.context(MinikubeCommandSnafu)?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/helm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub enum InstallReleaseError {
/// is not typed, as the error is a plain string coming directly from the
/// FFI bindings.
#[snafu(display("helm error: {error}"))]
HelmWrapperError { error: String },
HelmWrapper { error: String },
}

#[derive(Debug)]
Expand Down Expand Up @@ -282,7 +282,7 @@ fn install_release(
);

return Err(Error::InstallRelease {
source: InstallReleaseError::HelmWrapperError { error },
source: InstallReleaseError::HelmWrapper { error },
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ impl Display for ResourceRequests {
#[derive(Debug, Snafu)]
pub enum ResourceRequestsError {
#[snafu(display("failed to create kube client"))]
KubeClientError { source: Error },
KubeClientCreate { source: Error },

#[snafu(display("failed to retrieve cluster info"))]
ClusterInfoError { source: Error },
ClusterInfo { source: Error },

#[snafu(display("failed to parse cpu resource requirements"))]
ParseCpuResourceRequirements {
Expand Down Expand Up @@ -92,7 +92,7 @@ impl ResourceRequests {
/// resources to the available ones in the current cluster. `object_name`
/// should be `stack` or `demo`.
pub async fn validate_cluster_size(&self, object_name: &str) -> Result<()> {
let kube_client = Client::new().await.context(KubeClientSnafu)?;
let kube_client = Client::new().await.context(KubeClientCreateSnafu)?;
let cluster_info = kube_client
.get_cluster_info()
.await
Expand Down
2 changes: 1 addition & 1 deletion rust/stackable-cockpit/src/platform/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to fetch data from kubernetes API"))]
KubeClientFetchError { source: k8s::Error },
KubeClientFetch { source: k8s::Error },

#[snafu(display("no credentials secret found"))]
NoSecret,
Expand Down
2 changes: 1 addition & 1 deletion rust/stackable-cockpit/src/platform/demo/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {
InstallDemoManifests { source: stack::Error },

#[snafu(display("demo resource requests error"), context(false))]
DemoResourceRequestsError { source: ResourceRequestsError },
DemoResourceRequests { source: ResourceRequestsError },

#[snafu(display("cannot install demo in namespace '{requested}', only '{}' supported", supported.join(", ")))]
UnsupportedNamespace {
Expand Down
10 changes: 5 additions & 5 deletions rust/stackable-cockpit/src/platform/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::k8s;
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to create kubernetes client"))]
KubeClientCreateError { source: k8s::Error },
KubeClientCreate { source: k8s::Error },

#[snafu(display("permission denied - try to create the namespace manually or choose an already existing one to which you have access to"))]
PermissionDenied,
Expand All @@ -20,12 +20,12 @@ pub async fn create_if_needed(name: String) -> Result<(), Error> {
.create_namespace_if_needed(name)
.await
.map_err(|err| match err {
k8s::Error::KubeError { source } => match source {
k8s::Error::KubeClientCreate { source } => match source {
kube::Error::Api(err) if err.code == 401 => Error::PermissionDenied,
_ => Error::KubeClientCreateError {
source: k8s::Error::KubeError { source },
_ => Error::KubeClientCreate {
source: k8s::Error::KubeClientCreate { source },
},
},
_ => Error::KubeClientCreateError { source: err },
_ => Error::KubeClientCreate { source: err },
})
}
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/release/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub enum Error {
OperatorSpecParse { source: operator::SpecParseError },

#[snafu(display("failed to install release using Helm"))]
HelmInstallError { source: helm::Error },
HelmInstall { source: helm::Error },

#[snafu(display("failed to uninstall release using Helm"))]
HelmUninstallError { source: helm::Error },
HelmUninstall { source: helm::Error },
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
2 changes: 1 addition & 1 deletion rust/stackable-cockpit/src/platform/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::utils::k8s::{self, ListParamsExt};
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to fetch data from kubernetes API"))]
KubeClientFetchError { source: k8s::Error },
KubeClientFetch { source: k8s::Error },

#[snafu(display("missing namespace for service '{service}'"))]
MissingServiceNamespace { service: String },
Expand Down
28 changes: 14 additions & 14 deletions rust/stackable-cockpit/src/platform/stack/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum Error {
/// This error indicates that parsing a string into stack / demo parameters
/// failed.
#[snafu(display("failed to parse demo / stack parameters"))]
ParameterError { source: IntoParametersError },
ParameterParse { source: IntoParametersError },

/// This error indicates that the requested release doesn't exist in the
/// loaded list of releases.
Expand All @@ -46,50 +46,50 @@ pub enum Error {

/// This error indicates that the release failed to install.
#[snafu(display("failed to install release"))]
ReleaseInstallError { source: release::Error },
ReleaseInstall { source: release::Error },

/// This error indicates that the Helm wrapper failed to add the Helm
/// repository.
#[snafu(display("failed to add Helm repository {repo_name}"))]
HelmAddRepositoryError {
HelmAddRepository {
source: helm::Error,
repo_name: String,
},

/// This error indicates that the Hlm wrapper failed to install the Helm
/// release.
#[snafu(display("failed to install Helm release {release_name}"))]
HelmInstallReleaseError {
HelmInstallRelease {
release_name: String,
source: helm::Error,
},

/// This error indicates that the creation of a kube client failed.
#[snafu(display("failed to create kubernetes client"))]
KubeClientCreateError { source: k8s::Error },
KubeClientCreate { source: k8s::Error },

/// This error indicates that the kube client failed to deloy manifests.
#[snafu(display("failed to deploy manifests using the kube client"))]
ManifestDeployError { source: k8s::Error },
ManifestDeploy { source: k8s::Error },

/// This error indicates that Helm chart options could not be serialized
/// into YAML.
#[snafu(display("failed to serialize Helm chart options"))]
SerializeOptionsError { source: serde_yaml::Error },
SerializeOptions { source: serde_yaml::Error },

#[snafu(display("stack resource requests error"), context(false))]
StackResourceRequestsError { source: ResourceRequestsError },
StackResourceRequests { source: ResourceRequestsError },

/// This error indicates that parsing a string into a path or URL failed.
#[snafu(display("failed to parse '{path_or_url}' as path/url"))]
PathOrUrlParseError {
PathOrUrlParse {
source: PathOrUrlParseError,
path_or_url: String,
},

/// This error indicates that receiving remote content failed.
#[snafu(display("failed to receive remote content"))]
TransferError { source: xfer::Error },
FileTransfer { source: xfer::Error },

/// This error indicates that the stack doesn't support being installed in
/// the provided namespace.
Expand Down Expand Up @@ -212,7 +212,7 @@ impl StackSpec {
let parameters = parameters
.to_owned()
.into_params(&self.parameters)
.context(ParameterSnafu)?;
.context(ParameterParseSnafu)?;

Self::install_manifests(
&self.manifests,
Expand All @@ -238,7 +238,7 @@ impl StackSpec {
let parameters = demo_parameters
.to_owned()
.into_params(valid_demo_parameters)
.context(ParameterSnafu)?;
.context(ParameterParseSnafu)?;

Self::install_manifests(manifests, &parameters, product_namespace, transfer_client).await?;
Ok(())
Expand Down Expand Up @@ -267,7 +267,7 @@ impl StackSpec {
let helm_chart: helm::Chart = transfer_client
.get(&helm_file, &Template::new(parameters).then(Yaml::new()))
.await
.context(TransferSnafu)?;
.context(FileTransferSnafu)?;

info!(
"Installing Helm chart {} ({})",
Expand Down Expand Up @@ -315,7 +315,7 @@ impl StackSpec {
let manifests = transfer_client
.get(&path_or_url, &Template::new(parameters))
.await
.context(TransferSnafu)?;
.context(FileTransferSnafu)?;

let kube_client = k8s::Client::new().await.context(KubeClientCreateSnafu)?;

Expand Down
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/stacklet/grafana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use snafu::ResultExt;
use crate::{
platform::{
service::get_endpoint_urls,
stacklet::{Error, KubeClientFetchSnafu, ServiceSnafu, Stacklet},
stacklet::{Error, KubeClientFetchSnafu, ServiceFetchSnafu, Stacklet},
},
utils::k8s::{Client, ListParamsExt, ProductLabel},
};
Expand All @@ -25,7 +25,7 @@ pub(super) async fn list(
let service_name = service.name_any();
let endpoints = get_endpoint_urls(kube_client, &service, &service_name)
.await
.context(ServiceSnafu)?;
.context(ServiceFetchSnafu)?;

stacklets.push(Stacklet {
conditions: Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/stacklet/minio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use snafu::ResultExt;
use crate::{
platform::{
service::get_endpoint_urls,
stacklet::{Error, KubeClientFetchSnafu, ServiceSnafu, Stacklet},
stacklet::{Error, KubeClientFetchSnafu, ServiceFetchSnafu, Stacklet},
},
utils::k8s::Client,
};
Expand All @@ -30,7 +30,7 @@ pub(super) async fn list(
let service_name = service.name_any();
let endpoints = get_endpoint_urls(kube_client, service, &service_name)
.await
.context(ServiceSnafu)?;
.context(ServiceFetchSnafu)?;

stacklets.push(Stacklet {
product: "minio".to_string(),
Expand Down
18 changes: 9 additions & 9 deletions rust/stackable-cockpit/src/platform/stacklet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ pub struct Stacklet {
#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to create kubernetes client"))]
KubeClientCreateError { source: k8s::Error },
KubeClientCreate { source: k8s::Error },

#[snafu(display("failed to fetch data from the kubernetes api"))]
KubeClientFetchError { source: k8s::Error },
KubeClientFetch { source: k8s::Error },

#[snafu(display("no namespace set for custom resource '{crd_name}'"))]
CustomCrdNamespaceError { crd_name: String },
CustomCrdNamespace { crd_name: String },

#[snafu(display("failed to deserialize cluster conditions from JSON"))]
DeserializeConditionsError { source: serde_json::Error },
DeserializeConditions { source: serde_json::Error },

#[snafu(display("service error"))]
ServiceError { source: service::Error },
#[snafu(display("failed to receive service information"))]
ServiceFetch { source: service::Error },
}

/// Lists all installed stacklets. If `namespace` is [`None`], stacklets from ALL
Expand Down Expand Up @@ -102,8 +102,8 @@ pub async fn get_credentials_for_product(
let credentials = match credentials::get(&kube_client, product_name, &product_cluster).await {
Ok(credentials) => credentials,
Err(credentials::Error::NoSecret) => None,
Err(credentials::Error::KubeClientFetchError { source }) => {
return Err(Error::KubeClientFetchError { source })
Err(credentials::Error::KubeClientFetch { source }) => {
return Err(Error::KubeClientFetch { source })
}
};

Expand Down Expand Up @@ -150,7 +150,7 @@ async fn list_stackable_stacklets(
let endpoints =
service::get_endpoints(kube_client, product_name, &object_name, &object_namespace)
.await
.context(ServiceSnafu)?;
.context(ServiceFetchSnafu)?;

stacklets.push(Stacklet {
namespace: Some(object_namespace),
Expand Down
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/stacklet/opensearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use snafu::ResultExt;
use crate::{
platform::{
service::get_endpoint_urls,
stacklet::{Error, KubeClientFetchSnafu, ServiceSnafu, Stacklet},
stacklet::{Error, KubeClientFetchSnafu, ServiceFetchSnafu, Stacklet},
},
utils::k8s::{Client, ListParamsExt, ProductLabel},
};
Expand All @@ -25,7 +25,7 @@ pub(super) async fn list(
let service_name = service.name_any();
let endpoints = get_endpoint_urls(kube_client, &service, &service_name)
.await
.context(ServiceSnafu)?;
.context(ServiceFetchSnafu)?;

// TODO: Add "Logs view" extra info from old stackablectl once "Extra info" field is supported.
// see https://github.com/stackabletech/stackablectl/blob/eda45945cfcf5c6581cf1b88c782d98fada8065f/src/services/opensearch.rs#L41
Expand Down
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/platform/stacklet/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use snafu::ResultExt;
use crate::{
platform::{
service::get_endpoint_urls,
stacklet::{Error, KubeClientFetchSnafu, ServiceSnafu, Stacklet},
stacklet::{Error, KubeClientFetchSnafu, ServiceFetchSnafu, Stacklet},
},
utils::k8s::Client,
};
Expand All @@ -26,7 +26,7 @@ pub(super) async fn list(
let service_name = service.name_any();
let endpoints = get_endpoint_urls(kube_client, &service, &service_name)
.await
.context(ServiceSnafu)?;
.context(ServiceFetchSnafu)?;

stacklets.push(Stacklet {
product: "prometheus".to_string(),
Expand Down
Loading

0 comments on commit a050a37

Please sign in to comment.