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

Multiline strings generate invalid output when whitespace prefixed data #81

Open
warmfusion opened this issue Mar 2, 2023 · 6 comments

Comments

@warmfusion
Copy link

warmfusion commented Mar 2, 2023

Multiline yaml entries with whitespace prefixes generate invalid indentation indicators on dump.

Metadata

  • kubesplit version: 0.3.2
  • Python version: 3.11.2
  • Operating System: Macos / Debian Bullseye

Description

When splitting configuration files that present with existing multiline data blocks with indentation indicators, the generated split versions have the wrong indicators set.

What I Did

Given two configmaps in a yaml file named input.yaml

---
apiVersion: v1
data:
  no_indent_hint: |
    some content here
  no_indent_hint_with_whitespace: |

    some content here
kind: ConfigMap
metadata:
  name: example-no-indicators

---
apiVersion: v1
data:
  indent_2: |2
    some content here

  indent_2_with_whitespace: |2

    some content here
kind: ConfigMap
metadata:
  name: example-with-indicators

When processed through kubesplit ❯ kubesplit -i input.yaml -o example, the generated files for the indicators'

(Shown 'merged' for convenience)

---
apiVersion: v1
data:
  no_indent_hint: |
    some content here
  no_indent_hint_with_whitespace: |4

    some content here
kind: ConfigMap
metadata:
  name: example-no-indicators
---
apiVersion: v1
data:
  indent_2: |
    some content here

  indent_2_with_whitespace: |4

    some content here
kind: ConfigMap
metadata:
  name: example-with-indicators

Observe how the entries with whitespace prefixed in their data blocks are now indicated with |4, even if previously a value of None or 2 was given; this is incorrect, and can be observed with yamllint test;

❯ yamllint example/*
example/11--configmap--example-no-indicators.yml
  8:5       error    syntax error: expected <block end>, but found '<scalar>' (syntax)

example/11--configmap--example-with-indicators.yml
  9:5       error    syntax error: expected <block end>, but found '<scalar>' (syntax)

Additional

When using --no-dash-inwards argument, the entries are valid, which I belive hints that the problem lies in the yamkix function here;

https://github.com/looztra/yamkix/blob/main/src/yamkix/yamkix.py#L62-L69

Specifically, the 'transform' operationl named strip_leading_double_space

@warmfusion
Copy link
Author

Interestingly, using ruamel.yaml==0.17.14 results in the |4 stuff going away, but also the required |2 values we have in other places also breaks;

eg;

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-example-with-old-ruamel
data:
  example.conf: |2

    configuration text here 

becomes

...
  example.conf: |

    configuration text here

which is wrong too aparently.

@looztra
Copy link
Owner

looztra commented Jun 24, 2023

sorry for the horrible latency.

I had to publish a new version of yamkix that now requires ruamel.yaml>=0.17.27
so I will also have a look at this

(thanks for the detailed report)

@looztra
Copy link
Owner

looztra commented Jun 24, 2023

(to be honest, I'll have to dig into the subject of whitespace prefixed data first, I've never heard of this feature before 😺 )

@looztra
Copy link
Owner

looztra commented Jun 24, 2023

checked with the updated yamkix version (and ruamel.yaml==0.17.32)

Got

---
apiVersion: v1
data:
  no_indent_hint: |
    some content here
  no_indent_hint_with_whitespace: |2

    some content here
kind: ConfigMap
metadata:
  name: example-no-indicators
---
apiVersion: v1
data:
  indent_2: |
    some content here

  indent_2_with_whitespace: |2

    some content here
kind: ConfigMap
metadata:
  name: example-with-indicators

so indicators have the good value, but always output if one of the document has them.

@looztra
Copy link
Owner

looztra commented Jun 24, 2023

to be sure to understand the target:

  • if there is a indicator, we want to keep it in the output?
  • if there is a whitespace but no indicator, we don't want it?

or are we OK if the indicators are explicitely set in the output as long as they are like the ones in the inputs? (that seems fine with latest ruamel.yaml, no?)

ping @warmfusion

@looztra
Copy link
Owner

looztra commented Jun 25, 2023

A new version of kubesplit (0.3.3) has been published, nothing changed in the code, only the requirements that will make you use an updated ruamel.yaml version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants