Skip to content

Conversation

@cbandy
Copy link
Member

@cbandy cbandy commented Feb 26, 2025

The sigs.k8s.io/yaml package alone does not produce the same results as the Kubernetes API. This new function produces the same results and uses type parameters to accept input as a string or byte slice.

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • Testing enhancement

backups: { pgBackRest: { image: spec-image } },
}`), &cluster.Spec))
require.UnmarshalInto(t, &cluster.Spec, `{
backups: { pgbackrest: { image: spec-image } },
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 The new helper identified this typo and another a few lines down.

"loop_wait": int32(10),
"ttl": int32(30),
"retry_timeout": float64(5),
"retry_timeout": int64(5),
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 I noticed this difference while testing validation in Kubernetes.

Comment on lines +19 to +26
// Any fraction that amounts to an integral number is converted to an integer.
// See: https://go.dev/play/p/dvXRVhYO8UH
{input: `3`, expected: int64(3)},
{input: `3.000`, expected: int64(3)},
{input: `0.03e2`, expected: int64(3)},
{input: `{a: 5}`, expected: map[string]any{"a": int64(5)}},
{input: `{a: 5.000}`, expected: map[string]any{"a": int64(5)}},
{input: `{a: 0.05e2}`, expected: map[string]any{"a": int64(5)}},
Copy link
Member Author

Choose a reason for hiding this comment

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

📝 This surprised me in a recent Kubernetes and sent me to read about how the API unmarshals things.

@cbandy cbandy marked this pull request as ready for review February 26, 2025 02:46
The "sigs.k8s.io/yaml" package alone does not produce the same results
as the Kubernetes API. This new function produces the same results and
uses type parameters to accept input as a string or byte slice.
@cbandy cbandy merged commit 19a28f7 into CrunchyData:main Feb 26, 2025
18 of 19 checks passed
@cbandy cbandy deleted the unmarshal-helper branch February 26, 2025 16:14
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.

2 participants