Open deblaci opened 5 months ago
checking...
@deblaci I think your timestamp format is not correct (either it needs a timezone or a space between date and time). Which is the other yaml parser your are using which is parsing the unquoted string as timestamp? ytt (actually the underlying go.yaml parser) encloses data in quotes if it finds a valid timestamp
% cat timestamp.yaml
canonicalts: "2023-01-01T07:00:00.1Z"
canonicalts1: 2023-01-01T07:00:00.1Z
iso8601ts: "2023-01-01T07:00:00Z"
iso8601ts1: 2023-01-01T07:00:00Z
withspacets: "2023-01-01 07:00:00"
withspacets1: 2023-01-01 07:00:00
% ytt -f timestamp.yaml
canonicalts: "2023-01-01T07:00:00.1Z"
canonicalts1: "2023-01-01T07:00:00.1Z"
iso8601ts: "2023-01-01T07:00:00Z"
iso8601ts1: "2023-01-01T07:00:00Z"
withspacets: "2023-01-01 07:00:00"
withspacets1: "2023-01-01 07:00:00"
and currently ytt cannot force quotes see https://kubernetes.slack.com/archives/CH8KCCKA5/p1688043220329239 and https://kubernetes.slack.com/archives/CH8KCCKA5/p1668521528903319.
@prembhaskal Thanks for checking.
According to (https://yaml.org/type/timestamp.html), "2023-01-01T07:00:00" seems to be valid. I tried the regex. But If I would agree with the above timestamp is wrong, the above timestamp needs to be considered as a String.
Shouldn't Ytt generate a strict yaml in strict mode?
When I use Ytt in Strict mode, I give strict input yaml then I will get a non-strict yaml, since "exampleTimestamp: - 2023-01-01T07:00:00" is not a strict yaml without quote. (https://carvel.dev/ytt/docs/v0.46.x/strict/)
ytt: Error: Unmarshaling YAML template 'temp-yaml': • yaml: Strict parsing: Strings with colon must be explicitly quoted: • '2023-01-01T07:00:00'
I tried to parse the yaml with Groovy: import org-yaml.snakeyaml.Yaml new Yaml(). load(yamlContent) With Jenkins readYaml has same result
@deblaci so strict yaml is only for parsing. mainly we use strictdecoder of yaml library to achieve this. there is no encoder for strict output generation.
Upstream does not have this feature. We will try and find cycles to patch upstream.
What steps did you take:
When I provide a string but contains timestamp, after templating with Ytt this strings lose the quote. This would be valid, but yaml parsers handle this as a date not a string and convet it like Mon Sep 20 12:00:00 CEST 2021. This happens even I turn on strict yaml, according to rule "requires strings with colon to be explicitly quoted"
template.yaml: exampleTimestamp: "2023-01-01T07:00:00"
ytt -f template.yaml ytt -f template.yaml -s
What happened:
exampleTimestamp: 2023-01-01T07:00:00
What did you expect:
exampleTimestamp: "2023-01-01T07:00:00"
Environment:
ytt --version
): ytt version 0.47.0/etc/os-release
): ProductName: macOS ProductVersion: 14.2.1 BuildVersion: 23C71Vote on this request
👍 "I would like to see this addressed as soon as possible"