Skip to content

Commit

Permalink
kube-core: Add Restart marker and request.
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Pistol <vifino@tty.sh>
  • Loading branch information
vifino committed Sep 20, 2021
1 parent 00de37e commit 7f9360a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions kube-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ form_urlencoded = "1.0.1"
http = "0.2.2"
json-patch = { version = "0.2.6", optional = true }
once_cell = "1.8.0"
chrono = "0.4.19"

[dependencies.k8s-openapi]
version = "0.13.0"
Expand Down
2 changes: 2 additions & 0 deletions kube-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub mod response;

pub mod subresource;

pub mod util;

pub mod watch;
pub use watch::WatchEvent;

Expand Down
36 changes: 36 additions & 0 deletions kube-core/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Utils and helpers
use crate::{
params::{Patch, PatchParams},
Request, Result,
};
use chrono::Utc;
use k8s_openapi::api::apps::v1::{DaemonSet, Deployment, ReplicaSet, StatefulSet};

/// Restartable Resource marker trait
pub trait Restart {}

impl Restart for Deployment {}
impl Restart for DaemonSet {}
impl Restart for StatefulSet {}
impl Restart for ReplicaSet {}

impl Request {
/// Restart a resource
pub fn restart(&self, name: &str) -> Result<http::Request<Vec<u8>>> {
let patch = serde_json::json!({
"spec": {
"template": {
"metadata": {
"annotations": {
"kube.kubernetes.io/restartedAt": Utc::now().to_rfc3339()
}
}
}
}
});

let pparams = PatchParams::default();
self.patch(name, &pparams, &Patch::Merge(patch))
}
}

0 comments on commit 7f9360a

Please sign in to comment.