python icon indicating copy to clipboard operation
python copied to clipboard

How to use field_selector

Open TracyBin opened this issue 9 years ago • 11 comments

hi,I want to list service in specified namespace. I call list_namespaced_service,but output error. This is my code:


field_selector = {'spec.selector': label}   //label:   {u'app': 'admin-test'}
service = v1.list_namespaced_service(namespace='default', pretty='true', field_selector=field_selector, watch=False)

error:

ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 05 Apr 2017 03:57:23 GMT', 'Content-Length': '240', 'Content-Type': 'application/json'})
HTTP response body: {
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "invalid selector: '{'spec.selector': {u'app': 'admin-test'}}'; can't understand '{'spec.selector': {u'app': 'admin-test'}}'",
  "code": 500
}

TracyBin avatar Apr 05 '17 04:04 TracyBin

If you know kubectl command to do this, just run the command with -v9 and you would see the format of selector kubectl sends to api server.

mbohlool avatar Apr 05 '17 09:04 mbohlool

sorry,I can't find it. I have solve this problem by scanning all service to find specified service

TracyBin avatar Apr 06 '17 04:04 TracyBin

can you post your solution here. It useful for other community members if they hit the same issue. Thanks.

mbohlool avatar Apr 06 '17 07:04 mbohlool

I want to find service belong to the deployment,but failed depend on field_selector. The solution is that list all services to find specified one that match labels

TracyBin avatar Apr 10 '17 10:04 TracyBin

@TracyBin Can you please reopen the issue? Looks like you have a snippet in the description that fails to work.

dims avatar Apr 10 '17 10:04 dims

@dims ok, I have been reopened this issue

TracyBin avatar Apr 11 '17 03:04 TracyBin

I ran into this as well.

Reading the docs shows it is a str, but doesn't give a good, valid, example of it anywhere.

This gets appended to a dictionary of items to pass into a raw request call down the line, in which kubernetes expects it in the form of 'key=value'. So, for example, if I'm trying to find a secret named star-cert, the following should return the object:

kube.list_namespaced_secret('default', field_selector='metadata.name=star-cert') 

aguynamedjoetoo avatar Jun 28 '17 20:06 aguynamedjoetoo

Dose field_selector support regex?

YitongFeng avatar Oct 09 '18 05:10 YitongFeng

@YitongFeng I'm afraid not, https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/#supported-operators

tomplus avatar Oct 09 '18 06:10 tomplus

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Apr 26 '19 01:04 fejta-bot

/close

TracyBin avatar Apr 26 '19 01:04 TracyBin