Skip to content

Nested defaults #3208

Closed Answered by camilamacedo86
tbarizien asked this question in Support
Discussion options

You must be logged in to vote

Hi @tbarizien,

The omitempty tag tells the Kubernetes API server (and the underlying Go JSON encoder) to omit the field from the output if it's empty. In Kubernetes CRDs, it's common to use omitempty for optional fields to keep the serialized output clean.

When using omitempty in conjunction with default values, I understand that it can lead to some non-intuitive behavior.

Following how I understand that it works:

  • With omitempty: If the field is not provided in the YAML (i.e., it's absent), it's considered "empty". So, it gets omitted, and defaulting does not take place for the omitted struct. This is because the CRD mechanism doesn't see the field at all; thus, it doesn't know to look f…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by camilamacedo86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants