Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Replace Shopify/yaml with gopkg.in/yaml.v3 #227

Merged
merged 2 commits into from
Oct 18, 2019
Merged

Conversation

genevieveluyt
Copy link
Contributor

@genevieveluyt genevieveluyt commented Sep 23, 2019

Description

Now that goyaml v3 is out and supports comments, we can use that instead of the Shopify fork of goyaml v2.

There is one test that fails because of go-yaml/yaml#508. Once that is fixed, we need to update the goyaml v3 dependency and then hopefully all the tests will pass!

Fixes #223

Type of change
  • Bug fix 🐛
  • New feature ✨
  • This change requires a documentation update 📖
  • Breaking changes ⚠️
  • Code improvement
How Has This Been Tested?
  • Run the test script test.sh
Checklist:
  • I have 🎩 my changes (A 🎩 specifically includes pulling down changes, setting them up, and manually testing the changed features and potential side effects to make sure nothing is broken)
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The test coverage did not decrease

&yaml.Node{Kind: yaml.MappingNode, Tag: mapTag, Content: []*yaml.Node{
{Kind: yaml.ScalarNode, Tag: strTag, Value: "K", HeadComment: "Hi"},
{Kind: yaml.ScalarNode, Tag: strTag, Value: "V2", LineComment: "Bye"},
}},

Choose a reason for hiding this comment

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

nit: because this is kind of a big PR, I would recommend trying to keep as many things constant as possible to make it easy for reviewers. In this test case both the structure and the content of the nodes change, which makes things a little more complicated - especially because I'm new to the codebase. If we want to test both comment types and we didn't support them before it might make sense to split out multiple smaller commits that reviewers can consider individually like: "move to yaml.v3 nodes", "add HeadComment to test cases"? Just a suggestion for future PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense! We did support them before, they just looked different. In the old format, aka what the fork uses, it would have looked like this:

yaml.MapSlice{
	{Comment: "Hi"},
	{Key: "K", Value: "V2", Comment: "Bye"},
},

but I agree that I should have done a direct conversion and kept the test contents the same. I'll keep it in mind for next time!

- /bin/sh
- -c
- ls /etc/config/
command: ["/bin/sh", "-c", "ls /etc/config/"]

Choose a reason for hiding this comment

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

These changes are kind of surprising, since the library is supposed to preserve the structure of the YAML file? Is this caused by the move to yaml.v3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this output matches the formatting of the input file https://github.com/Shopify/kubeaudit/blob/master/fixtures/preserve_comments_v2.yml#L35
Our fork used default formatting for all data types so all arrays got marshaled into the multi-line dashed formatting. It wasn't great but it wasn't technically incorrect as far as yaml parsers could tell.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the one liner way more :)

Copy link

@actgardner actgardner left a comment

Choose a reason for hiding this comment

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

The AST tests look good. A few comments about trying to minimize the scope of changes to keep the review as small and focused as possible. Once the upstream library is fixed I'll give it one more pass and 👍

@genevieveluyt genevieveluyt changed the title WIP: Replace Shopify/yaml with gopkg.in/yaml.v3 Replace Shopify/yaml with gopkg.in/yaml.v3 Oct 10, 2019
Copy link
Contributor

@klautcomputing klautcomputing left a comment

Choose a reason for hiding this comment

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

Overall I think we can merge this 👍

@@ -189,7 +189,8 @@ spec:
spec:
# Trust me the following line is longer than 80 characters
containers:
- image: gcr.io/docker-images-directory/apps/production/fake-image-app:<%= current_sha %>
- image: gcr.io/docker-images-directory/apps/production/fake-image-app:<%= current_sha
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to not do the 80 (or whatever it is) character limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doesn't look like it's supported right now but I could open a feature request

@@ -21,5 +21,5 @@ spec:
podSelector: # chooses pods with type=monitoring
matchLabels:
type: monitoring
- ports: # This is comment 1
- port: 3452 #This is comment 2
- ports:
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened to this and the other comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These caused tests to fail because of the bug in goyaml but since they're covered by the PreserveComments test, I took them out to make sure nothing else was causing the tests to fail. I can put them back but I think the PreserveComments test is thorough enough. What do you think?

- /bin/sh
- -c
- ls /etc/config/
command: ["/bin/sh", "-c", "ls /etc/config/"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the one liner way more :)

@genevieveluyt genevieveluyt merged commit 8006e92 into master Oct 18, 2019
@genevieveluyt genevieveluyt deleted the migrate-go-yaml branch May 3, 2022 19:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace our fork of go-yaml with go-yaml.v3
3 participants