python icon indicating copy to clipboard operation
python copied to clipboard

create_namespaced_custom_object return404

Open shixinlishixinli opened this issue 2 years ago • 1 comments

i try to use create_namespaced_custom_object , but the return is 404

this is the code

from kubernetes import client, config

config.load_kube_config()

api_instance = client.CustomObjectsApi()

metric_object = { 'apiVersion': 'metrics.k8s.io/v1beta1', 'kind': 'MetricValue', 'metadata': { 'name': 'my-metric', }, 'spec': { 'type': 'Gauge', 'value': 10.0, }, }

response = api_instance.create_namespaced_custom_object( group='metrics.k8s.io', version='v1beta1', namespace='kube-system', plural='custom-metrics', body=metric_object, )

print(response)

this is the v1beta1/metrics.k8s.io

kubectl describe apiservice v1beta1.metrics.k8s.io Name: v1beta1.metrics.k8s.io Namespace: Labels: k8s-app=metrics-server Annotations: API Version: apiregistration.k8s.io/v1 Kind: APIService Metadata: Creation Timestamp: 2023-11-21T08:12:51Z Resource Version: 9213218 UID: 602824a6-306d-4483-8c7b-b0926f67a3a0 Spec: Group: metrics.k8s.io Group Priority Minimum: 100 Insecure Skip TLS Verify: true Service: Name: metrics-server Namespace: kube-system Port: 443 Version: v1beta1 Version Priority: 100 Status: Conditions: Last Transition Time: 2023-11-21T08:14:23Z Message: all checks passed Reason: Passed Status: True Type: Available Events:

this is the return

File "python_custom3.py", line 23, in response = api_instance.create_namespaced_custom_object( File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/api/custom_objects_api.py", line 225, in create_namespaced_custom_object return self.create_namespaced_custom_object_with_http_info(group, version, namespace, plural, body, **kwargs) # noqa: E501 File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/api/custom_objects_api.py", line 344, in create_namespaced_custom_object_with_http_info return self.api_client.call_api( File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 348, in call_api return self.__call_api(resource_path, method, File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 180, in __call_api response_data = self.request( File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 391, in request return self.rest_client.POST(url, File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/rest.py", line 276, in POST return self.request("POST", url, File "/home/lisa/.local/lib/python3.8/site-packages/kubernetes/client/rest.py", line 235, in request raise ApiException(http_resp=r) kubernetes.client.exceptions.ApiException: (404) Reason: Not Found HTTP response headers: HTTPHeaderDict({'Audit-Id': '77a53926-8a21-4d52-a9e8-368cd9e6c5f7, 77a53926-8a21-4d52-a9e8-368cd9e6c5f7', 'Cache-Control': 'no-cache, private, no-cache, private', 'Content-Length': '174', 'Content-Type': 'application/json', 'Date': 'Wed, 22 Nov 2023 02:20:37 GMT', 'X-Kubernetes-Pf-Flowschema-Uid': '1ad69f02-edd4-4b78-a504-4d67bc50489e', 'X-Kubernetes-Pf-Prioritylevel-Uid': '1e2f2c03-f778-49ef-bc54-b77e88e44420'}) HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the server could not find the requested resource","reason":"NotFound","details":{},"code":404}

Best Lisa Shi

shixinlishixinli avatar Nov 22 '23 02:11 shixinlishixinli

Please check this example https://github.com/kubernetes-client/python/blob/master/examples/namespaced_custom_object.py and see if it resolves the question

roycaihw avatar Dec 18 '23 17:12 roycaihw

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Mar 17 '24 18:03 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Apr 16 '24 18:04 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar May 16 '24 19:05 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar May 16 '24 19:05 k8s-ci-robot