Code Monkey home page Code Monkey logo

Comments (6)

ericchiang avatar ericchiang commented on June 11, 2024

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)

from k8s.

markvincze avatar markvincze commented on June 11, 2024

Hi @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!

from k8s.

ericchiang avatar ericchiang commented on June 11, 2024

from k8s.

markvincze avatar markvincze commented on June 11, 2024

I guess what happens is normally for Create it's the correct thing to omit the {name}, for example if we create a pod, we want to POST to

/api/v1/namespaces/{namespace}/pods

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 ...options argument, then we pass in true instead of false as withName?

from k8s.

markvincze avatar markvincze commented on June 11, 2024

Btw I tried just manually passing in true as a test, but I'm getting a 400 with this response:

Failure 400 Eviction in version "v1beta1" cannot be handled as a Eviction: proto: wrong wireType = 2 for field GracePeriodSeconds

from k8s.

markvincze avatar markvincze commented on June 11, 2024

So it seems that this endpoint needs the eviction to be sent in the POST body, which has to look like this:

{
  "apiVersion": "policy/v1beta1",
  "kind": "Eviction",
  "metadata": {
    "name": "pod_name",
    "namespace": "namespace"
  }
}

from k8s.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.