Handle omitted LimitRange spec and/or spec.limits from k8s. #6928
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[Review carefully, I'm new to MIQ, k8s, Ruby and Go. All and any criticism welcome.]
This hopefully solves crash seen in the wild: https://bugzilla.redhat.com/1305324 where
spec.limits
wasnil
.It might be overzelous.
What I see from types.go is that
LimitRange.Spec
isjson:"spec,omitempty"
butLimitRangeSpec.Limits
isn't, it should always be an array.omitempty doc says:
This suggests that only
spec
missing entirely or:spec => {:limits => []}
are the plausible scenarious;:spec => nil
,:spec => {}
and:spec => {:limits => nil}
shouldn't happen.Nevertheless,
limits
being nil is what the traceback suggests?But I see RecursiveOpenStruct returns nil for missing attributes, so I suspect what happenned in the traceback is that
limits
wasn't there. However shouldn't thenspec
have been omitempty'd andspec.limits
crashed instead ofspec.limits.each
? I'm still confused...limit_range.spec.try(:limits) || []
would also work (it passes the 5 test scenarios). IMHOtry
on spec helps readability clarifyng we expect spec to be missing, but perhaps all code here relies on nil-for-missing anyway?|| []
,.to_a
or an explicit condition skipping the loop is best.