fix(kube-owner): owner labels from resources created via manifest [EE-6647] (#11102)

Co-authored-by: testa113 <testa113>
pull/10001/head^2
Ali 2024-02-12 15:30:49 +13:00 committed by GitHub
parent 80b1cd19cb
commit 901549e8dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 26 additions and 7 deletions

View File

@ -1,6 +1,8 @@
import { formatDate } from '@/portainer/filters/filters';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { ConfigMapRowData } from '../types';
import { configurationOwnerUsernameLabel } from '../../../constants';
import { columnHelper } from './helper';
@ -12,7 +14,8 @@ export const created = columnHelper.accessor((row) => getCreatedAtText(row), {
function getCreatedAtText(row: ConfigMapRowData) {
const owner =
row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
row.metadata?.labels?.[configurationOwnerUsernameLabel] ||
row.metadata?.labels?.[appOwnerLabel];
const date = formatDate(row.metadata?.creationTimestamp);
return owner ? `${date} by ${owner}` : date;
}

View File

@ -1,11 +1,13 @@
import { CellContext } from '@tanstack/react-table';
import { Authorized } from '@/react/hooks/useUser';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { Link } from '@@/Link';
import { Badge } from '@@/Badge';
import { ConfigMapRowData } from '../types';
import { configurationOwnerUsernameLabel } from '../../../constants';
import { columnHelper } from './helper';
@ -16,8 +18,11 @@ export const name = columnHelper.accessor(
const isSystemToken = name?.includes('default-token-');
const isSystemConfigMap = isSystemToken || row.isSystem;
const hasConfigurationOwner =
!!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
const hasConfigurationOwner = !!(
row.metadata?.labels?.[configurationOwnerUsernameLabel] ||
row.metadata?.labels?.[appOwnerLabel]
);
return `${name} ${isSystemConfigMap ? 'system' : ''} ${
!isSystemToken && !hasConfigurationOwner ? 'external' : ''
} ${!row.inUse && !isSystemConfigMap ? 'unused' : ''}`;

View File

@ -1,6 +1,8 @@
import { formatDate } from '@/portainer/filters/filters';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { SecretRowData } from '../types';
import { configurationOwnerUsernameLabel } from '../../../constants';
import { columnHelper } from './helper';
@ -12,7 +14,8 @@ export const created = columnHelper.accessor((row) => getCreatedAtText(row), {
function getCreatedAtText(row: SecretRowData) {
const owner =
row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
row.metadata?.labels?.[configurationOwnerUsernameLabel] ||
row.metadata?.labels?.[appOwnerLabel];
const date = formatDate(row.metadata?.creationTimestamp);
return owner ? `${date} by ${owner}` : date;
}

View File

@ -1,11 +1,13 @@
import { CellContext } from '@tanstack/react-table';
import { Authorized } from '@/react/hooks/useUser';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { Link } from '@@/Link';
import { Badge } from '@@/Badge';
import { SecretRowData } from '../types';
import { configurationOwnerUsernameLabel } from '../../../constants';
import { columnHelper } from './helper';
@ -18,8 +20,10 @@ export const name = columnHelper.accessor(
row.metadata?.annotations?.['portainer.io/registry.id'];
const isSystemSecret = isSystemToken || row.isSystem || isRegistrySecret;
const hasConfigurationOwner =
!!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
const hasConfigurationOwner = !!(
row.metadata?.labels?.[configurationOwnerUsernameLabel] ||
row.metadata?.labels?.[appOwnerLabel]
);
return `${name} ${isSystemSecret ? 'system' : ''} ${
!isSystemToken && !hasConfigurationOwner ? 'external' : ''
} ${!row.inUse && !isSystemSecret ? 'unused' : ''}`;

View File

@ -0,0 +1,2 @@
export const configurationOwnerUsernameLabel =
'io.portainer.kubernetes.configuration.owner';

View File

@ -1,4 +1,5 @@
import { formatDate } from '@/portainer/filters/filters';
import { appOwnerLabel } from '@/react/kubernetes/applications/constants';
import { columnHelper } from './helper';
@ -13,7 +14,8 @@ export const created = columnHelper.accessor(
cell: ({ row, getValue }) => {
const date = formatDate(getValue());
const owner =
row.original.Labels?.['io.portainer.kubernetes.ingress.owner'];
row.original.Labels?.['io.portainer.kubernetes.ingress.owner'] ||
row.original.Labels?.[appOwnerLabel];
return owner ? `${date} by ${owner}` : date;
},