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

V1Lease fails to serialize Date #828

Closed
kurtb opened this issue Jun 23, 2022 · 6 comments
Closed

V1Lease fails to serialize Date #828

kurtb opened this issue Jun 23, 2022 · 6 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@kurtb
Copy link

kurtb commented Jun 23, 2022

Describe the bug
Attempting to create/update a Lease using the CoordinationV1Api fails due to the Date serializer calling toISOString(). Kubernetes expects this string to use the microsecond format (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#leasespec-v1-coordination-k8s-io) - not the millisecond format that the Date object provides. (i.e. Date creates 2022-06-23T18:43:04.180Z but Kubernetes expects 2022-06-23T18:43:04.180000Z).

The response from the Kubernetes API is

 "message": "Lease in version \"v1\" cannot be handled as a Lease: v1.Lease.Spec: v1.LeaseSpec.HolderIdentity: AcquireTime: unmarshalerDecoder: parsing time \"2022-06-23T18:10:50.278Z\" as \"2006-01-02T15:04:05.000000Z07:00\": cannot parse \".278Z\" as \".000000\", error found in #10 byte of ...|0:50.278Z\",\"holderId|..., bigger context ...|},\"spec\":{\"acquireTime\":\"2022-06-23T18:10:50.278Z\",\"holderIdentity\":\"test\",\"leaseDurationSeconds\":60|...",

As a workaround you can create a custom Date that overrides toISOString to convert to the correct format (see example code).

** Client Version **
0.16.3

** Server Version **
1.22.3

Expected behavior
Lease is created/updated

** Example Code**

import * as k8s from '@kubernetes/client-node';

export async function brokenTest() {
    const kc = new k8s.KubeConfig();
    kc.loadFromDefault();

    const leaseApi = kc.makeApiClient(k8s.CoordinationV1Api);
    await leaseApi.createNamespacedLease(
        'default', 
        {
            apiVersion: 'coordination.k8s.io/v1',
            kind: 'Lease',
            metadata: {
                name: 'test',
                namespace: 'default',
            },
            spec: {
                acquireTime: new Date(),
                holderIdentity: 'test',
                leaseDurationSeconds: 60,
                leaseTransitions: 0,
            },
        });
}

class MicroDate extends Date {
    public toISOString(): string {
        const str = super.toISOString();
        return str.slice(0, -1) + '000Z'; 
    }
}

export async function workingTest() {
    const kc = new k8s.KubeConfig();
    kc.loadFromDefault();

    const leaseApi = kc.makeApiClient(k8s.CoordinationV1Api);
    await leaseApi.createNamespacedLease(
        'default', 
        {
            apiVersion: 'coordination.k8s.io/v1',
            kind: 'Lease',
            metadata: {
                name: 'test',
                namespace: 'default',
            },
            spec: {
                acquireTime: new MicroDate(),
                holderIdentity: 'test',
                leaseDurationSeconds: 60,
                leaseTransitions: 0,
            },
        });
}

Environment (please complete the following information):

  • OS: Linux
  • NodeJS Version 16.15.0
@brendandburns
Copy link
Contributor

brendandburns commented Jun 23, 2022

This is related to this in the Java client code:

https://github.com/kubernetes-client/java/blob/a0e456ec0b5a455448e50f5e907bcbeef2f7bb7e/kubernetes/src/main/java/io/kubernetes/client/openapi/JSON.java#L251

Also discussion here:
kubernetes-client/java#1477

This probably requires changes us to insert a custom type for the v1Date objects instead of using javascript Date.

@uesyn
Copy link
Contributor

uesyn commented Jun 25, 2022

@brendandburns
I created the PR to represent micro seconds fields baesd on @kurtb code in the comment.
Please review the PR when you have a time!

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 23, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 23, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

@k8s-ci-robot k8s-ci-robot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants