java
java copied to clipboard
`Kubectl.get(V1EndpointSlice.class)` failed due to `endpoints: null`
Describe the bug
It is possible that a service does not have any endpoint, for example, when the corresponding deployment was scaled to zero. In this case, the EndpointSlice API returns endpoints: null. However, it will be rejected by the following validation rule:
https://github.com/kubernetes-client/java/blob/cbd3d1bb2cd1bd2f4aa18b80a1131e810dea9b79/kubernetes/src/main/java/io/kubernetes/client/openapi/models/V1EndpointSlice.java#L329-L332
Client Version
20.0.1
Kubernetes Version
1.29.0-eks-c417bb3
Java Version Java 21
To Reproduce Steps to reproduce the behavior:
- Create a service that cannot select any pod:
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app.kubernetes.io/name: proxy
ports:
- name: name-of-service-port
protocol: TCP
port: 80
targetPort: http-web-svc
EOF
- The
endpointsfield will be null:
k get endpointslice nginx-service-t786l -o yaml
addressType: IPv4
apiVersion: discovery.k8s.io/v1
endpoints: null
kind: EndpointSlice
...
Expected behavior
Kubectl.get(V1EndpointSlice.class) would not throw IllegalArgumentException.
Server (please complete the following information):
- OS: Bottlerocket
- Environment: container
- Cloud: AWS
Personally, I think this is an issue with how Go handles encoding empty arrays (https://medium.com/swlh/arrays-and-json-in-go-98540f2fa74e)
In practice, if you want to fix this, it needs to be in the upstream code generator, since this parsing is generated by that code generator.