-
Notifications
You must be signed in to change notification settings - Fork 107
Is it possible to do pod eviction? #114
Comments
You want https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#create-eviction-pod-v1-core func evictPod(ctx context.Context, c *k8s.Client, namespace, name string) error {
var pod corev1.Pod
if err := c.Get(ctx, namespace, name, &pod); err != nil {
return fmt.Errorf("get pod %s/%s: %v", namespace, name, err)
}
if err := c.Create(ctx, &pod, k8s.Subresource("eviction")); err != nil {
return fmt.Errorf("creating pod eviction: %v", err)
}
// TODO: wait for pod to actually be evicted
return nil
} (haven't tested that code) |
Hi @ericchiang, Thanks for the reply!
But it should go to
I think this is caused by the fact that Do you know a way I could get around this? Thanks! |
Ah that's a bug then :)
The URL should contain the "{name}" in the path
…On Mon, Mar 18, 2019, 2:18 PM Mark Vincze ***@***.***> wrote:
Hi @ericchiang <https://github.com/ericchiang>,
Thanks for the reply!
I tested this code, but so far I couldn't get it to work. The issue is
that the Create call will try sending the POST to the URL
/api/v1/namespaces/{namespace}/pods/eviction
But it should go to
/api/v1/namespaces/{namespace}/pods/{name}/eviction
I think this is caused by the fact that Create internally passes false to
the resourceURL function in the withName parameter.
I thought about using Update instead, but that sends a PUT, so that's
also not good.
Do you know a way I could get around this?
Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#114 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ACO_XUQRO9BmtAZq9t5Ym7QuNKM0WxOHks5vYAKxgaJpZM4b4qeJ>
.
|
I guess what happens is normally for
But in this case we need the name because we're creating a subresource. So maybe the code here should be changed so that if there is a subresource among the |
Btw I tried just manually passing in
|
So it seems that this endpoint needs the eviction to be sent in the
|
This is not an issue report, but a question.
I'm implementing a piece of code which retrieves the list of nodes and list of pods, and then based on some conditions I'd like to evict some pods. Listing the nodes and pods and getting their details works very nicely, but I couldn't find a way to do pod eviction yet.
Is it possible to do pod eviction with this library? I couldn't find a dedicated function for it, but in the K8s docs I see there is a REST API endpoint, which needs POSTing a small Json input to the route
/api/v1/namespaces/default/pods/{podname}/eviction
. Is there maybe a way with the library to send an arbitrary REST request to the K8s API, but reuse the HTTP client with the base address and the necessary headers, which is maintained by the client?The text was updated successfully, but these errors were encountered: