-
-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to do a rolling restart of a deployment? #630
Comments
We don't have a lot of special object handling herein, although i believe the trick that Going to mark this as a potential utils inclusion. |
For clarity: spec:
template:
metadata:
annotations:
kubectl.kubernetes.io/restartedAt: "2021-09-09T11:05:22+01:00" This can be done with the let patch = serde_json::json!({
"apiVersion": "apps/v1",
"kind": "Deployment",
"spec": {
"template": {
"metadata": {
"annotations": {
"kube.kubernetes.io/restartedAt": Utc::now().to_rfc3339()
}
}
}
}
});
let res = api.patch(mydeploy, &ssapply, &Patch::Apply(patch)).await?; But I think we should have some helper behaviour like this in a |
Hello @clux, thank you for your further comment. I've made your snippet compile in my code (but didn't get a chance to test it yet), but I'd definitly enjoy a generic Thank you so much! |
Hello again. After a bit of trouble I had with not specifying the /// Restart a Kubernetes Deployment by name.
async fn restart_deployment(&self, name: &str) -> Result<()> {
let deployments: Api<Deployment> = Api::namespaced(self.client.clone(), "<SNIP>");
let patch = serde_json::json!({
"apiVersion": "apps/v1",
"kind": "Deployment",
"spec": {
"template": {
"metadata": {
"annotations": {
"kube.kubernetes.io/restartedAt": Utc::now().to_rfc3339()
}
}
}
}
});
let mut patchparams = PatchParams::default();
patchparams.field_manager = Some(String::from("merge"));
deployments
.patch(name, &patchparams, &Patch::Apply(patch))
.await?;
Ok(())
} Thank you once again and I'd be very glad to assist in adding a PS: Sorry for the double-post. Too little caffeine. |
Awesome, that's great to hear. You can use I think this would be a great addition that's probably not too bad to contribute first time. Sketch
impl<K> Api<K>
where K: Restart + More? {
pub fn restart(name: &str) -> Result<K> { /*call self.requests.restart(name) and use it with the client (like most api calls)*/ }
} |
That sounds like a good plan. I'd implement the So my questions before I start:
|
You probably don't want to use server-side apply for this, since that will prevent anyone else from updating that annotation for any other reason (such as kubectl itself). Consider using a merge patch instead? Also, |
You should be able to use |
You can get the Pods won't work with the same patch, but also restarting pods would be different. You'd probably delete the pod. Even kubectl doesn't support it:
|
@teozkr : would the field-manager thing be a problem if we are patching with the annotation EDIT: In particular, this is what happens when you do it with - apiVersion: apps/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:template:
f:metadata:
f:annotations:
f:kubectl.kubernetes.io/restartedAt: {}
manager: kubectl-rollout
operation: Update
time: "2021-09-14T15:23:12Z" EDIT: kubectl rollout source |
I've changed it to be a merge patch and since I'll require K to be |
Actually, since the |
Hello.
I'm developing a project which needs to occasionally restart deployments.
There does not seem to be much special handling for deployments, only for pods.
Could you be so kind as to show me how to something akin to
kubectl rollout restart
?Thank you so much.
The text was updated successfully, but these errors were encountered: