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

kubernetes-client does not seem to be initializing the mapper correctly. #5306

Closed
ggallen opened this issue Jul 4, 2023 · 5 comments
Closed
Assignees

Comments

@ggallen
Copy link

ggallen commented Jul 4, 2023

Describe the bug

I have been working with @metacosm on some mapper issues. I have one now where it appears the kubernetes-client is not initializing the mapper correctly.

I have added as much information as I can and can help reproduce the problem if necessary. But the code is internal so that complicates things.

I am hoping @metacosm can fill in enough details if I have missed something.

Fabric8 Kubernetes Client version

6.7.2

Steps to reproduce

In my case, we have an enumeration like this:

@JsonSerialize(using = ToStringSerializer.class)
public enum ResourceStatus {
    NEW("New"),
    INITIALIZING("Initializing"),
    READY("Ready"),
    FAILED("Failed");

    private final String printable;

    private ResourceStatus(String printable) {
        this.printable = printable;
    }

    @Override
    public String toString() {
        return printable;
    }
}

And our mapper is configured like this:

@Singleton
public class DefaultObjectMapperCustomizer implements KubernetesClientObjectMapperCustomizer {
    public void customize(ObjectMapper mapper) {
        mapper.setConfig(mapper.getDeserializationConfig().with(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS));
        mapper.setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE);
        mapper.registerModule(JsonFormat.getCloudEventJacksonModule());
    }
}

This works fine most of the time. However, when I try to create a resource that needs validation by a webhook, that request is rejected (with no error on the webhook side) and this exception is raised:

io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://192.168.39.102:8443/apis/agogos.redhat.com/v1alpha1/namespaces/gallen/builds. Message: Internal error occurred: failed calling webhook "mutate.webhook.agogos.redhat.com": failed to call webhook: the server rejected our request for an unknown reason. Received status: Status(apiVersion=v1, code=500, details=StatusDetails(causes=[StatusCause(field=null, message=failed calling webhook "mutate.webhook.agogos.redhat.com": failed to call webhook: the server rejected our request for an unknown reason, reason=null, additionalProperties={})], group=null, kind=null, name=null, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=Internal error occurred: failed calling webhook "mutate.webhook.agogos.redhat.com": failed to call webhook: the server rejected our request for an unknown reason, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=InternalError, status=Failure, additionalProperties={}).
	at io.fabric8.kubernetes.client.KubernetesClientException.copyAsCause(KubernetesClientException.java:238)
	at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.waitForResult(OperationSupport.java:518)
	at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleResponse(OperationSupport.java:535)
	at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.handleCreate(OperationSupport.java:340)

This error occurs when I try to create an object using this YAML:

apiVersion: "agogos.redhat.com/v1alpha1"
kind: "Build"
metadata:
  generateName: "dummy-component-dep-"
  namespace: "gallen"
spec:
  component: "dummy-component-dep"
status:
  status: "New"

Note that Status is the enumeration I have included above, and its value is New, which should be changed to NEW when deserialized. I confirmed this is the problem by changing the value of the input file to NEW, and the creation of the object was successful.

Expected behavior

The mapper should handle enums correctly when ACCEPT_CASE_INSENSITIVE_ENUMS is set.

Runtime

minikube

Kubernetes API Server version

1.25.3@latest

Environment

Linux

Fabric8 Kubernetes Client Logs

N/A.

Additional context

N/A.

@shawkins
Copy link
Contributor

shawkins commented Jul 5, 2023

Is this related to #5293 ?

@ggallen
Copy link
Author

ggallen commented Jul 5, 2023

It very well could be. I'll leave that for @metacosm.

@metacosm
Copy link
Collaborator

metacosm commented Jul 5, 2023

I don't think it does. I think there's an issue with the ordering of how things are initialised or maybe lazy-loading is causing a problem. Running the webhook app without interacting with it showed that the mapper initialiser is not called, I would need to step debug to see what's going on but I don't have time to do that now.

@shawkins
Copy link
Contributor

shawkins commented Jul 5, 2023

@metacosm should this be a quarkus issue?

@metacosm
Copy link
Collaborator

metacosm commented Jul 5, 2023

I think we can close this issue: as explained elsewhere, the webhook is a REST endpoint which means that the request first goes through Quarkus' REST stack before even getting to the Kubernetes specific things. In this particular instance, the deserialisation issue occurred in the REST stack because the Quarkus' ObjectMapper isn't configured the same way than the Fabric8 Client's one. The fix is easy enough: make the customizer above also implement io.quarkus.jackson.ObjectMapperCustomizer which configures Quarkus' ObjectMapper in the same way as the Fabric8 Client's.

There might still be issues with ordering but let's cross that bridge when/if we get there.

@metacosm metacosm closed this as completed Jul 6, 2023
@metacosm metacosm self-assigned this Jul 6, 2023
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

3 participants