-
Notifications
You must be signed in to change notification settings - Fork 31
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
refactoring (support ODF in any Namespace) #1099
refactoring (support ODF in any Namespace) #1099
Conversation
1120a41
to
712f0be
Compare
switch (action.type) { | ||
case nsActions.SetOprInstallNs: | ||
return { | ||
...state, |
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.
This performs a shallow copy. The internal properties will be equal by reference, this can cause bugs. Use immutable
to help you work with state.
see https://immutable-js.com/
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.
done, added immer
as per the suggestion...
712f0be
to
6fee8e8
Compare
* Wrapper around "useK8sGet" hook. | ||
* Ensures no API request is made unless its "safe" to do so (ODF installed namespace is fetched successfully). | ||
*/ | ||
export const useSafeK8sGet = <R extends K8sResourceCommon = K8sResourceCommon>( |
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.
Is this required for the usecase when the user is not an admin?
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.
this can use used for any case (given we have required RBACs), it saves some unnecessary API calls... in case of non-admin, if we want we can pass allowFallback = true
argument which would default to openshift-storage
...
anyError, | ||
}) => | ||
!isAllSafe ? ( | ||
<StatusBox loaded={isAllLoaded} loadError={anyError} /> |
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.
Doesn't StatusBox
take a component as child?
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.
it does, but current way makes it possible to display children
even in case of any error (upto consumer of the FC to decide what to do)...
one of the example:
<StatusBox loaded={isAllLoaded} loadError={anyError} />{children}</StatusBox>
>> then in case of non-admin this will always show error as anyError
will not be empty (RBAC issue), but if I pass allowFallback
argument and use ternary condition (current way) I can still display children
, if I want to.
onChange={(e) => { | ||
onParamChange(parameterKey, e.currentTarget.value, false); | ||
}} |
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.
Why this change?
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 was testing something, then forgot to remove this... will update...
// ToDo (epic 4422): Need to pass the namespace where ceph cluster is deployed (remove from here, add dropdown) | ||
React.useEffect(() => { | ||
sessionStorage.setItem( | ||
CEPH_CLUSTER_NAMESPACE_SESSION_STORAGE, |
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.
CEPH_CLUSTER_NAMESPACE_SESSION_STORAGE, | |
CEPH_CLUSTER_NAMESPACE, |
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 agree it is a long name, but it is not really a CEPH_CLUSTER_NAMESPACE
, it is infact the "key" that we use to store the namespace in the session... will update anyway...
packages/odf/hooks/useSafeK8sGet.ts
Outdated
useOprInstallNamespaceSelector(); | ||
|
||
const canUseFallback = allowFallback && isFallbackSafe; | ||
const useK8sGetArgs = getValidK8sOptions( |
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.
const useK8sGetArgs = getValidK8sOptions( | |
const K8sGetArgs = getValidK8sOptions( |
use
should be prefix for hooks.
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.
ack...
|
||
/** | ||
* Wrapper around "useK8sGet" hook. | ||
* Ensures no API request is made unless its "safe" to do so (ODF installed namespace is fetched successfully). |
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.
IIUC this assumption is incorrect. A fetch request will go but it will just be a useless call. Nevertheless we are adding this call to our stack. If you really want to avoid this I suggest you use the fetch functions such as k8sGetResource
instead of useK8sGet
hook. This applies for other safe functions as well.
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.
it won't send any api call at all because of the resource object that I am passing to useK8sGet
(I defined getValidK8sOptions
for the very same reason)...
and I already updated useK8sGet
as well (in this same PR), there is a condition if (kind) fetch();
that would ensure no api call...
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.
same is true for other "safe" hook wrapper that I defined...
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 see if (kind) fetch();
anywhere. Can you point me to it?
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.
|
||
type UseOprInstallNamespaceDispatch = () => (payload: nsPayload) => void; | ||
|
||
export const useOprInstallNamespaceDispatch: UseOprInstallNamespaceDispatch = |
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 see much value of having a separate component. It's used in only one place. We can just simply dispatch the action with some args. Is this used in more than one place?
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.
not really, but it is more of a directory structure to keep things logically grouped together...
in future if we need another dispatcher (diff use case) then we can create a separate file for that (here under /redux/dispatchers
) and export via index
...
maybe useOprInstallNamespaceDispatch
is not reused, but others (in future) could be... so it's more of a way to group things under new redux
directory...
import { getNamespace } from '@odf/shared/selectors'; | ||
import { SubscriptionKind } from '@odf/shared/types'; | ||
import { k8sList } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { useOprInstallNamespaceDispatch } from '../dispatchers'; |
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.
Please see that you are not adding circular dependencies with imports.
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 think we have any circular dependency, maybe I missed somewhere ??
also we use CircularDependencyPlugin
in webpack config... so I am assuming we are safe...
|
||
return { | ||
// installed operator namespace | ||
oprInstallNs, |
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.
Could we do a better name odfNamespace
? Also how are we handling usecases for MCO? Do we need to detect MCO as well?
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.
ack !
we don't need it in MCO, there are just couple of places where we need this namespace and for that as well we need not to rely on this hook/redux (anyway MCO will be on hub and ODF on managed cluster, so this redux won't work for MCO)...
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.
gonna be lot of changes to rename everything though !!
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.
done...
getOprInstallNamespace | ||
); | ||
|
||
return { |
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 you return it as an array end users will not have to use the same name for variables. It might be better as we might have to support multiple namespaces for multiple operators.
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.
but array would mean to always read "return"ed values in same order... and if I don't want to read all values leaving gaps such as: const [oprInstallNs, _, _, isSafe] = useOprInstallNamespaceSelector();
...
if we want to rename we can use const { oprInstallNs: test } = useOprInstallNamespaceSelector();
right ??
if (kind) fetch(); | ||
else setLoaded(true); |
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.
cc @bipuladh
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.
same is true for useK8sList.ts
Adds a new package "immer". Adds a new extension "console.redux-reducer", for redux state. Adds a new hook "useOprInstallNamespaceSelector", for detecting ODF install namespace. Removes dependency on "openshift-storage" namespace.
6fee8e8
to
2396037
Compare
/test odf-console-e2e-aws |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bipuladh, SanjalKatiyar 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 |
5117053
into
red-hat-storage:master
Adds a new package "immer".
Adds a new extension "console.redux-reducer", for redux state.
Adds a new hook "useOprInstallNamespaceSelector", for detecting ODF install namespace.
Removes dependency on "openshift-storage" namespace.