Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubectl.get(V1EndpointSlice.class) failed due to endpoints: null #3226

Open
fanyang01 opened this issue Mar 19, 2024 · 1 comment
Open

Kubectl.get(V1EndpointSlice.class) failed due to endpoints: null #3226

fanyang01 opened this issue Mar 19, 2024 · 1 comment

Comments

@fanyang01
Copy link

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:

// ensure the json data is an array
if (!jsonObj.get("endpoints").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `endpoints` to be an array in the JSON string but got `%s`", jsonObj.get("endpoints").toString()));
}

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 endpoints field 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
@brendandburns
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants