-
Notifications
You must be signed in to change notification settings - Fork 616
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
Firehose: honor optional
prop for watches on individual resources
#1711
Firehose: honor optional
prop for watches on individual resources
#1711
Conversation
If set to `true`, a resource is skipped from generic `loadError` 404 checking (cross-resources). So the overall data retrieval does not fail if a specified resource is missing. Can be used to optionally query a resource but enable rendering of children if it is missing (HTTP 404). The new property is an addition to existing `optional` property which does not block rendering of children if list-retrieval is still in progress. With default value `ignoreIfMissing = false`, the component is backward compatible.
Hi @mareklibra. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
stuff = stuff.toJS(); | ||
stuff.ignoreIfMissing = props.ignoreIfMissing; | ||
} | ||
return stuff || {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use the same approach which is used for lists?
const data = k8s.getIn([reduxID, 'data']);
return {
data: data && data.toJS(),
loadError: k8s.getIn([reduxID, 'loadError']),
loaded: k8s.getIn([reduxID, 'loaded']),
optional: props.optional,
ignoreIfMissing: props.ignoreIfMissing,
};
This way we can optionally swap the toJS
with only immutables once they are needed in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the stuff
is not the response received from API but already a wrapper around it, please see
console/frontend/public/reducers/k8s.ts
Line 135 in 98211bb
return state.mergeIn([id], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but it will be easier to extend for adding a support of raw immutables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meaning that toJS
may not be used at all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is needed, I propose to do it in a follow-up.
It would require refactoring of code around the reducer and this is unrelated to original need behind this PR.
@mareklibra I'm confused: how is this different than |
@@ -208,6 +223,7 @@ Firehose.propTypes = { | |||
selector: PropTypes.object, | |||
fieldSelector: PropTypes.string, | |||
isList: PropTypes.bool, | |||
optional: PropTypes.bool, | |||
optional: PropTypes.bool, // do not block children-rendering while resource is still being loaded | |||
ignoreIfMissing: PropTypes.bool, // do not fail if the resource is missing (HTTP 404) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone can opinionate that optional
can be reused for that feature, as the difference is quite small.
I prefer to keep semantics of optional
as it is, so existing functionality will not be broken.
If not clear otherwise: if optional=true
, the children are rendered no matter if loading is still in progress. And eventually causes error 404 afterwards.
With ignoreIfMissing=true
only, the rendering is postponed till data are loaded or errored. But 404 is not a blocker for rendering. A child component can still check the error code, but the overall error checking is not affected.
It makes sense to set these props individually same as both together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having two similarly-named properties that behave almost the same, but subtly different, makes for a confusing API. I'm still unclear on the difference even after the explaination :) Can't callers check the loaded
value if they don't want to render when loading?
I'd prefer either:
- Using
optional
as-is - Changing
optional
if we think there is better behavior (as long as we can do so without breaking current use)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only see 5 places where optional
is used today, so changing behavior is an option as long we can test / update those places.
Again, I'm still unclear on what's different. Can you give a specific example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that when reusing StatusBox
component.
If optional=true
for a single (non-list) object and 404 occurs, the Firehose
injects top-level loadError
with 404.
With the change proposed in this PR, the ignoreIfMissing
resource will not affect the top-level loadError
with 404.
My component structure is like:
<Firehose>
<StatusBox>
<MyComponent>
I can change behaviour in StatusBox
by ignoring the top-level loadError and checking loadError on every loaded resource, but this is more complicated and would introduce more confusion.
Or I can re-implement StatusBox, but this goes against reusability.
Again, expected behaviour by this PR is:
optional=true
==> do not postpone rendering but fail on 404ignoreIfMissing=true
==> postpone rendering but ignore 404- both set to true ==> do not block rendering and do not fail if 404 - the resource is really optional we do not care about it's availability.
If we change semantics of optional
to act like the third option above only, it will be difficult to implement scenario for immediate (non-blocking) rendering of a page/detail and failing asynchronously if missing.
My PRs do not need this feature but I am not sure whether this is not already expected on other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
optional=true
for a single (non-list) object and 404 occurs, theFirehose
injects top-levelloadError
with 404.
That sounds like a bug. Are we sure that's how optional
is intended to behave? Can we simply fix optional
? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a "fix" would be simple.
I don't see optional
defined anywhere except just the code.
It was my natural understanding that optional
should ignore 404. But I am not sure whether something is not already relying on recent semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the history, but I believe it was originally added to avoid 403 errors when you don't have permission. I don't see a reason to handle 404 the same way, though.
The places to check are:
- frontend/public/components/resource-quota.jsx
- frontend/public/components/operator-lifecycle-manager/k8s-resource.tsx
- frontend/public/components/RBAC/role.jsx
- frontend/public/components/RBAC/bindings.jsx
- frontend/public/components/cluster-settings/cluster-settings.tsx
I don't see any other usages.
If a resource is `optional: true` then it is excluded from setting of top-level loadError. Firehose's child component can still check loadError by inspecting the resource directly.
@spadgett , I changed semantics of |
/ok-to-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
@@ -25,8 +25,12 @@ const processReduxId = ({k8s}, props) => { | |||
} | |||
|
|||
if (!isList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, OK. I see now. We didn't have proper support for optional
with individual resources, only lists.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mareklibra, spadgett The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
optional
prop for watches on individual resources
/retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
…penshift#1711) * Firehose: introduce "ignoreIfMissing" resource property If set to `true`, a resource is skipped from generic `loadError` 404 checking (cross-resources). So the overall data retrieval does not fail if a specified resource is missing. Can be used to optionally query a resource but enable rendering of children if it is missing (HTTP 404). The new property is an addition to existing `optional` property which does not block rendering of children if list-retrieval is still in progress. With default value `ignoreIfMissing = false`, the component is backward compatible. * Firehose: fix the `optional` property for 404 If a resource is `optional: true` then it is excluded from setting of top-level loadError. Firehose's child component can still check loadError by inspecting the resource directly.
Introduce
ignoreIfMissing
Firehose resource property.If set to
true
, a resource is skipped from genericloadError
404 checking (cross-resources). So the overall dataretrieval does not fail if a specified resource is missing.
Can be used to optionally query a resource but enable rendering
of children if it is missing (HTTP 404).
The new property is an addition to existing
optional
property whichdoes not block rendering of children if list-retrieval is still in progress.
With default value
ignoreIfMissing = false
, the component isbackward compatible.