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

Yaml containing aliases rejected due to FasterXML bug #2510

Closed
rittneje opened this issue Sep 27, 2020 · 3 comments · Fixed by #2646
Closed

Yaml containing aliases rejected due to FasterXML bug #2510

rittneje opened this issue Sep 27, 2020 · 3 comments · Fixed by #2646
Assignees
Labels

Comments

@rittneje
Copy link

There is a long-standing bug in the way that FasterXML handles yaml containing aliases. FasterXML/jackson-dataformats-text#98

As a consequence, anyone using perfectly valid yaml containing aliases (which may have been automatically generated via SnakeYaml) will get a mysterious error message like this:

15:26:16  hudson.remoting.ProxyException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('id001')
15:26:16   at [Source: (BufferedInputStream); line: 49, column: 17] (through reference chain: io.fabric8.kubernetes.api.model.Pod["spec"]->io.fabric8.kubernetes.api.model.PodSpec["containers"]->java.util.ArrayList[1]->io.fabric8.kubernetes.api.model.Container["resources"]->io.fabric8.kubernetes.api.model.ResourceRequirements["requests"])
15:26:16  	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
15:26:16  	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1455)
15:26:16  	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1081)
15:26:16  	at com.fasterxml.jackson.databind.deser.ValueInstantiator._createFromStringFallbacks(ValueInstantiator.java:371)
15:26:16  	at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromString(ValueInstantiator.java:258)
15:26:16  	at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:357)
15:26:16  	at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:29)
15:26:16  	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:293)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:156)
15:26:16  	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:293)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:156)
15:26:16  	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:291)
15:26:16  	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:250)
15:26:16  	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
15:26:16  	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:293)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:156)
15:26:16  	at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:293)
15:26:16  	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:156)
15:26:16  	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4524)
15:26:16  	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3511)
15:26:16  	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:246)

Is the use of FasterXML strictly required? Would it be possible to simply use SnakeYaml directly for parsing, which seems to handle aliases properly?

@manusa
Copy link
Member

manusa commented Sep 28, 2020

I've personally bumped into a few issues when serializing and deserializing content from the client. It seems that YAML produced/serialzied by Jackson can't be deserialized again in some circumstances (another example is deserializing YAMLs double curly brackets >> Helm chart template variables).

This is something we'll need to look into.

@manusa manusa added the bug label Sep 28, 2020
@manusa
Copy link
Member

manusa commented Oct 5, 2020

Hi @rittneje

Could you provide a sample of the YAML content that's failing for you so we can create specific tests for this issue before we proceed with a fix?

@rittneje
Copy link
Author

rittneje commented Oct 5, 2020

apiVersion: v1
kind: Pod
spec:
  nodeSelector:
    workload: build
  tolerations:
  - key: nodeType
    operator: Equal
    value: build
    effect: NoSchedule
  securityContext:
    runAsUser: 1000
    runAsGroup: 1000
  containers:
  - name: ubuntu
    image: ubuntu:bionic
    imagePullPolicy: Always
    command:
    - cat
    tty: true
    resources:
      requests: &id001
        cpu: 100m
  - name: python3
    image: python:3.7
    imagePullPolicy: Always
    command:
    - cat
    tty: true
    resources:
      requests: *id001

@rohanKanojia rohanKanojia self-assigned this Dec 1, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Dec 2, 2020
… bug

+ Fallback to SnakeYAML while deserializing Kubernetes YAML manifests
+ Refactored SerializationUtils#dumpAsYaml(...) to use SnakeYAML instead
  of Jackson
+ Moved `SerializationUtils` to `io.fabric8.kubernetes.client.utils`
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Dec 2, 2020
… bug

+ Fallback to SnakeYAML while deserializing Kubernetes YAML manifests
+ Refactored SerializationUtils#dumpAsYaml(...) to use SnakeYAML instead
  of Jackson
+ Moved `SerializationUtils` to `io.fabric8.kubernetes.client.utils`
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Dec 11, 2020
… bug

Modify the way we deserialize Yaml objects. Load them into raw HashMap
using SnakeYAML and then use Jackson to convert them to JSON and finally
the required object
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Dec 11, 2020
… bug

Modify the way we deserialize Yaml objects. Load them into raw HashMap
using SnakeYAML and then use Jackson to convert them to JSON and finally
the required object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants