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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 Updating WriteYAML to not add empty line to start files #626
馃悰 Updating WriteYAML to not add empty line to start files #626
Conversation
56e4327
to
e1520fc
Compare
b3a1559
to
1fe1610
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hypothetically it means cat *.yaml
is no longer valid yaml doc. I think its a good change, just one hypothetical reason it could be useful
1fe1610
to
a5f3860
Compare
@howardjohn that's a good point, I was on the fence with the approach here but ended up deciding to go back to a delimiter to start the file, just without the extra prepended new line, hopefully that's a reasonable balance here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
thanks!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, robscott The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Recently we bumped `controller-tools` version to `v0.9.2` to support building controller with go1.19. This change sneakily impacted the `build-controller-release.sh` script, which caused our prow testing jobs to fail. To summarize the bug we can generate the `role.yaml` file using controller-gen `0.7.0` and `0.9.2` and inspect the differences: ```bash diff role-controller-gen0.9.2.yaml role-controller-gen0.7.0.yaml 0a1 > ``` We can observe that the new line that used it be generated at the top of each file is no longer there, due to the fix introduced in 0.8.0 more precisely in kubernetes-sigs/controller-tools#626 This change combined with the command `tail -n +8` in https://github.com/aws-controllers-k8s/code-generator/blob/v0.20.0/scripts/build-controller-release.sh#L237 causes the script to cut an extra line which happens to be declaration of rules section in a controller ClusterRole manifest. Hence the error observed in the prow logs: ```bash Error: INSTALLATION FAILED: YAML parse error on emrcontainers-chart/templates/cluster-role-controller.yaml: error converting YAML to JSON: yaml: line 8: did not find expected key ``` This patch fixes the `tail` command to properly cut the generated `role.yaml` file and avoid deleteng the `rules` section.
This patch fixes the `tail` command to properly cut the generated `role.yaml` file and avoid deleteng the `rules` section. Context: Recently we bumped `controller-tools` version to `v0.9.2` to support building controller with go1.19. This change sneakily impacted the `build-controller-release.sh` script, which caused our prow testing jobs to fail. To summarize the bug we can generate the `role.yaml` file using controller-gen `0.7.0` and `0.9.2` and inspect the differences: ```bash diff role-controller-gen0.9.2.yaml role-controller-gen0.7.0.yaml 0a1 > ``` We can observe that the new line that used it be generated at the top of each file is no longer there, due to the fix introduced in 0.8.0 more precisely in kubernetes-sigs/controller-tools#626 This change combined with the command `tail -n +8` in the [build controller release script](https://github.com/aws-controllers-k8s/code-generator/blob/v0.20.0/scripts/build-controller-release.sh#L237) causes the script to cut an extra line which happens to be declaration of rules section in a controller ClusterRole manifest. Hence the error observed in the prow logs: ```bash Error: INSTALLATION FAILED: YAML parse error on emrcontainers-chart/templates/cluster-role-controller.yaml: error converting YAML to JSON: yaml: line 8: did not find expected key ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Currently generated YAML files all have
\n---\n
prepended to them. Although that's not an issue when usingkubectl apply
with those files, it requires extra work when trying to do something simple like parse CRD yaml from a controller. Although not a significant issue, it's caused us (Gateway API + associated controller authors) to have to workaround it in several places. When parsing YAML files like this, the leading new line is parsed as an empty yaml struct, so we need to write code that can handle this empty/invalid object that starts all our generated YAML CRDs.It looks like this code originated from #208, and this particular part of the change does not seem like it was intentional.
Initially I wrote this to simply not add the delimiter to the start of the file, but as @howardjohn pointed out, that would make the concatenated files invalid YAML. This change does mean that concatenating YAML files that don't have a trailing new line will not work. Of course all files generated by this tool do have a trailing new line, and that seems like a reasonable expectation of other YAML files.