Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions src/provider/states.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use k8s_openapi::api::core::v1::ContainerStatus as KubeContainerStatus;
use k8s_openapi::api::core::v1::PodCondition as KubePodCondition;
use kubelet::pod::Phase;

pub(crate) mod creating_config;
pub(crate) mod creating_service;
pub(crate) mod downloading;
Expand All @@ -22,3 +26,24 @@ macro_rules! fail_fatal {
return Transition::Complete(Err(aerr));
}};
}

/// Create basic Pod status patch with container status and pod conditions
pub fn make_status_with_containers_and_condition(
phase: Phase,
reason: &str,
container_statuses: Vec<KubeContainerStatus>,
init_container_statuses: Vec<KubeContainerStatus>,
pod_conditions: Vec<KubePodCondition>,
) -> serde_json::Value {
serde_json::json!(
{
"status": {
"phase": phase,
"reason": reason,
"containerStatuses": container_statuses,
"initContainerStatuses": init_container_statuses,
"conditions": pod_conditions
}
}
)
}
37 changes: 32 additions & 5 deletions src/provider/states/running.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use k8s_openapi::api::core::v1::{
ContainerState, ContainerStateRunning, ContainerStatus as KubeContainerStatus,
ContainerState, ContainerStateRunning, ContainerStatus as KubeContainerStatus, PodCondition,
};
use kubelet::pod::Pod;
use kubelet::state::prelude::*;
Expand All @@ -8,12 +8,25 @@ use log::{debug, error, trace};

use crate::provider::states::failed::Failed;
use crate::provider::states::installing::Installing;
use crate::provider::states::make_status_with_containers_and_condition;
use crate::provider::states::stopping::Stopping;
use crate::provider::PodState;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time;
use k8s_openapi::chrono;

#[derive(Debug, TransitionTo)]
#[transition_to(Stopping, Failed, Running, Installing)]
pub struct Running {}
pub struct Running {
pub transition_time: Time,
}

impl Default for Running {
fn default() -> Self {
Self {
transition_time: Time(chrono::offset::Utc::now()),
}
}
}

#[async_trait::async_trait]
impl State<PodState> for Running {
Expand Down Expand Up @@ -66,7 +79,7 @@ impl State<PodState> for Running {

async fn json_status(
&self,
_pod_state: &mut PodState,
pod_state: &mut PodState,
pod: &Pod,
) -> anyhow::Result<serde_json::Value> {
let state = ContainerState {
Expand All @@ -83,11 +96,25 @@ impl State<PodState> for Running {
state: Some(state),
..Default::default()
});
Ok(make_status_with_containers(
let condition = PodCondition {
last_probe_time: None,
last_transition_time: Some(self.transition_time.clone()),
message: Some(String::from("Service is running")),
reason: Some(String::from("Running")),
status: "True".to_string(),
type_: "Ready".to_string(),
};
let status = make_status_with_containers_and_condition(
Phase::Running,
"Running",
container_status,
vec![],
))
vec![condition],
);
debug!(
"Patching status for running servce [{}] with: [{}]",
pod_state.service_name, status
);
Ok(status)
}
}
7 changes: 6 additions & 1 deletion src/provider/states/starting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ impl State<PodState> for Starting {
// Store the child handle in the podstate so that later states
// can use it
pod_state.process_handle = Some(child);
return Transition::next(self, Running {});
return Transition::next(
self,
Running {
..Default::default()
},
);
}
Err(error) => {
let error_message = format!("Failed to start process with error {}", error);
Expand Down