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

istio Timestamp type should be mapped to String type in java #4312

Closed
yimoucao opened this issue Jul 29, 2022 · 5 comments · Fixed by #4474
Closed

istio Timestamp type should be mapped to String type in java #4312

yimoucao opened this issue Jul 29, 2022 · 5 comments · Fixed by #4474
Assignees
Labels
component/extensions Deals with the extensions
Milestone

Comments

@yimoucao
Copy link
Contributor

Describe the bug

in istio generators, there's such code block that converts istio Timestamp to Long

manualTypeMap := map[reflect.Type]string{
		reflect.TypeOf(types.BoolValue{}):   "java.lang.Boolean",
		reflect.TypeOf(types.DoubleValue{}): "java.lang.Double",
		reflect.TypeOf(types.Duration{}):    "java.lang.String",
		reflect.TypeOf(types.Timestamp{}):   "java.lang.Long",
		reflect.TypeOf(types.Int32Value{}):  "java.lang.Integer",
		reflect.TypeOf(types.UInt32Value{}): "java.lang.Integer",
	}

according to istio doc, it will be marshaled to string in RFC-3339 string
and one example is lastTransitionTime on istio offical site

strings can't be deserialized into java Long type

Fabric8 Kubernetes Client version

6.0.0

Steps to reproduce

copy yaml

  - lastProbeTime: null
    lastTransitionTime: "2019-12-26T22:06:34Z"
    message: "61/122 complete"
    reason: "stillPropagating"
    status: "False"
    type: Reconciled

and do deserialization with type IstioCondition

Expected behavior

successful deserialization

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

macOS

Fabric8 Kubernetes Client Logs

enterprise-customized k8s

Additional context

No response

@manusa
Copy link
Member

manusa commented Aug 9, 2022

Hi @yimoucao,
Do you want to contribute a fix for this?

@manusa manusa added the component/extensions Deals with the extensions label Aug 9, 2022
@yimoucao
Copy link
Contributor Author

yimoucao commented Aug 10, 2022

Hi @yimoucao, Do you want to contribute a fix for this?

@manusa yes I'd love to. so you confirmed it is indeed a bug? I am no expert in istio and don't know what was considered to map it to Long by original author

@manusa
Copy link
Member

manusa commented Aug 30, 2022

If the provided code reproduces an issue, i.e. the provided snippet (or any other resource retrieved from the cluster) doesn't get deserialized properly, this should be treated as a bug and fixed.

The right approach would be to deserialize the field as a Java Timestamp-compatible type via a Jackson converter/deserializer module, instead of a regular Java String type (which is not very useful for users, especially if they intend to perform operations on the value of the field).

However, most of the timestamps we deal with in the client models are currently being deserialized as Strings (See ObjectMeta#creationTimestamp)

Since this will involve a breaking change, maybe we can already switch this to use a Java Timestamp-compatible (java.time) type + the Jackson JavaTimeModule.

@yimoucao
Copy link
Contributor Author

yimoucao commented Oct 3, 2022

@manusa I can fix it using Strings fairly quick. If we use a Java Timestamp type, will it require serializer/deserializer change? I'm assuming something has to be done like registering JavaTimeModule and configuring feature flags. To accommodate RFC-3339, extra logic I think has to be written. In sum to fix with a right approach, it's worthwhile to open a new issue and fix all the timestamps not just this Istio one

@manusa
Copy link
Member

manusa commented Oct 4, 2022

Despite not being the most Java friendly way (OffsetDateTime, or other Java Time API types would be much better suited), we're currently mapping Tiemestamps to Strings:

https://github.com/kubernetes/apimachinery/blob/478dd6ed1ec9b4cc3459dcd4f1d772013ac0103c/pkg/apis/meta/v1/types.go#L179-L188

So for consistency reasons, we should stick with mapping Timestamps to Strings.

@manusa manusa added this to the 6.2.0 milestone Oct 17, 2022
manusa pushed a commit that referenced this issue Oct 17, 2022
)

* fix timestamp can't be deserialized for IstioCondition

* add generated Istio files

* update CHANGELOG

Co-authored-by: yimcao <yimcao@ebay.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/extensions Deals with the extensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants