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

Expected a single document in the stream #3648

Closed
ParriePierre opened this issue Dec 13, 2021 · 3 comments · Fixed by #3711
Closed

Expected a single document in the stream #3648

ParriePierre opened this issue Dec 13, 2021 · 3 comments · Fixed by #3711
Assignees
Labels
Milestone

Comments

@ParriePierre
Copy link

Describe the bug

Hello,

Kubernetes-client cannot read documents that contains one ressource and end with "---", snakeyaml throws exception "expected a single document in the stream".
It used to work with kubernetes-client 4.13.3.

Using Kubernetes-client:4.13.0, this used to work.

Fabric8 Kubernetes Client version

5.10.1@latest

Steps to reproduce

Using example LoadMultipleDocumentsFromFileExample, modify the file multiple-document-template.yml to keep only one resource and ending the file with "---" :

apiVersion: v1
kind: Service
metadata:
  name: redis-master
  labels:
    app: redis
    tier: backend
    role: master
spec:
  ports:
  - port: 6379
    targetPort: 6379
  selector:
    app: redis
    tier: backend
    role: master
---

snakeyaml throws exception

expected a single document in the stream
 in 'reader', line 17, column 1:
    apiVersion: v1
    ^
but found another document
 in 'reader', line 33, column 1:
    ---
    ^

	at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:114)
	at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:139)
	at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:524)
	at org.yaml.snakeyaml.Yaml.load(Yaml.java:452)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshalYaml(Serialization.java:369)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:191)
	at io.fabric8.kubernetes.client.utils.Serialization.unmarshal(Serialization.java:156)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.getItems(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:81)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.getOperations(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:92)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.accept(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:215)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.accept(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:53)
	at com.dassault_systemes.infra.cloud.kubernetes.driver.action.LoadMultipleDocumentsFromFileExampleTest.test(LoadMultipleDocumentsFromFileExampleTest.java:49)

Expected behavior

Kubernetes-client should be able to serialize YAML files that have only one resource and ends with "---".

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

Linux

Fabric8 Kubernetes Client Logs

No response

Additional context

Issue is not related to K8S API.

@manusa manusa added the bug label Dec 21, 2021
@rohanKanojia rohanKanojia self-assigned this Jan 4, 2022
@rohanKanojia
Copy link
Member

I can reproduce this issue. While processing YAML document, I can see YAML document is parsed correctly; however, since it's just one document this condition is not satisfied:

static boolean containsMultipleDocuments(String specFile) {
final long validDocumentCount = splitSpecFile(specFile).stream().filter(Serialization::validate)
.count();
return validDocumentCount > 1;
}

This behavior seems to be correct. Since it's only a single document control goes to Single document unmarshal method. But at this point there is still --- present in YAML document which causes the error.

if (containsMultipleDocuments(specFile)) {
return (T) getKubernetesResourceList(parameters, specFile);
}
return unmarshal(new ByteArrayInputStream(specFile.getBytes()), JSON_MAPPER, parameters);

Removing leading/trailing Document delimiters --- should fix this issue.

rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jan 4, 2022
…ML with single document in presence of document delimiter(`---`)

Serialization.unmarshal doesn't handle the case when YAML contains only
single document but yet contains a leading or trailing document
delimiter(`---`).

Trim YAML document delimiters in case of single documents

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@manusa manusa added this to the 5.12.0 milestone Jan 7, 2022
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jan 7, 2022
…ML with single document in presence of document delimiter(`---`)

Serialization.unmarshal doesn't handle the case when YAML contains only
single document but yet contains a leading or trailing document
delimiter(`---`).

Trim YAML document delimiters in case of single documents

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jan 7, 2022
…ML with single document in presence of document delimiter(`---`)

Serialization.unmarshal doesn't handle the case when YAML contains only
single document but yet contains a leading or trailing document
delimiter(`---`).

Trim YAML document delimiters in case of single documents

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jan 7, 2022
…ML with single document in presence of document delimiter(`---`)

Serialization.unmarshal doesn't handle the case when YAML contains only
single document but yet contains a leading or trailing document
delimiter(`---`).

Trim YAML document delimiters in case of single documents

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Jan 7, 2022
…ML with single document in presence of document delimiter(`---`)

Serialization.unmarshal doesn't handle the case when YAML contains only
single document but yet contains a leading or trailing document
delimiter(`---`).

Trim YAML document delimiters in case of single documents

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@ParriePierre
Copy link
Author

Thank you very much @rohanKanojia !

@rohanKanojia
Copy link
Member

@ParriePierre : Np, Would appreciate if you could also review my PR :-)

manusa pushed a commit that referenced this issue Jan 11, 2022
…ingle document in presence of document delimiter(`---`)

Serialization.unmarshal doesn't handle the case when YAML contains only
single document but yet contains a leading or trailing document
delimiter(`---`).

Trim YAML document delimiters in case of single documents

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment