Skip to content

Commit

Permalink
Merge pull request #2195 from metalice/CNV-41290-disable-checkups-ins…
Browse files Browse the repository at this point in the history
…tall-button-for-not-cluster-reader

CNV-41290: Disable checkups storage install button for non cluster reader
  • Loading branch information
openshift-merge-bot[bot] authored Sep 23, 2024
2 parents 15944b1 + 3f08d84 commit 30c4d80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
IoK8sApiRbacV1ClusterRoleBinding,
} from '@kubevirt-ui/kubevirt-api/kubernetes';
import { ALL_NAMESPACES_SESSION_KEY } from '@kubevirt-utils/hooks/constants';
import { isEmpty } from '@kubevirt-utils/utils/utils';
import { useActiveNamespace, useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk';

import {
Expand Down Expand Up @@ -44,7 +45,9 @@ export const useCheckupsStoragePermissions = () => {
},
);

const [clusterRoleBinding] = useK8sWatchResource<IoK8sApiRbacV1ClusterRoleBinding[]>(
const [clusterRoleBinding, loadedClusterRoleBinding] = useK8sWatchResource<
IoK8sApiRbacV1ClusterRoleBinding[]
>(
!isAllNamespace && {
groupVersionKind: modelToGroupVersionKind(ClusterRoleBindingModel),
isList: true,
Expand Down Expand Up @@ -81,7 +84,11 @@ export const useCheckupsStoragePermissions = () => {

return {
clusterRoleBinding: isClusterRoleBinding,
isPermitted: Boolean(isServiceAccount && isConfigMapRole && isConfigMapRoleBinding),
loading: !loadingServiceAccounts && !loadingRoles && !loadingRolesBinding,
isPermitted: Boolean(
isServiceAccount && isConfigMapRole && isConfigMapRoleBinding && isClusterRoleBinding,
),
isPermittedToInstall: !isEmpty(clusterRoleBinding),
loading:
!loadingServiceAccounts && !loadingRoles && !loadingRolesBinding && !loadedClusterRoleBinding,
};
};
2 changes: 2 additions & 0 deletions src/views/checkups/storage/list/CheckupsStorageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CheckupsStorageList = () => {
const {
clusterRoleBinding,
isPermitted,
isPermittedToInstall,
loading: loadingPermissions,
} = useCheckupsStoragePermissions();
const { configMaps, error, jobs, loading } = useCheckupsStorageData();
Expand All @@ -38,6 +39,7 @@ const CheckupsStorageList = () => {
<CheckupsStorageListEmptyState
clusterRoleBinding={clusterRoleBinding}
isPermitted={isPermitted}
isPermittedToInstall={isPermittedToInstall}
loadingPermissions={loadingPermissions}
/>
);
Expand Down
16 changes: 14 additions & 2 deletions src/views/checkups/storage/list/CheckupsStorageListEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import './CheckupsStorageListEmptyState.scss';
type CheckupsStorageListEmptyStateProps = {
clusterRoleBinding: IoK8sApiRbacV1ClusterRoleBinding;
isPermitted: boolean;
isPermittedToInstall: boolean;
loadingPermissions: boolean;
};

const CheckupsStorageListEmptyState: FC<CheckupsStorageListEmptyStateProps> = ({
clusterRoleBinding,
isPermitted,
isPermittedToInstall,
loadingPermissions,
}) => {
const { t } = useKubevirtTranslation();
Expand Down Expand Up @@ -64,6 +66,12 @@ const CheckupsStorageListEmptyState: FC<CheckupsStorageListEmptyStateProps> = ({
</EmptyStateActions>
<EmptyStateActions>
<Button
isDisabled={
isLoading ||
loadingPermissions ||
namespace === ALL_NAMESPACES_SESSION_KEY ||
!isPermittedToInstall
}
onClick={async () => {
setIsLoading(true);
try {
Expand All @@ -76,15 +84,19 @@ const CheckupsStorageListEmptyState: FC<CheckupsStorageListEmptyStateProps> = ({
setIsLoading(false);
}
}}
isDisabled={isLoading || loadingPermissions || namespace === ALL_NAMESPACES_SESSION_KEY}
isLoading={isLoading || loadingPermissions}
variant={isLoading ? ButtonVariant.plain : ButtonVariant.secondary}
>
{!isLoading && isPermitted ? t('Remove permissions') : t('Install permissions')}
</Button>
</EmptyStateActions>
<EmptyStateActions className="empty-state-secondary-action">
<ExternalLink href={'#'} text={t('Learn more about storage checkups')} />
<ExternalLink
href={
'https://docs.openshift.com/container-platform/4.16/virt/monitoring/virt-running-cluster-checkups.html'
}
text={t('Learn more about storage checkups')}
/>
</EmptyStateActions>
</EmptyStateFooter>
</EmptyState>
Expand Down

0 comments on commit 30c4d80

Please sign in to comment.