Skip to content

Commit 330ec56

Browse files
fix(pci-kubernetes): mks create nodepool pricing type error
Signed-off-by: Joakim Eriksson <75730728+ErikssonJoakim@users.noreply.github.com>
1 parent 66a6cb5 commit 330ec56

3 files changed

Lines changed: 38 additions & 31 deletions

File tree

packages/manager/apps/pci-kubernetes/src/api/data/flavors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export type TFlavor = {
3535
osType: string;
3636
outboundBandwidth?: number;
3737
planCodes: {
38-
hourly?: string;
39-
monthly?: string;
38+
hourly: string | null;
39+
monthly: string | null;
4040
};
4141
quota: number;
4242
ram: number;

packages/manager/apps/pci-kubernetes/src/components/flavor-selector/FlavorTile.component.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import clsx from 'clsx';
1+
import { clsx } from 'clsx';
22
import { useTranslation } from 'react-i18next';
33

44
import {
@@ -35,7 +35,7 @@ export interface FlavorTileProps {
3535
};
3636
flavorCompatibility: Record<DeploymentMode, boolean>;
3737
flavorPrice: {
38-
hourly: number;
38+
hourly?: number;
3939
monthly?: number;
4040
};
4141
isNewFlavor: boolean;
@@ -187,13 +187,15 @@ export function FlavorTile({
187187
})}
188188
</OsdsText>
189189
)}
190-
<OsdsText
191-
level={ODS_THEME_TYPOGRAPHY_LEVEL.body}
192-
size={ODS_THEME_TYPOGRAPHY_SIZE._100}
193-
color={ODS_THEME_COLOR_INTENT.text}
194-
>
195-
{getFormattedHourlyCatalogPrice(flavorPrice.hourly)}
196-
</OsdsText>
190+
{flavorPrice.hourly !== undefined && (
191+
<OsdsText
192+
level={ODS_THEME_TYPOGRAPHY_LEVEL.body}
193+
size={ODS_THEME_TYPOGRAPHY_SIZE._100}
194+
color={ODS_THEME_COLOR_INTENT.text}
195+
>
196+
{getFormattedHourlyCatalogPrice(flavorPrice.hourly)}
197+
</OsdsText>
198+
)}
197199
{!hasEnoughQuota && (
198200
<>
199201
<hr className={separatorClass} />

packages/manager/apps/pci-kubernetes/src/hooks/useFlavors.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,29 @@ export const useKubeFlavors = (projectId: string, region: string) =>
8484
enabled: !!projectId && !!region,
8585
});
8686

87-
export const hasEnoughQuota = (flavor: TFlavor, quota: TQuota) => {
87+
export const hasEnoughQuota = (flavor: Partial<TFlavor>, quota: TQuota) => {
8888
if (!quota?.instance) return true;
8989
const { instance } = quota;
9090
if (instance.usedInstances + 1 > (instance.maxInstances || 0)) return false;
91-
if (instance.usedRAM + flavor.ram > (instance.maxRam || 0)) return false;
92-
if (instance.usedCores + flavor.vcpus > (instance.maxCores || 0)) return false;
91+
if (instance.usedRAM + (flavor.ram ?? 0) > (instance.maxRam || 0)) return false;
92+
if (instance.usedCores + (flavor.vcpus ?? 0) > (instance.maxCores || 0)) return false;
9393
return true;
9494
};
9595

9696
export const useMergedKubeFlavors = (projectId: string, region: string | null) => {
97-
const { data: flavors, isPending: isFlavorsPending } = useFlavors(projectId, region);
98-
const { data: kubeFlavors, isPending: isKubeFlavorsPending } = useKubeFlavors(projectId, region);
97+
const { data: flavors, isPending: isFlavorsPending } = useFlavors(projectId, region ?? '');
98+
const { data: kubeFlavors, isPending: isKubeFlavorsPending } = useKubeFlavors(
99+
projectId,
100+
region ?? '',
101+
);
99102
const { data: catalog, isPending: isCatalogPending } = useCatalog();
100103
const { data: availability, isPending: isAvailabilityPending } =
101104
useProductAvailability(projectId);
102105

103-
const { data: quota, isPending: isQuotaPending } = useProjectQuotaByRegion(projectId, region);
106+
const { data: quota, isPending: isQuotaPending } = useProjectQuotaByRegion(
107+
projectId,
108+
region ?? '',
109+
);
104110

105111
const isPending =
106112
isFlavorsPending ||
@@ -118,11 +124,12 @@ export const useMergedKubeFlavors = (projectId: string, region: string | null) =
118124
}));
119125
return result
120126
.map((flavor) => {
121-
const addon = catalog.addons.find((_addon) => _addon.planCode === flavor.planCodes.hourly);
127+
const addon = catalog.addons.find((_addon) => _addon.planCode === flavor.planCodes?.hourly);
122128
const addonMonthly = catalog.addons.find(
123-
(_addon) => _addon.planCode === flavor.planCodes.monthly,
129+
(_addon) => _addon.planCode === flavor.planCodes?.monthly,
124130
);
125-
const plan = availability.plans?.find((_plan) => _plan.code === flavor.planCodes.hourly);
131+
const plan = availability.plans?.find((_plan) => _plan.code === flavor.planCodes?.hourly);
132+
const planRegionTypes = new Set(plan?.regions?.map((_region) => _region.type));
126133

127134
// Bugfix: Issue with selecting the correct monthly price in the US
128135
// -----------------------------------------------------------
@@ -144,27 +151,25 @@ export const useMergedKubeFlavors = (projectId: string, region: string | null) =
144151
...flavor,
145152
blobs: addon?.blobs,
146153
compatibility: Object.values(DeploymentMode).reduce(
147-
(acc, value) => ({
148-
...acc,
149-
[value]: plan?.regions?.some((_region) => _region.type === value),
150-
}),
154+
(acc, value) => ({ ...acc, [value]: planRegionTypes.has(value) }),
151155
{},
152156
) as Record<DeploymentMode, boolean>,
153157

154158
pricingsHourly: addon?.pricings?.[0],
155159
pricingsMonthly: priceMonthly,
156160
isNew: addon?.blobs.tags.includes('is_new'),
157-
flavorCategory: FLAVOR_CATEGORIES.find((cat) => cat.pattern.test(flavor.type))?.category,
158-
isFlex: /flex$/.test(flavor.name),
159-
isLegacy: /eg|sp|hg|vps-ssd/.test(flavor.name),
161+
flavorCategory: FLAVOR_CATEGORIES.find((cat) => cat.pattern.test(flavor.type ?? ''))
162+
?.category,
163+
isFlex: /flex$/.test(flavor.name ?? ''),
164+
isLegacy: /eg|sp|hg|vps-ssd/.test(flavor.name ?? ''),
160165
hasEnoughQuota: hasEnoughQuota(flavor, quota),
161166
};
162167
})
163168
.sort((a, b) => {
164-
const aGroup = Number((a.name.match(/[0-9]+/) || [])[0]);
165-
const bGroup = Number((b.name.match(/[0-9]+/) || [])[0]);
166-
const aRank = Number((a.name.match(/-([^-]+)$/) || [])[1]);
167-
const bRank = Number((b.name.match(/-([^-]+)$/) || [])[1]);
169+
const aGroup = Number((a.name?.match(/[0-9]+/) || [])[0]);
170+
const bGroup = Number((b.name?.match(/[0-9]+/) || [])[0]);
171+
const aRank = Number((a.name?.match(/-([^-]+)$/) || [])[1]);
172+
const bRank = Number((b.name?.match(/-([^-]+)$/) || [])[1]);
168173
if (aGroup === bGroup) return aRank - bRank;
169174
return bGroup - aGroup;
170175
});

0 commit comments

Comments
 (0)