Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Add functionality to stop and restart processes #25

Merged
merged 4 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/provider/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ pub enum StackableError {
"The following config maps were specified in a pod but not found: {missing_config_maps:?}"
)]
MissingConfigMapsError { missing_config_maps: Vec<String> },
#[error("An object received from Kubernetes didn't contain a required field: {field_name}")]
IllegalKubeObject { field_name: String },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
16 changes: 14 additions & 2 deletions src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use kubelet::provider::Provider;
use log::{debug, error};

use crate::provider::error::StackableError;
use crate::provider::error::StackableError::{CrdMissing, KubeError, PodValidationError};
use crate::provider::error::StackableError::{
CrdMissing, IllegalKubeObject, KubeError, PodValidationError,
};
use crate::provider::repository::package::Package;
use crate::provider::states::downloading::Downloading;
use crate::provider::states::terminated::Terminated;
Expand Down Expand Up @@ -155,7 +157,17 @@ impl Provider for StackableProvider {

async fn initialize_pod_state(&self, pod: &Pod) -> anyhow::Result<Self::PodState> {
let service_name = pod.name();
let service_uid = String::from(pod.as_kube_pod().metadata.uid.as_ref().unwrap());

// Extract uid from pod object, if this fails we return an error -
// this should not happen, as all objects we get from Kubernetes should have
// a uid set!
let service_uid = if let Some(uid) = pod.as_kube_pod().metadata.uid.as_ref() {
uid.to_string()
} else {
return Err(anyhow::Error::new(IllegalKubeObject {
field_name: "uid".to_string(),
}));
};
let parcel_directory = self.parcel_directory.clone();
// TODO: make this configurable
let download_directory = parcel_directory.join("_download");
Expand Down
3 changes: 2 additions & 1 deletion src/provider/states/stopping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ impl State<PodState> for Stopping {
if let Some(child) = &pod_state.process_handle {
info!(
"Received stop command for service {}, stopping process with pid {}",
pod_state.service_name, &1
pod_state.service_name,
child.id()
);
}
Transition::next(self, Stopped)
Expand Down