The client raise an exception if there is an endpoint slice with no endpoints
What happened (please include outputs or screenshots): Have the endpoint slice with no endpoints (just deleted the deployment):
kubectl get endpointslices.discovery.k8s.io
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
ac-arpserver-svc-8vmcx IPv4 8080,8890,8888 + 1 more... 10.244.0.141,10.244.0.142,10.244.0.143 11d
ac-backend-svc-87m26 IPv4 8000 10.244.0.103,10.244.0.105,10.244.0.139 11d
ac-configsync-svc-4dcgp IPv4 <unset> <unset> 11d
ac-monitoring-svc-nlmgq IPv4 9007 10.244.0.113,10.244.0.111,10.244.0.112 11d
cm-nginx-svc-lnqjx IPv4 8080 10.244.0.167,10.244.0.168,10.244.0.169 25h
kubernetes IPv4 8443 192.168.49.2 14d
Try to get a endpoint slice:
from kubernetes import client, config
config.load_incluster_config()
ep = client.DiscoveryV1Api().list_namespaced_endpoint_slice(namespace = "default", watch = False).items
Got the error:
Traceback (most recent call last):
File "/root/bug.py", line 5, in <module>
ep = client.DiscoveryV1Api().list_namespaced_endpoint_slice(namespace = "default", watch = False).items
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api/discovery_v1_api.py", line 828, in list_namespaced_endpoint_slice
return self.list_namespaced_endpoint_slice_with_http_info(namespace, **kwargs) # noqa: E501
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api/discovery_v1_api.py", line 947, in list_namespaced_endpoint_slice_with_http_info
return self.api_client.call_api(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 348, in call_api
return self.__call_api(resource_path, method,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 192, in __call_api
return_data = self.deserialize(response_data, response_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 264, in deserialize
return self.__deserialize(data, response_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
return self.__deserialize_model(data, klass)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 639, in __deserialize_model
kwargs[attr] = self.__deserialize(value, attr_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 280, in __deserialize
return [self.__deserialize(sub_data, sub_kls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 303, in __deserialize
return self.__deserialize_model(data, klass)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 641, in __deserialize_model
instance = klass(**kwargs)
^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/models/v1_endpoint_slice.py", line 70, in __init__
self.endpoints = endpoints
^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/kubernetes/client/models/v1_endpoint_slice.py", line 147, in endpoints
raise ValueError("Invalid value for `endpoints`, must not be `None`") # noqa: E501
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid value for `endpoints`, must not be `None`
What you expected to happen: Expected to get something like this:
{
"addressType": "IPv4",
"endpoints": [],
"metadata": {
...
How to reproduce it (as minimally and precisely as possible): Create a deployment, then a Service, then just kubectl delete -f deployment.yaml. Next try to run:
from kubernetes import client, config
config.load_incluster_config()
ep = client.DiscoveryV1Api().list_namespaced_endpoint_slice(namespace = "default", watch = False).items
Anything else we need to know?: I fixed it by just commenting on the raise of the exception and passing [] to the endpoints in kubernetes/client/models/v1_endpoint_slice.py:
def endpoints(self, endpoints):
"""Sets the endpoints of this V1EndpointSlice.
endpoints is a list of unique endpoints in this slice. Each slice may include a maximum of 1000 endpoints. # noqa: E501
:param endpoints: The endpoints of this V1EndpointSlice. # noqa: E501
:type: list[V1Endpoint]
"""
if self.local_vars_configuration.client_side_validation and endpoints is None: # noqa: E501
#raise ValueError("Invalid value for `endpoints`, must not be `None`") # noqa: E501
endpoints = []
self._endpoints = endpoints
Environment:
- Kubernetes version (
kubectl version): Client Version: v1.33.2 Kustomize Version: v5.6.0 Server Version: v1.33.1 - OS (e.g., MacOS 10.13.6): Alpine Linux v3.22
- Python version (
python --version) Python 3.12.11 - Python client version (
pip list | grep kubernetes) kubernetes 32.0.1
/assign
Invalid value for
endpoints, must not beNone
This validation in this client is auto-generated based on the upstream Kubernetes openapi spec. It sounds to me that the upstream spec is incorrectly marking the endpoints filed to be required, but in reality it should be optional.
It may be another occurrence of https://github.com/kubernetes-client/gen/issues/52. Could you check that issue? If it's the case, the correct way of fixing it is to change the upstream Kubernetes openapi spec to mark the field as optional.
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
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/staleis applied - After 30d of inactivity since
lifecycle/stalewas applied,lifecycle/rottenis applied - After 30d of inactivity since
lifecycle/rottenwas 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
I’m still encountering this issue on current versions (Python 3.12.3, kubernetes_asyncio==32.3.2). Confirming it's still reproducible and relevant today.