fix(ui): mark resources system correctly [EE-6558] (#10996)

* fix(ui): mark resources system correctly [EE-6558]

* address review comments
pull/11002/head
Prabhat Khera 2024-01-23 13:49:25 +13:00 committed by GitHub
parent 85ae705833
commit f7840e0407
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 110 additions and 75 deletions

View File

@ -4,6 +4,7 @@ import { Pod } from 'kubernetes-types/core/v1';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { useStackFile } from '@/react/common/stacks/stack.service'; import { useStackFile } from '@/react/common/stacks/stack.service';
import { useNamespaceQuery } from '@/react/kubernetes/namespaces/queries/useNamespaceQuery';
import { Widget, WidgetBody } from '@@/Widget'; import { Widget, WidgetBody } from '@@/Widget';
import { Button } from '@@/buttons'; import { Button } from '@@/buttons';
@ -14,7 +15,6 @@ import {
useApplication, useApplication,
useApplicationServices, useApplicationServices,
} from '../../application.queries'; } from '../../application.queries';
import { isSystemNamespace } from '../../../namespaces/utils';
import { applicationIsKind, isExternalApplication } from '../../utils'; import { applicationIsKind, isExternalApplication } from '../../utils';
import { appStackIdLabel } from '../../constants'; import { appStackIdLabel } from '../../constants';
@ -39,6 +39,9 @@ export function ApplicationDetailsWidget() {
}, },
} = stateAndParams; } = stateAndParams;
const namespaceData = useNamespaceQuery(environmentId, namespace);
const isSystemNamespace = namespaceData.data?.IsSystem;
// get app info // get app info
const { data: app } = useApplication( const { data: app } = useApplication(
environmentId, environmentId,
@ -61,7 +64,7 @@ export function ApplicationDetailsWidget() {
<div className="col-sm-12"> <div className="col-sm-12">
<Widget> <Widget>
<WidgetBody> <WidgetBody>
{!isSystemNamespace(namespace) && ( {!isSystemNamespace && (
<div className="mb-4 flex flex-wrap gap-2"> <div className="mb-4 flex flex-wrap gap-2">
<Authorized authorizations="K8sApplicationDetailsW"> <Authorized authorizations="K8sApplicationDetailsW">
<Link to="kubernetes.applications.application.edit"> <Link to="kubernetes.applications.application.edit">

View File

@ -18,7 +18,6 @@ import { InlineLoader } from '@@/InlineLoader';
import { Icon } from '@@/Icon'; import { Icon } from '@@/Icon';
import { Note } from '@@/Note'; import { Note } from '@@/Note';
import { isSystemNamespace } from '../../namespaces/utils';
import { import {
appStackNameLabel, appStackNameLabel,
appKindToDeploymentTypeMap, appKindToDeploymentTypeMap,
@ -39,6 +38,7 @@ import {
usePatchApplicationMutation, usePatchApplicationMutation,
} from '../application.queries'; } from '../application.queries';
import { Application, ApplicationPatch } from '../types'; import { Application, ApplicationPatch } from '../types';
import { useNamespaceQuery } from '../../namespaces/queries/useNamespaceQuery';
export function ApplicationSummaryWidget() { export function ApplicationSummaryWidget() {
const stateAndParams = useCurrentStateAndParams(); const stateAndParams = useCurrentStateAndParams();
@ -56,7 +56,9 @@ export function ApplicationSummaryWidget() {
name, name,
resourceType resourceType
); );
const systemNamespace = isSystemNamespace(namespace); const namespaceData = useNamespaceQuery(environmentId, namespace);
const isSystemNamespace = namespaceData.data?.IsSystem;
const externalApplication = application && isExternalApplication(application); const externalApplication = application && isExternalApplication(application);
const applicationRequests = application && getResourceRequests(application); const applicationRequests = application && getResourceRequests(application);
const applicationOwner = application?.metadata?.labels?.[appOwnerLabel]; const applicationOwner = application?.metadata?.labels?.[appOwnerLabel];
@ -124,7 +126,7 @@ export function ApplicationSummaryWidget() {
data-cy="k8sAppDetail-appName" data-cy="k8sAppDetail-appName"
> >
{name} {name}
{externalApplication && !systemNamespace && ( {externalApplication && !isSystemNamespace && (
<Badge type="info">external</Badge> <Badge type="info">external</Badge>
)} )}
</div> </div>
@ -154,7 +156,7 @@ export function ApplicationSummaryWidget() {
> >
{namespace} {namespace}
</Link> </Link>
{systemNamespace && <Badge type="info">system</Badge>} {isSystemNamespace && <Badge type="info">system</Badge>}
</div> </div>
</td> </td>
</tr> </tr>
@ -231,7 +233,7 @@ export function ApplicationSummaryWidget() {
application?.metadata?.creationTimestamp application?.metadata?.creationTimestamp
).format('YYYY-MM-DD HH:mm:ss')} ).format('YYYY-MM-DD HH:mm:ss')}
</span> </span>
{(!externalApplication || systemNamespace) && ( {(!externalApplication || isSystemNamespace) && (
<span <span
className="flex items-center gap-1" className="flex items-center gap-1"
data-cy="k8sAppDetail-creationMethod" data-cy="k8sAppDetail-creationMethod"

View File

@ -6,12 +6,12 @@ import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
import { Authorized, useAuthorizations } from '@/react/hooks/useUser'; import { Authorized, useAuthorizations } from '@/react/hooks/useUser';
import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings'; import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription'; import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription';
import { useApplicationsQuery } from '@/react/kubernetes/applications/application.queries'; import { useApplicationsQuery } from '@/react/kubernetes/applications/application.queries';
import { Application } from '@/react/kubernetes/applications/types'; import { Application } from '@/react/kubernetes/applications/types';
import { pluralize } from '@/portainer/helpers/strings'; import { pluralize } from '@/portainer/helpers/strings';
import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery'; import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery';
import { Namespaces } from '@/react/kubernetes/namespaces/types';
import { Datatable, TableSettingsMenu } from '@@/datatables'; import { Datatable, TableSettingsMenu } from '@@/datatables';
import { confirmDelete } from '@@/modals/confirm'; import { confirmDelete } from '@@/modals/confirm';
@ -64,14 +64,15 @@ export function ConfigMapsDatatable() {
configMaps?.filter( configMaps?.filter(
(configMap) => (configMap) =>
(canAccessSystemResources && tableState.showSystemResources) || (canAccessSystemResources && tableState.showSystemResources) ||
!isSystemNamespace(configMap.metadata?.namespace ?? '') !namespaces?.[configMap.metadata?.namespace ?? '']?.IsSystem
) || [], ) || [],
[configMaps, tableState, canAccessSystemResources] [configMaps, tableState, canAccessSystemResources, namespaces]
); );
const configMapRowData = useConfigMapRowData( const configMapRowData = useConfigMapRowData(
filteredConfigMaps, filteredConfigMaps,
applications ?? [], applications ?? [],
applicationsQuery.isLoading applicationsQuery.isLoading,
namespaces
); );
return ( return (
@ -85,7 +86,7 @@ export function ConfigMapsDatatable() {
titleIcon={FileCode} titleIcon={FileCode}
getRowId={(row) => row.metadata?.uid ?? ''} getRowId={(row) => row.metadata?.uid ?? ''}
isRowSelectable={(row) => isRowSelectable={(row) =>
!isSystemNamespace(row.original.metadata?.namespace ?? '') !namespaces?.[row.original.metadata?.namespace ?? ''].IsSystem
} }
disableSelect={readOnly} disableSelect={readOnly}
renderTableActions={(selectedRows) => ( renderTableActions={(selectedRows) => (
@ -110,7 +111,8 @@ export function ConfigMapsDatatable() {
function useConfigMapRowData( function useConfigMapRowData(
configMaps: ConfigMap[], configMaps: ConfigMap[],
applications: Application[], applications: Application[],
applicationsLoading: boolean applicationsLoading: boolean,
namespaces?: Namespaces
): ConfigMapRowData[] { ): ConfigMapRowData[] {
return useMemo( return useMemo(
() => () =>
@ -119,8 +121,11 @@ function useConfigMapRowData(
inUse: inUse:
// if the apps are loading, set inUse to true to hide the 'unused' badge // if the apps are loading, set inUse to true to hide the 'unused' badge
applicationsLoading || getIsConfigMapInUse(configMap, applications), applicationsLoading || getIsConfigMapInUse(configMap, applications),
isSystem: namespaces
? namespaces?.[configMap.metadata?.namespace ?? '']?.IsSystem
: false,
})), })),
[configMaps, applicationsLoading, applications] [configMaps, applicationsLoading, applications, namespaces]
); );
} }

View File

@ -1,6 +1,5 @@
import { CellContext } from '@tanstack/react-table'; import { CellContext } from '@tanstack/react-table';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
@ -13,13 +12,9 @@ import { columnHelper } from './helper';
export const name = columnHelper.accessor( export const name = columnHelper.accessor(
(row) => { (row) => {
const name = row.metadata?.name; const name = row.metadata?.name;
const namespace = row.metadata?.namespace;
const isSystemToken = name?.includes('default-token-'); const isSystemToken = name?.includes('default-token-');
const isInSystemNamespace = namespace const isSystemConfigMap = isSystemToken || row.isSystem;
? isSystemNamespace(namespace)
: false;
const isSystemConfigMap = isSystemToken || isInSystemNamespace;
const hasConfigurationOwner = const hasConfigurationOwner =
!!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner']; !!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
@ -36,11 +31,9 @@ export const name = columnHelper.accessor(
function Cell({ row }: CellContext<ConfigMapRowData, string>) { function Cell({ row }: CellContext<ConfigMapRowData, string>) {
const name = row.original.metadata?.name; const name = row.original.metadata?.name;
const namespace = row.original.metadata?.namespace;
const isSystemToken = name?.includes('default-token-'); const isSystemToken = name?.includes('default-token-');
const isInSystemNamespace = namespace ? isSystemNamespace(namespace) : false; const isSystemConfigMap = isSystemToken || row.original.isSystem;
const isSystemConfigMap = isSystemToken || isInSystemNamespace;
const hasConfigurationOwner = const hasConfigurationOwner =
!!row.original.metadata?.labels?.[ !!row.original.metadata?.labels?.[

View File

@ -2,4 +2,5 @@ import { ConfigMap } from 'kubernetes-types/core/v1';
export interface ConfigMapRowData extends ConfigMap { export interface ConfigMapRowData extends ConfigMap {
inUse: boolean; inUse: boolean;
isSystem: boolean;
} }

View File

@ -6,12 +6,12 @@ import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
import { Authorized, useAuthorizations } from '@/react/hooks/useUser'; import { Authorized, useAuthorizations } from '@/react/hooks/useUser';
import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings'; import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription'; import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription';
import { useApplicationsQuery } from '@/react/kubernetes/applications/application.queries'; import { useApplicationsQuery } from '@/react/kubernetes/applications/application.queries';
import { Application } from '@/react/kubernetes/applications/types'; import { Application } from '@/react/kubernetes/applications/types';
import { pluralize } from '@/portainer/helpers/strings'; import { pluralize } from '@/portainer/helpers/strings';
import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery'; import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery';
import { Namespaces } from '@/react/kubernetes/namespaces/types';
import { Datatable, TableSettingsMenu } from '@@/datatables'; import { Datatable, TableSettingsMenu } from '@@/datatables';
import { confirmDelete } from '@@/modals/confirm'; import { confirmDelete } from '@@/modals/confirm';
@ -64,14 +64,15 @@ export function SecretsDatatable() {
secrets?.filter( secrets?.filter(
(secret) => (secret) =>
(canAccessSystemResources && tableState.showSystemResources) || (canAccessSystemResources && tableState.showSystemResources) ||
!isSystemNamespace(secret.metadata?.namespace ?? '') !namespaces?.[secret.metadata?.namespace ?? '']?.IsSystem
) || [], ) || [],
[secrets, tableState, canAccessSystemResources] [secrets, tableState, canAccessSystemResources, namespaces]
); );
const secretRowData = useSecretRowData( const secretRowData = useSecretRowData(
filteredSecrets, filteredSecrets,
applications ?? [], applications ?? [],
applicationsQuery.isLoading applicationsQuery.isLoading,
namespaces
); );
return ( return (
@ -85,7 +86,7 @@ export function SecretsDatatable() {
titleIcon={Lock} titleIcon={Lock}
getRowId={(row) => row.metadata?.uid ?? ''} getRowId={(row) => row.metadata?.uid ?? ''}
isRowSelectable={(row) => isRowSelectable={(row) =>
!isSystemNamespace(row.original.metadata?.namespace ?? '') !namespaces?.[row.original.metadata?.namespace ?? '']?.IsSystem
} }
disableSelect={readOnly} disableSelect={readOnly}
renderTableActions={(selectedRows) => ( renderTableActions={(selectedRows) => (
@ -110,7 +111,8 @@ export function SecretsDatatable() {
function useSecretRowData( function useSecretRowData(
secrets: Secret[], secrets: Secret[],
applications: Application[], applications: Application[],
applicationsLoading: boolean applicationsLoading: boolean,
namespaces?: Namespaces
): SecretRowData[] { ): SecretRowData[] {
return useMemo( return useMemo(
() => () =>
@ -119,8 +121,11 @@ function useSecretRowData(
inUse: inUse:
// if the apps are loading, set inUse to true to hide the 'unused' badge // if the apps are loading, set inUse to true to hide the 'unused' badge
applicationsLoading || getIsSecretInUse(secret, applications), applicationsLoading || getIsSecretInUse(secret, applications),
isSystem: namespaces
? namespaces?.[secret.metadata?.namespace ?? '']?.IsSystem
: false,
})), })),
[secrets, applicationsLoading, applications] [secrets, applicationsLoading, applications, namespaces]
); );
} }

View File

@ -1,6 +1,5 @@
import { CellContext } from '@tanstack/react-table'; import { CellContext } from '@tanstack/react-table';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
@ -13,16 +12,11 @@ import { columnHelper } from './helper';
export const name = columnHelper.accessor( export const name = columnHelper.accessor(
(row) => { (row) => {
const name = row.metadata?.name; const name = row.metadata?.name;
const namespace = row.metadata?.namespace;
const isSystemToken = name?.includes('default-token-'); const isSystemToken = name?.includes('default-token-');
const isInSystemNamespace = namespace
? isSystemNamespace(namespace)
: false;
const isRegistrySecret = const isRegistrySecret =
row.metadata?.annotations?.['portainer.io/registry.id']; row.metadata?.annotations?.['portainer.io/registry.id'];
const isSystemSecret = const isSystemSecret = isSystemToken || row.isSystem || isRegistrySecret;
isSystemToken || isInSystemNamespace || isRegistrySecret;
const hasConfigurationOwner = const hasConfigurationOwner =
!!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner']; !!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
@ -39,11 +33,9 @@ export const name = columnHelper.accessor(
function Cell({ row }: CellContext<SecretRowData, string>) { function Cell({ row }: CellContext<SecretRowData, string>) {
const name = row.original.metadata?.name; const name = row.original.metadata?.name;
const namespace = row.original.metadata?.namespace;
const isSystemToken = name?.includes('default-token-'); const isSystemToken = name?.includes('default-token-');
const isInSystemNamespace = namespace ? isSystemNamespace(namespace) : false; const isSystemSecret = isSystemToken || row.original.isSystem;
const isSystemSecret = isSystemToken || isInSystemNamespace;
const hasConfigurationOwner = const hasConfigurationOwner =
!!row.original.metadata?.labels?.[ !!row.original.metadata?.labels?.[

View File

@ -2,4 +2,5 @@ import { Secret } from 'kubernetes-types/core/v1';
export interface SecretRowData extends Secret { export interface SecretRowData extends Secret {
inUse: boolean; inUse: boolean;
isSystem: boolean;
} }

View File

@ -7,7 +7,6 @@ import { useAuthorizations, Authorized } from '@/react/hooks/useUser';
import Route from '@/assets/ico/route.svg?c'; import Route from '@/assets/ico/route.svg?c';
import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings'; import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription'; import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription';
import { confirmDelete } from '@@/modals/confirm'; import { confirmDelete } from '@@/modals/confirm';
@ -19,6 +18,7 @@ import { useTableState } from '@@/datatables/useTableState';
import { DeleteIngressesRequest, Ingress } from '../types'; import { DeleteIngressesRequest, Ingress } from '../types';
import { useDeleteIngresses, useIngresses } from '../queries'; import { useDeleteIngresses, useIngresses } from '../queries';
import { useNamespacesQuery } from '../../namespaces/queries/useNamespacesQuery'; import { useNamespacesQuery } from '../../namespaces/queries/useNamespacesQuery';
import { Namespaces } from '../../namespaces/types';
import { columns } from './columns'; import { columns } from './columns';
@ -54,9 +54,14 @@ export function IngressDatatable() {
ingresses?.filter( ingresses?.filter(
(ingress) => (ingress) =>
(canAccessSystemResources && tableState.showSystemResources) || (canAccessSystemResources && tableState.showSystemResources) ||
!isSystemNamespace(ingress.Namespace ?? '') !namespaces?.[ingress.Namespace].IsSystem
) || [], ) || [],
[ingresses, tableState, canAccessSystemResources] [ingresses, tableState, canAccessSystemResources, namespaces]
);
const ingressesWithIsSystem = useIngressesRowData(
filteredIngresses || [],
namespaces
); );
const deleteIngressesMutation = useDeleteIngresses(); const deleteIngressesMutation = useDeleteIngresses();
@ -66,13 +71,14 @@ export function IngressDatatable() {
return ( return (
<Datatable <Datatable
settingsManager={tableState} settingsManager={tableState}
dataset={filteredIngresses} dataset={ingressesWithIsSystem}
columns={columns} columns={columns}
isLoading={ingressesQuery.isLoading || namespacesQuery.isLoading} isLoading={ingressesQuery.isLoading || namespacesQuery.isLoading}
emptyContentLabel="No supported ingresses found" emptyContentLabel="No supported ingresses found"
title="Ingresses" title="Ingresses"
titleIcon={Route} titleIcon={Route}
getRowId={(row) => row.Name + row.Type + row.Namespace} getRowId={(row) => row.Name + row.Type + row.Namespace}
isRowSelectable={(row) => !namespaces?.[row.original.Namespace].IsSystem}
renderTableActions={tableActions} renderTableActions={tableActions}
renderTableSettings={() => ( renderTableSettings={() => (
<TableSettingsMenu> <TableSettingsMenu>
@ -88,6 +94,21 @@ export function IngressDatatable() {
/> />
); );
// useIngressesRowData appends the `isSyetem` property to the service data
function useIngressesRowData(
ingresses: Ingress[],
namespaces?: Namespaces
): Ingress[] {
return useMemo(
() =>
ingresses.map((r) => ({
...r,
IsSystem: namespaces ? namespaces?.[r.Namespace].IsSystem : false,
})),
[ingresses, namespaces]
);
}
function tableActions(selectedFlatRows: Ingress[]) { function tableActions(selectedFlatRows: Ingress[]) {
return ( return (
<div className="ingressDatatable-actions"> <div className="ingressDatatable-actions">

View File

@ -1,7 +1,6 @@
import { CellContext } from '@tanstack/react-table'; import { CellContext } from '@tanstack/react-table';
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { Link } from '@@/Link'; import { Link } from '@@/Link';
import { Badge } from '@@/Badge'; import { Badge } from '@@/Badge';
@ -19,7 +18,6 @@ export const name = columnHelper.accessor('Name', {
function Cell({ row, getValue }: CellContext<Ingress, string>) { function Cell({ row, getValue }: CellContext<Ingress, string>) {
const name = getValue(); const name = getValue();
const namespace = row.original.Namespace; const namespace = row.original.Namespace;
const isSystemIngress = isSystemNamespace(namespace);
return ( return (
<div className="flex flex-nowrap whitespace-nowrap"> <div className="flex flex-nowrap whitespace-nowrap">
@ -36,7 +34,7 @@ function Cell({ row, getValue }: CellContext<Ingress, string>) {
{name} {name}
</Link> </Link>
</Authorized> </Authorized>
{isSystemIngress && ( {row.original.IsSystem && (
<Badge type="success" className="ml-2"> <Badge type="success" className="ml-2">
System System
</Badge> </Badge>

View File

@ -35,6 +35,8 @@ export type Ingress = {
Type?: string; Type?: string;
Labels?: Record<string, string>; Labels?: Record<string, string>;
CreationDate?: string; CreationDate?: string;
IsSystem?: boolean;
}; };
export interface DeleteIngressesRequest { export interface DeleteIngressesRequest {

View File

@ -4,7 +4,7 @@ import axios, { parseAxiosError } from '@/portainer/services/axios';
import { notifyError } from '@/portainer/services/notifications'; import { notifyError } from '@/portainer/services/notifications';
import { EnvironmentId } from '@/react/portainer/environments/types'; import { EnvironmentId } from '@/react/portainer/environments/types';
import { Namespaces } from '../types'; import { DefaultOrSystemNamespace } from '../types';
export function useNamespaceQuery( export function useNamespaceQuery(
environmentId: EnvironmentId, environmentId: EnvironmentId,
@ -27,7 +27,7 @@ export async function getNamespace(
namespace: string namespace: string
) { ) {
try { try {
const { data: ns } = await axios.get<Namespaces>( const { data: ns } = await axios.get<DefaultOrSystemNamespace>(
`kubernetes/${environmentId}/namespaces/${namespace}` `kubernetes/${environmentId}/namespaces/${namespace}`
); );
return ns; return ns;

View File

@ -1,6 +1,8 @@
export interface Namespaces { export interface Namespaces {
[key: string]: { [key: string]: DefaultOrSystemNamespace;
IsDefault: boolean; }
IsSystem: boolean;
}; export interface DefaultOrSystemNamespace {
IsDefault: boolean;
IsSystem: boolean;
} }

View File

@ -1,10 +0,0 @@
export const systemNamespaces = [
'kube-system',
'kube-public',
'kube-node-lease',
'portainer',
];
export function isSystemNamespace(namespace: string) {
return systemNamespaces.includes(namespace || '');
}

View File

@ -1,14 +1,15 @@
import { useMemo } from 'react';
import { Shuffle, Trash2 } from 'lucide-react'; import { Shuffle, Trash2 } from 'lucide-react';
import { useRouter } from '@uirouter/react'; import { useRouter } from '@uirouter/react';
import clsx from 'clsx'; import clsx from 'clsx';
import { Row } from '@tanstack/react-table'; import { Row } from '@tanstack/react-table';
import { Namespaces } from '@/react/kubernetes/namespaces/types';
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
import { Authorized, useAuthorizations } from '@/react/hooks/useUser'; import { Authorized, useAuthorizations } from '@/react/hooks/useUser';
import { notifyError, notifySuccess } from '@/portainer/services/notifications'; import { notifyError, notifySuccess } from '@/portainer/services/notifications';
import { pluralize } from '@/portainer/helpers/strings'; import { pluralize } from '@/portainer/helpers/strings';
import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings'; import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription'; import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription';
import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery'; import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery';
@ -52,12 +53,17 @@ export function ServicesDatatable() {
const filteredServices = services?.filter( const filteredServices = services?.filter(
(service) => (service) =>
(canAccessSystemResources && tableState.showSystemResources) || (canAccessSystemResources && tableState.showSystemResources) ||
!isSystemNamespace(service.Namespace) !namespaces?.[service.Namespace].IsSystem
);
const servicesWithIsSystem = useServicesRowData(
filteredServices || [],
namespaces
); );
return ( return (
<Datatable <Datatable
dataset={filteredServices || []} dataset={servicesWithIsSystem || []}
columns={columns} columns={columns}
settingsManager={tableState} settingsManager={tableState}
isLoading={servicesQuery.isLoading || namespacesQuery.isLoading} isLoading={servicesQuery.isLoading || namespacesQuery.isLoading}
@ -65,7 +71,7 @@ export function ServicesDatatable() {
title="Services" title="Services"
titleIcon={Shuffle} titleIcon={Shuffle}
getRowId={(row) => row.UID} getRowId={(row) => row.UID}
isRowSelectable={(row) => !isSystemNamespace(row.original.Namespace)} isRowSelectable={(row) => !namespaces?.[row.original.Namespace].IsSystem}
disableSelect={readOnly} disableSelect={readOnly}
renderTableActions={(selectedRows) => ( renderTableActions={(selectedRows) => (
<TableActions selectedItems={selectedRows} /> <TableActions selectedItems={selectedRows} />
@ -87,6 +93,21 @@ export function ServicesDatatable() {
); );
} }
// useServicesRowData appends the `isSyetem` property to the service data
function useServicesRowData(
services: Service[],
namespaces?: Namespaces
): Service[] {
return useMemo(
() =>
services.map((service) => ({
...service,
IsSystem: namespaces ? namespaces?.[service.Namespace].IsSystem : false,
})),
[services, namespaces]
);
}
// needed to apply custom styling to the row cells and not globally. // needed to apply custom styling to the row cells and not globally.
// required in the AC's for this ticket. // required in the AC's for this ticket.
function servicesRenderRow(row: Row<Service>, highlightedItemId?: string) { function servicesRenderRow(row: Row<Service>, highlightedItemId?: string) {

View File

@ -1,5 +1,4 @@
import { Authorized } from '@/react/hooks/useUser'; import { Authorized } from '@/react/hooks/useUser';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { Badge } from '@@/Badge'; import { Badge } from '@@/Badge';
@ -11,13 +10,12 @@ export const name = columnHelper.accessor(
const isExternal = const isExternal =
!row.Labels || !row.Labels['io.portainer.kubernetes.application.owner']; !row.Labels || !row.Labels['io.portainer.kubernetes.application.owner'];
const isSystem = isSystemNamespace(row.Namespace);
if (isExternal && !isSystem) { if (isExternal && !row.IsSystem) {
name = `${name} external`; name = `${name} external`;
} }
if (isSystem) { if (row.IsSystem) {
name = `${name} system`; name = `${name} system`;
} }
return name; return name;
@ -27,7 +25,6 @@ export const name = columnHelper.accessor(
id: 'name', id: 'name',
cell: ({ row }) => { cell: ({ row }) => {
const name = row.original.Name; const name = row.original.Name;
const isSystem = isSystemNamespace(row.original.Namespace);
const isExternal = const isExternal =
!row.original.Labels || !row.original.Labels ||
@ -38,13 +35,13 @@ export const name = columnHelper.accessor(
<Authorized authorizations="K8sServiceW" childrenUnauthorized={name}> <Authorized authorizations="K8sServiceW" childrenUnauthorized={name}>
{name} {name}
{isSystem && ( {row.original.IsSystem && (
<Badge type="success" className="ml-2"> <Badge type="success" className="ml-2">
System System
</Badge> </Badge>
)} )}
{isExternal && !isSystem && ( {isExternal && !row.original.IsSystem && (
<Badge className="ml-2">External</Badge> <Badge className="ml-2">External</Badge>
)} )}
</Authorized> </Authorized>

View File

@ -38,6 +38,8 @@ export type Service = {
ExternalIPs?: Array<string>; ExternalIPs?: Array<string>;
CreationTimestamp: string; CreationTimestamp: string;
Applications?: Application[]; Applications?: Application[];
IsSystem?: boolean;
}; };
export type NodeMetrics = { export type NodeMetrics = {