Resolve NPE merging yaml when resource requests/limits are not set #310
Conversation
Function<ResourceRequirements, Map<String, Quantity>> resourceTypeMapper, | ||
String field) { | ||
Quantity templateField = resourceTypeMapper.apply(template.getResources()).get(field); | ||
if (templateField != null && !Strings.isNullOrEmpty(templateField.getAmount())) { |
carlossg
Apr 17, 2018
Contributor
would be clearer with Optional.ofNullable
as in https://github.com/jenkinsci/kubernetes-plugin/pull/311/files#diff-eff844000c9e60765310e70fa8c8a71cR208 ?
would be clearer with Optional.ofNullable
as in https://github.com/jenkinsci/kubernetes-plugin/pull/311/files#diff-eff844000c9e60765310e70fa8c8a71cR208 ?
Is this the proper fix? Either this change or something that was merged later results in objects that match the schema, but are rejected by the API server at validation time. The test case checks the former, but not the latter (which would require the Kubernetes Golang codebase). I suspect the This is what I am seeing if I don't specify all limits and requests, with line splits added for clarity:
The object might be well-formed, but the server rejects it at validation time and returns a 400, at least with Kubernetes 1.10. Proof that empty strings are problematic:
Reverting to 1.5.2 results in NPEs, of course. 1.6.0 has the same validation errors. I can file an issue in the tracker with all the above. |
I think |
I can try, but this is going to be a bit rough, since I haven't written any Java in 15 years. :) |
Ok, #342 seems to work, but it wasn't fun to write using only Chrome as the IDE. |
If you have a
PodTemplate
with a ContainerSpec, and want to also set theyaml
field to apply some things that aren't directly configurable through this plugin, then it's possible to hit NPEs if resource requests / limits aren't set. (In Kubernetes, it's perfectly valid not to set resource request / limit values forcpu
and memory.)This PR defensively codes to cover that case.