Skip to content
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

Include OAuth2 Service status in application and environment list #1053

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/components/app-list-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '../environments-summary/environment-card-status';
import {
aggregateComponentEnvironmentStatus,
aggregateReplicaEnvironmentStatus,
aggregateComponentReplicaEnvironmentStatus,
aggregateVulnerabilitySummaries,
EnvironmentStatus,
environmentVulnerabilitySummarizer,
Expand All @@ -35,7 +35,6 @@ import {
ApplicationSummary,
Component,
JobSummary,
ReplicaSummary,
} from '../../store/radix-api';
import { ImageScan, Vulnerability, scanApi } from '../../store/scan-api';
import { routeWithParams } from '../../utils/string';
Expand Down Expand Up @@ -71,13 +70,7 @@ function aggregateEnvironmentStatus(
): EnvironmentStatus {
return Math.max(
aggregateComponentEnvironmentStatus(components),
aggregateReplicaEnvironmentStatus(
components?.reduce<Array<ReplicaSummary>>(
(obj, { replicaList }) =>
!replicaList ? obj : [...obj, ...replicaList],
[]
)
)
aggregateComponentReplicaEnvironmentStatus(components)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/environments-summary/environment-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { EnvironmentIngress } from './environment-ingress';
import {
aggregateComponentEnvironmentStatus,
aggregateReplicaEnvironmentStatus,
aggregateComponentReplicaEnvironmentStatus,
environmentVulnerabilitySummarizer,
} from './environment-status-utils';

Expand Down Expand Up @@ -105,7 +105,7 @@ function CardContentBuilder(
const elements: EnvironmentCardStatusMap = {
Components: aggregateComponentEnvironmentStatus(components),
...(replicas.length > 0 && {
Replicas: aggregateReplicaEnvironmentStatus(replicas),
Replicas: aggregateComponentReplicaEnvironmentStatus(components),
}),
};

Expand Down
35 changes: 26 additions & 9 deletions src/components/environments-summary/environment-status-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { StatusBadgeTemplateType } from '../status-badges/status-badge-template'
import { StatusPopoverType } from '../status-popover/status-popover';
import { StatusTooltipTemplateType } from '../status-tooltips/status-tooltip-template';
import {
AuxiliaryResourceDeployment,
Component,
ReplicaStatus,
ReplicaSummary,
} from '../../store/radix-api';
import { EnvironmentVulnerabilities, ImageScan } from '../../store/scan-api';

Expand All @@ -17,18 +17,25 @@ export enum EnvironmentStatus {
Danger,
}

export type EnvironmentStatusType = StatusBadgeTemplateType &
type EnvironmentStatusType = StatusBadgeTemplateType &
StatusPopoverType &
StatusTooltipTemplateType;

export const ComponentStatusMap = Object.freeze<
const ComponentStatusMap = Object.freeze<
Partial<Record<Component['status'], EnvironmentStatus>>
>({
Stopped: EnvironmentStatus.Stopped,
Consistent: EnvironmentStatus.Consistent,
});

export const ReplicaStatusMap = Object.freeze<
const AuxiliaryResourceDeploymentStatusMap = Object.freeze<
Partial<Record<AuxiliaryResourceDeployment['status'], EnvironmentStatus>>
>({
Stopped: EnvironmentStatus.Stopped,
Consistent: EnvironmentStatus.Consistent,
});

const ReplicaStatusMap = Object.freeze<
Partial<Record<ReplicaStatus['status'], EnvironmentStatus>>
>({
Running: EnvironmentStatus.Running,
Expand All @@ -39,16 +46,26 @@ export function aggregateComponentEnvironmentStatus(
components: Readonly<Array<Component>>
): EnvironmentStatus {
return (components ?? []).reduce<EnvironmentStatus>(
(obj, { status }) =>
Math.max(ComponentStatusMap[status] ?? EnvironmentStatus.Warning, obj),
(obj, { status, oauth2 }) =>
Math.max(
ComponentStatusMap[status] ?? EnvironmentStatus.Warning,
AuxiliaryResourceDeploymentStatusMap[
oauth2?.deployment.status ?? 'Consistent'
] ?? EnvironmentStatus.Warning,
obj
),
EnvironmentStatus.Consistent
);
}

export function aggregateReplicaEnvironmentStatus(
replicas: Readonly<Array<ReplicaSummary>>
export function aggregateComponentReplicaEnvironmentStatus(
components: Readonly<Array<Component>>
): EnvironmentStatus {
return (replicas ?? []).reduce<EnvironmentStatus>(
const replicas = (components ?? [])
.flatMap((c) => c.replicaList)
.concat(components.flatMap((c) => c.oauth2?.deployment.replicaList ?? []));

return replicas.reduce<EnvironmentStatus>(
(obj, { replicaStatus }) =>
Math.max(
ReplicaStatusMap[replicaStatus?.status] ?? EnvironmentStatus.Warning,
Expand Down
Loading