-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kube-core: Add Restart marker and request.
Signed-off-by: Adrian Pistol <vifino@tty.sh>
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ pub mod response; | |
|
||
pub mod subresource; | ||
|
||
pub mod util; | ||
|
||
pub mod watch; | ||
pub use watch::WatchEvent; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |