-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Initialize labels and annotations on ObjectMeta #3898
Initialize labels and annotations on ObjectMeta #3898
Conversation
Linking to #3625 - The issue is that ObjectMetadata, labels, and annotations are all nullable (even with this change as the setters or getters are not guarding against null) and that complicates a lot of basic logic. One option is to go further with this change and enforce they are all non-null. The issue with that is that the serialization will change - that is instead of omitting metadata, you'll see metadata: {}, and similar changes for annotations and labels. Changing the generated code to add @JsonInclude(JsonInclude.Include.NON_EMPTY) on annotations and labels could help. Another option is to have convenience methods - HasMetadata.getOrCreateMetadata(), etc. that will guarantee non-null results. Another issue with this pr is that these modifications are to a generated class - which will get undone the next time the code is generated. |
What's the end purpose of this? Is it to be able to Considering this use-case, there's what Steven already mentioned. But there's also the immutable approach where you |
It could be for reads or writes. For writes a builder can make sense. For reads it's an awfully heavy weight approach. |
Yes it can. These are all driving at the same things. Here's the options:
|
Sorry I missed these replies! And yeah I totally missed that this was a generated class 😅 My purpose is for reading. I submitted this PR after fixing a bug where we got a NPE when no labels existed on a resource.
And I needed to update it to first check that labels weren't null:
Having the convenience methods for getting labels and annotations would definitely help; I could use just |
Closing this pr, I'll introduce another (#4160) based upon updating the generation logic. |
Description
Initialize the
labels
andannotations
maps on ObjectMeta so they're empty Maps instead of null if there are no labels/annotations on a resource.The
additionalProperties
map is already initialized in ObjectMeta, as are all the List fields, so I don't see a reason to not initialize thelabels
andannotations
too.Type of change
test, version modification, documentation, etc.)
Checklist
It says to open the PR as a draft if you haven't completed the checklist, but most of this doesn't seem warranted for such a simple change, and I'm afraid this won't be looked at if I don't just open for review