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 cannot create Lease resources in native mode #25829

Closed
jamesnetherton opened this issue May 27, 2022 · 1 comment · Fixed by #25875
Closed

Kubernetes Client cannot create Lease resources in native mode #25829

jamesnetherton opened this issue May 27, 2022 · 1 comment · Fixed by #25875
Labels
area/kubernetes kind/bug Something isn't working
Milestone

Comments

@jamesnetherton
Copy link
Contributor

Describe the bug

If you try to create a Lease with the Kubernetes Client in native mode, then it fails with the following error returned from the API server:

Exception while trying to create the lease resource: io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://172.30.0.1/apis/coordination.k8s.io/v1/namespaces/default/leases. Message: Lease in version "v1" cannot be handled as a Lease: json: cannot unmarshal number into Go struct field LeaseSpec.spec.acquireTime of type string. Received status: Status(apiVersion=v1, code=400, details=null, kind=Status, message=Lease in version "v1" cannot be handled as a Lease: json: cannot unmarshal number into Go struct field LeaseSpec.spec.acquireTime of type string, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=BadRequest, status=Failure, additionalProperties={}).

The problem seems to be that the serialization of the ZonedDateTime fields on LeaseSpec is incorrect. In JVM mode, the serialized Lease JSON looks like:

{
  "apiVersion": "coordination.k8s.io/v1",
  "kind": "Lease",
  "spec": {
    "acquireTime": "2022-05-27T08:46:39.358180Z",
    "holderIdentity": "test",
    "leaseDurationSeconds": 1,
    "leaseTransitions": 1,
    "renewTime": "2022-05-27T08:46:39.358200Z"
  }
}

In native mode it is (note the differences in date format):

{
  "apiVersion": "coordination.k8s.io/v1",
  "kind": "Lease",
  "spec": {
    "acquireTime": "2022-05-27T09:25:29.711055+01:00",
    "holderIdentity": "test",
    "leaseDurationSeconds": 1,
    "leaseTransitions": 1,
    "renewTime": "2022-05-27T09:25:29.711061+01:00",
    "additionalProperties": {}
  }
}

acquireTime and renewTime are configured like:

@JsonProperty("acquireTime")
@JsonFormat(timezone = "UTC", pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'")
private ZonedDateTime acquireTime;

For the @JsonFormat to take effect properly, I had to register LeaseSpec for reflective field access. Seems only method access is configured for it by default.

It's simple to reproduce the issue outside of k8s like:

@Inject
ObjectMapper objectMapper;

public void testLeaseSerialization() throws JsonProcessingException {
    LeaseSpec spec = new LeaseSpec(ZonedDateTime.now(), "test", 1, 1, ZonedDateTime.now());
    Lease build = new LeaseBuilder().withSpec(spec).build();
    System.out.println(objectMapper.writeValueAsString(build));
}

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

@jamesnetherton jamesnetherton added the kind/bug Something isn't working label May 27, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented May 27, 2022

/cc @geoand, @iocanel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubernetes kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant