Skip to content

Commit d12d5a9

Browse files
upcoming: [M3-9513] – Update endpoints, types, and validation for VPC Linode instances (#11942)
1 parent 1e33017 commit d12d5a9

16 files changed

Lines changed: 315 additions & 155 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@linode/api-v4": Upcoming Features
3+
---
4+
5+
Add ipv6 field to VPCInterfaceData and update ConfigInterfaceIPv6 type ([#11942](https://github.com/linode/manager/pull/11942))

packages/api-v4/src/linodes/types.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,23 @@ export type LinodeStatus =
179179
// ----------------------------------------------------------------------
180180
export type InterfacePurpose = 'public' | 'vlan' | 'vpc';
181181

182+
// IPv4
182183
export interface ConfigInterfaceIPv4 {
183184
vpc?: string | null;
184185
nat_1_1?: string | null;
185186
}
186187

188+
export interface IPv6SLAAC {
189+
range: string;
190+
address: string;
191+
}
192+
187193
export interface ConfigInterfaceIPv6 {
188-
vpc?: string | null;
194+
slaac: IPv6SLAAC[];
195+
ranges: {
196+
range?: string;
197+
}[];
198+
is_public: boolean;
189199
}
190200

191201
// The legacy interface type - for Configuration Profile Interfaces
@@ -286,17 +296,26 @@ export interface LinodeInterfaces {
286296
interfaces: LinodeInterface[];
287297
}
288298

299+
export interface LinodeInterfaceIPv6 {
300+
slaac: IPv6SLAAC[];
301+
ranges: {
302+
range: string;
303+
}[];
304+
is_public: boolean;
305+
}
306+
289307
export interface VPCInterfaceData {
290308
vpc_id: number;
291309
subnet_id: number;
292-
ipv4: {
310+
ipv4?: {
293311
addresses: {
294312
address: string;
295313
primary: boolean;
296314
nat_1_1_address?: string;
297315
}[];
298316
ranges: { range: string }[];
299317
};
318+
ipv6?: LinodeInterfaceIPv6;
300319
}
301320

302321
export interface PublicInterfaceData {

packages/manager/src/features/Linodes/LinodeCreate/Networking/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type {
77
} from '@linode/api-v4';
88

99
/**
10-
* Extend the API's new interface type with a vpc_id so that state managment is easier for us
11-
* The new endpoint only uses subnet_id and I guess it dervies the VPC from that?
10+
* Extend the API's new interface type with a vpc_id so that state management is easier for us
11+
* The new endpoint only uses subnet_id and I guess it derives the VPC from that?
1212
*/
1313
interface VPC extends NonNullable<CreateLinodeInterfacePayload['vpc']> {
1414
vpc_id: number;

packages/manager/src/features/Linodes/LinodeCreate/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { LinodeCreateFormValues } from './utilities';
1010
import type { ObjectSchema } from 'yup';
1111

1212
/**
13-
* Extends pure `CreateLinodeSchema` because the Lindoe Create form
13+
* Extends pure `CreateLinodeSchema` because the Linode Create form
1414
* has extra fields that we want to validate.
1515
* In theory, this schema should align with the `LinodeCreateFormValues` type.
1616
*/

packages/manager/src/features/Linodes/LinodeCreate/utilities.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ export interface LinodeCreateFormValues extends CreateLinodeRequest {
295295
*/
296296
hasSignedEUAgreement?: boolean;
297297
/**
298-
* Override the interfaces type of the Linode Create flow so it only has Legacy Interfaces
298+
* Override the interfaces type of the Linode Create flow so it only has Legacy Interfaces.
299+
* `ipv4` and `ipv6` fields are only accepted for VPC interfaces and the omit type avoids
300+
* `CreateLinodeSchema` type errors (see https://github.com/linode/manager/pull/11942#discussion_r2043029481)
299301
*/
300-
interfaces: InterfacePayload[];
302+
interfaces: InterfacePayload[] | Omit<InterfacePayload, 'ipv4' | 'ipv6'>[];
301303
/**
302304
* The currently selected Linode (used for the Backups and Clone tabs)
303305
*/

packages/manager/src/features/Linodes/LinodesDetail/LinodeConfigs/UpgradeInterfaces/DialogContents/SuccessDialogContent.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ type VPCInterfaceInfo = VPCInterfaceData &
108108

109109
const VPCInterfaceInfo = (props: VPCInterfaceInfo) => {
110110
const { default_route, ipv4, subnet_id, vpc_id } = props;
111-
const { addresses, ranges } = ipv4;
111+
const { addresses, ranges } = ipv4 || {};
112112

113-
const primaryAddress = addresses.find((address) => address.primary === true);
113+
const primaryAddress = addresses?.find((address) => address.primary === true);
114114

115115
return (
116116
<>
@@ -127,13 +127,13 @@ const VPCInterfaceInfo = (props: VPCInterfaceInfo) => {
127127
<Typography>VPC ID: {vpc_id}</Typography>
128128
<Typography>Subnet ID: {subnet_id}</Typography>
129129
<Typography>
130-
Addresses: {addresses.map((address) => address.address).join(', ')}
130+
Addresses: {addresses?.map((address) => address.address).join(', ')}
131131
</Typography>
132132
{primaryAddress && (
133133
<Typography>Primary Address: {primaryAddress.address}</Typography>
134134
)}
135-
{ranges.length > 0 && (
136-
<Typography>Routed Ranges: {ranges.join(', ')}</Typography>
135+
{ranges?.length && ranges?.length > 0 && (
136+
<Typography>Routed Ranges: {ranges?.join(', ')}</Typography>
137137
)}
138138
</Stack>
139139
</>

packages/manager/src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/EditInterfaceDrawer/VPCInterface/VPCIPv4Address.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const VPCIPv4Address = (props: Props) => {
5151
field.onChange(
5252
checked
5353
? 'auto'
54-
: (linodeInterface.vpc?.ipv4.addresses[index].address ??
54+
: (linodeInterface.vpc?.ipv4?.addresses[index].address ??
5555
'')
5656
)
5757
}

packages/manager/src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/InterfaceDetailsDrawer/VPCInterfaceDetailsContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const VPCInterfaceDetailsContent = (props: VPCInterfaceData) => {
1515

1616
const ipv4ToTypography = (
1717
<>
18-
{ipv4.addresses.map((address) =>
18+
{ipv4?.addresses.map((address) =>
1919
address.nat_1_1_address ? (
2020
<Stack key={address.address}>
2121
<MaskableText
@@ -35,7 +35,7 @@ export const VPCInterfaceDetailsContent = (props: VPCInterfaceData) => {
3535
/>
3636
)
3737
)}
38-
{ipv4.ranges.map((range) => (
38+
{ipv4?.ranges.map((range) => (
3939
<MaskableText
4040
isToggleable
4141
key={range.range}

packages/manager/src/features/Linodes/LinodesDetail/LinodeNetworking/LinodeInterfaces/LinodeInterfaceIPs.utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function getLinodeInterfaceIPs(linodeInterface: LinodeInterface) {
3737
}
3838
}
3939

40-
if (linodeInterface.vpc) {
40+
if (linodeInterface.vpc && linodeInterface.vpc.ipv4) {
4141
// VPC IPv4s
4242
for (const address of linodeInterface.vpc.ipv4.addresses) {
4343
if (address.primary) {
@@ -52,6 +52,7 @@ export function getLinodeInterfaceIPs(linodeInterface: LinodeInterface) {
5252
}
5353
}
5454
}
55+
5556
// VPC IPv4 Ranges
5657
for (const address of linodeInterface.vpc.ipv4.ranges) {
5758
ips.push(address.range);

packages/manager/src/features/VPCs/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const hasUnrecommendedConfigurationLinodeInterface = (
3030
) => {
3131
return (
3232
isInterfaceActive &&
33-
linodeInterface?.vpc?.ipv4.addresses.some(
33+
linodeInterface?.vpc?.ipv4?.addresses.some(
3434
(address) => address.nat_1_1_address
3535
) &&
3636
!linodeInterface?.default_route.ipv4
@@ -83,10 +83,10 @@ export const getIsVPCLKEEnterpriseCluster = (vpc: VPC) =>
8383
/^lke\d+/i.test(vpc.label);
8484

8585
export const getLinodeInterfacePrimaryIPv4 = (iface: LinodeInterface) =>
86-
iface.vpc?.ipv4.addresses.find((address) => address.primary)?.address;
86+
iface.vpc?.ipv4?.addresses.find((address) => address.primary)?.address;
8787

8888
export const getLinodeInterfaceRanges = (iface: LinodeInterface) =>
89-
iface.vpc?.ipv4.ranges.map((range) => range.range);
89+
iface.vpc?.ipv4?.ranges.map((range) => range.range);
9090

9191
// TODO: update this when converting to react-hook-form
9292
// gets the VPC Interface payload depending on whether we want a Linode Interface or Config Interface payload

0 commit comments

Comments
 (0)