Skip to content

Commit b6b1302

Browse files
Merge pull request #13417 from sg00dwin/show-vpas-for-project
OCPBUGS-23925: Only show VPAs that are associated with the selected namespace
2 parents 8d633dc + cc84811 commit b6b1302

5 files changed

Lines changed: 57 additions & 48 deletions

File tree

frontend/packages/console-app/locales/en/console-app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,10 @@
552552
"Source": "Source",
553553
"VolumeSnapshotContent": "VolumeSnapshotContent",
554554
"Snapshot content": "Snapshot content",
555-
"VerticalPodAutoscaler": "VerticalPodAutoscaler",
556555
"Recommended": "Recommended",
557556
"Container name": "Container name",
558-
"No VerticalPodAutoscaler": "No VerticalPodAutoscaler",
557+
"VerticalPodAutoscalers": "VerticalPodAutoscalers",
558+
"No VerticalPodAutoscalers": "No VerticalPodAutoscalers",
559559
"Cluster": "Cluster",
560560
"Control Plane": "Control Plane",
561561
"Control Plane status": "Control Plane status",

frontend/packages/console-app/src/components/vpa/VerticalPodAutoscalerRecommendations.tsx

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,37 @@ import { useTranslation } from 'react-i18next';
33
import { getGroupVersionKindForResource } from '@console/dynamic-plugin-sdk/src/utils/k8s/k8s-ref';
44
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';
55
import { ResourceLink } from '@console/internal/components/utils/resource-link';
6-
import { K8sResourceCommon } from '@console/internal/module/k8s';
7-
import { getVerticalPodAutoscalerForResource } from '@console/shared/src';
6+
import { K8sResourceKind } from '@console/internal/module/k8s';
7+
import { getVerticalPodAutoscalersForResource } from '@console/shared/src';
8+
9+
const Recommendations: React.FC<VerticalPodAutoscalerRecommendationsProps> = ({ obj }) => {
10+
const { t } = useTranslation();
11+
const recommendations = obj?.status?.recommendation?.containerRecommendations ?? [];
12+
return (
13+
<>
14+
{recommendations.length > 0 && <p>{t('console-app~Recommended')}</p>}
15+
{recommendations.map((recommendation) => (
16+
<React.Fragment key={recommendation.containerName}>
17+
<div>
18+
{t('console-app~Container name')}: {recommendation.containerName}
19+
</div>
20+
<div>
21+
{t('console-app~CPU')}: {recommendation.target.cpu}
22+
</div>
23+
<div>
24+
{t('console-app~Memory')}: {recommendation.target.memory}
25+
</div>
26+
</React.Fragment>
27+
))}
28+
</>
29+
);
30+
};
831

932
export const VerticalPodAutoscalerRecommendations: React.FC<VerticalPodAutoscalerRecommendationsProps> = ({
1033
obj,
1134
}) => {
1235
const { t } = useTranslation();
13-
const [vpas] = useK8sWatchResource<K8sResourceCommon[]>({
36+
const [vpas] = useK8sWatchResource<K8sResourceKind[]>({
1437
groupVersionKind: {
1538
group: 'autoscaling.k8s.io',
1639
version: 'v1',
@@ -21,46 +44,31 @@ export const VerticalPodAutoscalerRecommendations: React.FC<VerticalPodAutoscale
2144
namespaced: true,
2245
});
2346

24-
const verticalPodAutoscaler = getVerticalPodAutoscalerForResource(vpas, obj);
25-
const recommendations =
26-
verticalPodAutoscaler?.status?.recommendation?.containerRecommendations ?? [];
47+
const verticalPodAutoscalers = getVerticalPodAutoscalersForResource(vpas, obj);
2748

2849
return (
2950
<>
30-
<dt>{t('console-app~VerticalPodAutoscaler')}</dt>
51+
<dt>{t('console-app~VerticalPodAutoscalers')}</dt>
3152
<dd>
32-
{verticalPodAutoscaler ? (
33-
<>
34-
<p>
35-
<ResourceLink
36-
groupVersionKind={getGroupVersionKindForResource(verticalPodAutoscaler)}
37-
name={verticalPodAutoscaler?.metadata?.name}
38-
namespace={verticalPodAutoscaler?.metadata?.namespace}
39-
/>
40-
</p>
41-
{recommendations.length > 0 && <p>{t('console-app~Recommended')}</p>}
42-
{recommendations.map((recommendation) => (
43-
<React.Fragment key={recommendation.containerName}>
44-
<div>
45-
{t('console-app~Container name')}: {recommendation.containerName}
46-
</div>
47-
<div>
48-
{t('console-app~CPU')}: {recommendation.target.cpu}
49-
</div>
50-
<div>
51-
{t('console-app~Memory')}: {recommendation.target.memory}
52-
</div>
53-
</React.Fragment>
54-
))}
55-
</>
56-
) : (
57-
t('console-app~No VerticalPodAutoscaler')
58-
)}
53+
{verticalPodAutoscalers.length > 0
54+
? verticalPodAutoscalers.map((vpa) => (
55+
<>
56+
<p>
57+
<ResourceLink
58+
groupVersionKind={getGroupVersionKindForResource(vpa)}
59+
name={vpa?.metadata?.name}
60+
namespace={vpa?.metadata?.namespace}
61+
/>
62+
</p>
63+
<Recommendations obj={vpa} />
64+
</>
65+
))
66+
: t('console-app~No VerticalPodAutoscalers')}
5967
</dd>
6068
</>
6169
);
6270
};
6371

6472
type VerticalPodAutoscalerRecommendationsProps = {
65-
obj: K8sResourceCommon;
73+
obj: K8sResourceKind;
6674
};

frontend/packages/console-shared/src/utils/resource-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,11 @@ export const getLimitsDataFromResource = (resource: K8sResourceKind) => {
766766
return limitsData;
767767
};
768768

769-
export const getVerticalPodAutoscalerForResource = (
769+
export const getVerticalPodAutoscalersForResource = (
770770
vpas: K8sResourceKind[],
771771
obj: K8sResourceKind,
772772
) =>
773-
(vpas ?? []).find((vpa) => {
773+
(vpas ?? []).filter((vpa) => {
774774
const { targetRef } = vpa.spec;
775775
return (
776776
targetRef &&

frontend/packages/topology/locales/en/topology.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"Health checks": "Health checks",
135135
"Add health checks": "Add health checks",
136136
"Resource Quotas": "Resource Quotas",
137-
"VerticalPodAutoscaler": "VerticalPodAutoscaler",
137+
"VerticalPodAutoscalers": "VerticalPodAutoscalers",
138138
"Visual connector": "Visual connector",
139139
"Expand groups": "Expand groups",
140140
"Pod count": "Pod count",

frontend/packages/topology/src/components/workload/vpa-tab-section.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getGroupVersionKindForResource } from '@console/dynamic-plugin-sdk/src/
66
import { ResourceLink, SidebarSectionHeading } from '@console/internal/components/utils';
77
import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watch-hook';
88
import { K8sResourceCommon } from '@console/internal/module/k8s';
9-
import { getVerticalPodAutoscalerForResource } from '@console/shared/src';
9+
import { getVerticalPodAutoscalersForResource } from '@console/shared/src';
1010
import { TYPE_WORKLOAD } from '@console/topology/src/const';
1111
import { getResource } from '../../utils';
1212
import TopologySideBarTabSection from '../side-bar/TopologySideBarTabSection';
@@ -19,7 +19,7 @@ const VPATabSection: React.FC<VPATabSectionProps> = ({ vpas }) => {
1919
const { t } = useTranslation();
2020
return (
2121
<>
22-
<SidebarSectionHeading text={t('topology~VerticalPodAutoscaler')} />
22+
<SidebarSectionHeading text={t('topology~VerticalPodAutoscalers')} />
2323
<ul className="list-group">
2424
{vpas.map((vpa: K8sResourceCommon) => (
2525
<li key={vpa.metadata.name} className="list-group-item">
@@ -51,12 +51,13 @@ export const useVpaSideBarTabSection: DetailsTabSectionExtensionHook = (element:
5151
}
5252

5353
const resource = getResource(element);
54-
const verticalPodAutoscaler = getVerticalPodAutoscalerForResource(vpas, resource);
54+
const verticalPodAutoscalers = getVerticalPodAutoscalersForResource(vpas, resource);
5555

56-
const section = verticalPodAutoscaler ? (
57-
<TopologySideBarTabSection>
58-
<VPATabSection vpas={vpas} />
59-
</TopologySideBarTabSection>
60-
) : undefined;
56+
const section =
57+
verticalPodAutoscalers.length > 0 ? (
58+
<TopologySideBarTabSection>
59+
<VPATabSection vpas={verticalPodAutoscalers} />
60+
</TopologySideBarTabSection>
61+
) : undefined;
6162
return [section, true, undefined];
6263
};

0 commit comments

Comments
 (0)