-
Notifications
You must be signed in to change notification settings - Fork 136
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
[lang] support emitting comments in resulting YAML #63
Comments
that would be helpful in certain cases for sure.
that would work from a syntax perspective. minor concern i would have is if someone accidentally throws in annotations like we currently use plain YAML library to implement serialization and it doesnt support emitting YAML comments; however, i was also playing around with |
That's entirely valid, especially since that's an easy typo to make. For me it'd be fine to emit a highly visible notice (or fatal parse error?) to I understand this is due to the ambiguity introduced from the [albeit positive] fact that YAML comments are used for |
currently
we currently dont have more advanced proposal process beyond dedicated github issues+comments (and slack for live discussion). imho it works ok for now. |
Using |
i would imagine it would be not be used that often, hence shorthand would not be necessary. how frequently do you think you'll be adding comments to resulting YAML? |
Maybe not that often. My latest workflow is primarily focused on the So I cannot argue for it strongly since I may not use it much now, myself. Being a new user, I thought I might need it, but it turns out that it'll be of fairly low importance (and wouldn't use it at all if it had that verbose of syntax, actually). |
👍 let keep the issue open for now, and let's see if anyone else has a use case for this feature. |
Hi, |
@smg8fe for your use case you can use something like this for now, |
Guys, yaml is yaml. IMO it would be best if ytt default behaviour does not fail when there is a comment in the input yaml file: #@ def labels():
#! This is a ytt comment
## This is a comment in the yaml output
# And this is just a comment in this file
|
@PyMeH our thinking was to help catch mistakes by authors if they forget to add |
This makes me wonder @cppforlife, is there the ability to flag the file (maybe in the header at the very top) to enable this functionality? That or maybe some code-based configuration so that we can keep it "git ops". Since the code is already That way we can keep it all in-code and clearly defined as a preference somewhere. |
Yes. In my head ytt extends yaml. Think of OOP - ytt should follow the yaml contract. Talking about polymorphism- ytt format should be processible by every yaml tool.
An analogy - json and json-ld formats.
Regarding —ignore-unknown-comments - it should either be reversed, e.g —fail-on-yaml-comments or (IMO the better approach) should go away.
My 2c
… On 27 Nov 2019, at 18:32, Dmitriy Kalinin ***@***.***> wrote:
@PyMeH our thinking was to help catch mistakes by authors if they forget to add @ after '#' (since IDEs for example dont help to add it). there is currently --ignore-unknown-comments to allow anything to pass through. do you think opting in for a flag is unnecessary?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Please don't suggest hackish workarounds like this. I, too, am trying to do something more robust that Jinja templating to get values from external variables into a YAML file, in this case also a In this use case, I am trying to make it easier for someone with little programming experience to preconfigure a Raspberry Pi using a The concept of templating is hard enough, so new users insert hard-coded passwords into a YAML file, or worse, just use the default password that came in the cloned repo. It is already going to be a hard sell for me to get them to use I've been trying to find a supported way to include the string using existing
I can only make Not providing a means of working around this issue (besides concatenation at the shell) does not seem to be user-friendly or robust. Can you just add an option to select what the "expected document start" string should be? I would be happy to just add Thanks! |
This would be super useful! We're starting to explore using This exact use case is having a bunch of shorter yaml docs in source that can be composed together to create a valid values.yaml file for a specific environment for documentation purposes. |
The use case of using ytt for something like a cloud-config is especially challenging here. What is the appropriate way to engage here to get some focus on this use case from the maintainers here? I think there are valid use cases that would be very helpful for the project to consider here. |
I found this issue looking for a way to tag my generated files with headers like # generated by ytt, do not modify
# author:
... |
I don't know if this belongs in here or could be a separate issue, but we're finding ourselves doing more and more stuff like this:
Which is cutting down on readability pretty significantly, it would be really nice to be able to pull this out into a yaml fragment like we do with non-ytt overlay config files:
|
If I understand this correctly, there is currently no way to force ytt to emit yaml E.g. App Accelerator templates can invoke ytt on input yaml files, to generate modified output yaml files for a new project. The value of those output files is significantly impacted by a lack of comments. |
This would be a huge benefit for us to have this option. We have a few use cases currently impacted by this. The main one is using ytt in app accelerator and we need comments which isnt possible. The other is a bit more advanced but is using ytt to generate ytt templates. This also may be relevant down the road in a system like app accelerator but currently i use a bunch of sed and awk stuff to generate ytt templates that could much more easily and cleanly be done via ytt generating them. |
We try to bootstrap new repositories with templates that follow common patterns as "getting started" -- we do this mostly with sed scripts now, but it comes up extremely often it seems silly to use sed to create ytt templates when ytt would excel in that use case. |
It stinks that we're still stuck at not being able to simply emit comments in @pivotaljohn what do you think: Could we at the very least have some kind of esoteric syntax like @cppforlife's suggestion above #63 (comment) just to make it possible? e.g. ... and then maybe discuss having a more intuitive shorthand syntax like |
This may be sacrilege, but: I’m actually dropping Ironically, it doesn’t include comments in resulting YAML, but it’s generally not necessary at all. 😊 |
Hey @patricknelson. Sorry for the delay. Thanks for letting us know where you're at. It's unfortunate that we haven't been able to make more progress on this issue. We're constantly prioritizing where we invest and haven't had the bandwidth to include this (albeit useful) suggestion. We're really big on folks using the right tool for the job. 👍🏻 Kustomize can be great for straight-forward patching and is well integrated into the Kubernetes tooling.
Keeping this open as we haven't decided not to implement this feature. In the meantime, we would absolutely welcome a contribution for implementing the |
Another concrete example of this arose, recently: where a template evaluated at build time... A Carvel user wanted to template their PackageInstall CR so that they could include it in a collection of packages to be installed as a larger system: Build Step: during "build time", populate some fields with values determined by the published of the package:
#@ load("@ytt:data", "data")
#@ #@ load("@ytt:data", "data")
#@ #@ load("@ytt:yaml", "yaml")
#@ #@ load("_profiles.star", "profiles")
#@ #@ if profiles.is_any_enabled([profiles.full]):
#@ #@ if profiles.is_pkg_enabled("telemetry.platform.com"):
---
apiVersion: packaging.carvel.dev/v1alpha1
kind: PackageInstall
metadata:
name: #@ data.values.name
namespace: platform-install
spec:
serviceAccountName: #@ data.values.serviceAccount
packageRef:
refName: #@ data.values.name + "." + data.values.domain
versionSelection:
constraints: #@ data.values.version
prereleases: {}
---
apiVersion: v1
kind: Secret
metadata:
name: telemetry-values
namespace: platform-install
stringData:
values.yml: #@ #@ yaml.encode(data.values.telemetry)
#@ #@ end
#@ #@ end ... such that the lines that start with #@ load("@ytt:data", "data")
#@ load("@ytt:yaml", "yaml")
#@ load("_profiles.star", "profiles")
#@ if profiles.is_any_enabled([profiles.full]):
#@ if profiles.is_pkg_enabled("telemetry.platform.com"):
---
apiVersion: packaging.carvel.dev/v1alpha1
kind: PackageInstall
metadata:
name: telemetry
namespace: platform-install
spec:
serviceAccountName: telemetry-acct
packageRef:
refName: telemetry.platform.com
versionSelection:
constraints: 1.1.0
prereleases: {}
---
apiVersion: v1
kind: Secret
metadata:
name: telemetry-values
namespace: platform-install
stringData:
values.yml: #@ yaml.encode(data.values.telemetry)
#@ end
#@ end Install Step: while the system is being installed, the system operator provides installation values to complete the PackageInstall CR: ---
apiVersion: packaging.carvel.dev/v1alpha1
kind: PackageInstall
metadata:
name: telemetry
namespace: platform-install
spec:
serviceAccountName: telemetry-acct
packageRef:
refName: telemetry.platform.com
versionSelection:
constraints: 1.1.0
prereleases: {}
---
apiVersion: v1
kind: Secret
metadata:
name: telemetry-values
namespace: platform-install
stringData:
values.yml: |
apiVersion: observability/v1alpha1
kind: TelemetryConfig
spec:
... |
A potentially related example: the ability to — from within a template — take a YAML Fragment and encode it (complete with its annotations) ... Being able to do so means that such values (e.g. a k8s Secret who's data is an overlay) could be closer to being editable (overlay-able) as well... 🤔 |
Friendly bump, this still is strongly desired. |
i would vote for simply allowing |
While this is a good point, the problem with the above examples is that we don't want things to go through as:
and come out as:
but instead to come out as:
in the output. |
Just calling this out in abstract, but: What if we resolve some of this ambiguity issues by making a decision and then issuing warnings to the console when the application detects possible edge cases one the ones being called out for each various approach? Then maybe just add a flag maybe in the file to ignore that warning (e.g. sort of like what we already do for code linters). Just a thought. |
Another example is ability to generate yaml comments interpreted by IDEs such as the The following ytt output is performed using data.load, however lack of comments rendering would break such approach then using a ytt library instead (see related thread https://kubernetes.slack.com/archives/CH8KCCKA5/p1673719852280819 ) apiVersion: v1
kind: ConfigMap
metadata:
name: kuttle-test-files
annotations:
kapp.k14s.io/versioned: ""
kapp.k14s.io/num-versions: "5"
data:
kuttl-test-suite_00-all-tests.yaml: |-
# nonk8s
# See https://youtrack.jetbrains.com/issue/IDEA-307431/Kubernetes-Add-ability-to-suppress-k8s-schema-inspections-locally-by-comment#focus=Comments-27-6695586.0-0
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
metadata:
name: 00-all-tests
testDirs:
- /kuttl-test-suite/01-sample-static-pg
- /kuttl-test-suite/02-dynamic-small-pg
timeout: 3600
parallel: 1
suppress:
- "events"
namespace: "75-crossplane-sample-xrcs" |
@voor |
@c33s its not a cosmetic issue in many use cases. There are alot of cases i have had which im sure @voor alsi has encountered where i want to use ytt to output a ytt template. Think of an automation to produce ytt configurations. |
@vrabbi doesn't it work to use but in the end i think it should be configurabe |
No because then it would be parsed already by the initial ytt invocation |
Because for good and for bad ytt use the # symbol in its logic, i believe being explicit is needed. Part of the pain but huge benefit of ytt is that it is safe in nature unlike other tools using mechanisms like go templating. I feel the pain of not supporting plain # symbols but that is a byproduct of the core design of ytt which would be a complete breaking change if that were to change in my mind. Allowing the output of a plain # comment can be done i believe in the ideas put together by john on hackmd using the #@yaml/comment annotation which i think is a good option. You can also have ytt ignore comments in existing yaml by using the relevant flag when invoking ytt so as much as i feel the pain, i personally dont think that it is the right approach, i think being explicit is important, supporting emitting ytt templates and yaml with standard comments while not causing some really hard to debug issue is the critical aspect |
Just a simple comment to show support for the |
+1 to @drawsmcgraw and @voor's comments for support. This would be a great nice-to-have. |
originally @patricknelson added as a comment to related issue: #14 (comment):
It's not always essential for the resulting YAML to have comments for me, but it certainly would be very helpful!
What if we were to use a double
#
to work as an escape method when at the beginning of a line, so that the resulting YAML will contain a standard comment? For example, taken from the main demo at https://get-ytt.io:With the output resulting in:
I'm brand new to
ytt
(just doing research right now), so I'm asking just in case this isn't already available with first class syntax support without any special flags.The text was updated successfully, but these errors were encountered: