mogensen / kubernetes-split-yaml

Split the 'giant yaml file' into one file pr kubernetes resource
99 stars 20 forks source link

Panic when YAML file has a comment #9

Closed mbrancato closed 2 years ago

mbrancato commented 3 years ago

Hi, I ran into a panic when a YAML file has a top-level comment.

 % ./kubernetes-split-yaml test.yaml 
WARN[0000] Ignoring yaml file with kind missing         
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x11c30da]

Here is a minimal example that produces this panic:

# Some comment
---
apiVersion: v1
kind: Namespace
metadata:
  name: ns1
---
apiVersion: v1
kind: Namespace
metadata:
  name: ns2
elzapp commented 3 years ago

Hi, i tested your example on the current version. It works as expected on my system

$ ./kubernetes-split-yaml test.yaml
WARN[0000] Ignoring yaml file with kind missing
INFO[0000] Creating file: generated/ns1-namespace.yaml
INFO[0000] Creating file: generated/ns2-namespace.yaml

$ cat test.yaml |./kubernetes-split-yaml -
WARN[0000] Ignoring yaml file with kind missing
INFO[0000] Creating file: generated/ns1-namespace.yaml
INFO[0000] Creating file: generated/ns2-namespace.yaml

I say expected, even with the warning, since the first document is an empty document with only comments.

I performed the test on b448d8a, built and tested on Ubuntu 18.04.4 LTS under WSL1 (Windows 10) go version go1.17 linux/amd64

Can you provide more information to be able to reproduce the issue?

elzapp commented 3 years ago

I reproduced it in v0.3.0, it seems to have been fixed in 3856173

mogensen commented 2 years ago

Fixed :D