Skip to content

Add wrapper for serde_yaml - #448

Closed
siegfriedweber wants to merge 1 commit into
mainfrom
yaml_utils
Closed

Add wrapper for serde_yaml#448
siegfriedweber wants to merge 1 commit into
mainfrom
yaml_utils

Conversation

@siegfriedweber

@siegfriedweber siegfriedweber commented Aug 1, 2022

Copy link
Copy Markdown
Member

Description

  • Add wrapper for serde_yaml which adheres to the YAML specification. Operators should use the yaml module instead of serde_yaml.
  • Update serde_yaml to version 0.9.

This pull request solves the problem that serde_yaml in version 0.9 does not emit leading dashes anymore (see dtolnay/serde-yaml#266) which does not conform to the YAML specification (see https://yaml.org/spec/1.2.2/#22-structures). This becomes especially a problem when concatenating YAMLs which is done in many operators as follows:

Command::Crd => println!(
    "{}{}{}",
    serde_yaml::to_string(&SupersetCluster::crd())?,
    serde_yaml::to_string(&SupersetDB::crd())?,
    serde_yaml::to_string(&DruidConnection::crd())?
),

However, I did not move the concatenation to operator-rs, so it must still be done in the operator:

Command::Crd => {
    let yamls = vec![
        yaml::to_string(&SupersetCluster::crd())?,
        yaml::to_string(&SupersetDB::crd())?,
        yaml::to_string(&DruidConnection::crd())?,
    ];
    println!("{}", yamls.concat());
}

It can be discussed if this step should also be moved into operator-rs.

According to the usage in the operators (https://github.com/search?l=&q=org%3Astackabletech+%22serde_yaml%3A%3A%22+language%3ARust&type=code), it should be sufficient to forward only Error, from_str, and to_string from serde_yaml.

The implementation of yaml::to_string could be improved to use less space but with increased code complexity.

Review Checklist

  • Code contains useful comments
  • (Integration-)Test cases added (or not applicable)
  • Documentation added (or not applicable)
  • Changelog updated (or not applicable)
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Once the review is done, comment bors r+ (or bors merge) to merge. Further information

@siegfriedweber
siegfriedweber requested a review from a team August 1, 2022 12:08
@siegfriedweber siegfriedweber self-assigned this Aug 1, 2022
@nightkr

nightkr commented Aug 1, 2022

Copy link
Copy Markdown
Contributor

Oh, I would have called it serialize_crds or something, since that's the actual use-case we're trying to solve here.

Otherwise a more descriptive name might be documents_to_string or something? to_string doesn't really make it clear to me what the difference is compared to serde_yaml::to_string.

@soenkeliebau soenkeliebau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, ran tests, looks good to me overall.

Not sure I agree with the upstreams change, but it is what it is :)

Comment thread src/yaml.rs
@@ -0,0 +1,65 @@
//! Wrapper around serde_yaml which adheres to the YAML specification

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think strictly speaking the --- are only mandatory if the file starts with directives, to delimit these from the actual content of the file.
So arguably serde_yaml adheres to the spec, even though I have to say that I do not agree with the upstream change.
Besides that, it might be worthwhile just adding one sentence about what exactly the difference is between this and serde_yaml to make it easier to understand.

@siegfriedweber siegfriedweber Aug 2, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In YAML 1.0 and 1.1, a YAML stream can start with an "implicit document" (without dashes) or an "explicit document" (with dashes), see https://yaml.org/spec/1.0/index.html#id2561559 and https://yaml.org/spec/1.1/current.html#id898785.

It is the same in YAML 1.2 but "implicit documents" are called "bare documents", see https://yaml.org/spec/1.2.2/#913-bare-documents.

So serde_yaml is compliant with the YAML specification. I will change my pull request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth opening an issue against yamllint for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a closed issue with this topic: adrienverge/yamllint#302

@siegfriedweber

Copy link
Copy Markdown
Member Author

Pull request closed in favor of #450

@siegfriedweber
siegfriedweber deleted the yaml_utils branch August 2, 2022 11:07
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

Successfully merging this pull request may close these issues.

3 participants