Skip to content

Commit

Permalink
Update Linode and PG types
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Feb 26, 2024
1 parent 02bdf6d commit 0107d5d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 30 deletions.
8 changes: 2 additions & 6 deletions packages/api-v4/src/linodes/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Region } from '../regions';
import type { IPAddress, IPRange } from '../networking/types';
import type { SSHKey } from '../profile/types';
import type { PlacementGroup } from '../placement-groups/types';
import type { LinodePlacementGroup } from '../placement-groups/types';

export type Hypervisor = 'kvm' | 'zen';

Expand All @@ -24,11 +24,7 @@ export interface Linode {
ipv4: string[];
ipv6: string | null;
label: string;
// While the API returns an array of PlacementGroup objects for future proofing,
// we only support one PlacementGroup per Linode at this time, hence the tuple.
placement_groups:
| [Pick<PlacementGroup, 'id' | 'label' | 'affinity_type'>]
| [];
placement_group: LinodePlacementGroup;
type: string | null;
status: LinodeStatus;
updated: string;
Expand Down
17 changes: 12 additions & 5 deletions packages/api-v4/src/placement-groups/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ export interface PlacementGroup {
affinity_type: AffinityType;
is_compliant: boolean;
linode_ids: number[];
strict: boolean;
}

// The `strict` parameter specifies whether placement groups should be ignored when looking for a host.
// TODO VM_Placement: figure out the values for each create flow (create, clone, migrate etc)
export type CreatePlacementGroupPayload = Pick<
type PlacementGroupPayload = Pick<
PlacementGroup,
'label' | 'affinity_type' | 'region'
> & { strict: boolean };
'label' | 'affinity_type' | 'strict'
>;

export type LinodePlacementGroup = PlacementGroupPayload & {
id: number;
};

export type CreatePlacementGroupPayload = PlacementGroupPayload & {
region: Region['id'];
};

export type RenamePlacementGroupPayload = Pick<PlacementGroup, 'label'>;

Expand Down
28 changes: 24 additions & 4 deletions packages/manager/src/__data__/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export const linode1: Linode = {
ipv4: ['97.107.143.78', '98.107.143.78', '99.107.143.78'],
ipv6: '2600:3c03::f03c:91ff:fe0a:109a/64',
label: 'test',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'pg-1',
strict: true,
},
region: 'us-east',
specs: {
disk: 20480,
Expand Down Expand Up @@ -64,7 +69,12 @@ export const linode2: Linode = {
ipv4: ['97.107.143.49'],
ipv6: '2600:3c03::f03c:91ff:fe0a:0d7a/64',
label: 'another-test',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'pg-1',
strict: true,
},
region: 'us-east',
specs: {
disk: 30720,
Expand Down Expand Up @@ -104,7 +114,12 @@ export const linode3: Linode = {
ipv4: ['97.107.143.49'],
ipv6: '2600:3c03::f03c:91ff:fe0a:0d7a/64',
label: 'another-test',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'pg-1',
strict: true,
},
region: 'us-east',
specs: {
disk: 30720,
Expand Down Expand Up @@ -144,7 +159,12 @@ export const linode4: Linode = {
ipv4: ['97.107.143.49'],
ipv6: '2600:3c03::f03c:91ff:fe0a:0d7a/64',
label: 'another-test-eu',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'pg-1',
strict: true,
},
region: 'eu-west',
specs: {
disk: 30720,
Expand Down
15 changes: 5 additions & 10 deletions packages/manager/src/factories/linodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,11 @@ export const linodeFactory = Factory.Sync.makeFactory<Linode>({
ipv4: ['50.116.6.212', '192.168.203.1'],
ipv6: '2600:3c00::f03c:92ff:fee2:6c40/64',
label: Factory.each((i) => `linode-${i}`),
placement_groups: [
placementGroupFactory.build({
affinity_type: 'anti_affinity',
id: 1,
is_compliant: true,
label: 'test',
linode_ids: [1],
region: 'us-east',
}),
],
placement_group: placementGroupFactory.build({
affinity_type: 'anti_affinity',
id: 1,
label: 'pg-1',
}),
region: 'us-east',
specs: linodeSpecsFactory.build(),
status: 'running',
Expand Down
1 change: 1 addition & 0 deletions packages/manager/src/factories/placementGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const placementGroupFactory = Factory.Sync.makeFactory<PlacementGroup>({
label: Factory.each((id) => `pg-${id}`),
linode_ids: [0, 1, 2, 3, 5, 6, 7, 8, 43],
region: 'us-east',
strict: true,
});

export const createPlacementGroupPayloadFactory = Factory.Sync.makeFactory<CreatePlacementGroupPayload>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ const props: AddonsPanelProps = {
ipv4: ['45.56.75.98'],
ipv6: '2600:3c00::f03c:93ff:fe85:576d/128',
label: 'test_instance',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'test',
strict: true,
},
region: 'us-central',
specs: {
disk: 51200,
Expand Down Expand Up @@ -102,7 +107,12 @@ const props: AddonsPanelProps = {
ipv4: ['192.168.139.183', '139.144.17.202'],
ipv6: '2600:3c04::f03c:93ff:fe75:0612/128',
label: 'debian-ca-central',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'test',
strict: true,
},
region: 'ca-central',
specs: {
disk: 25600,
Expand Down Expand Up @@ -141,7 +151,12 @@ const props: AddonsPanelProps = {
ipv4: ['45.79.74.95'],
ipv6: '2600:3c01::f03c:93ff:fe75:e4f9/128',
label: 'almalinux-us-west',
placement_groups: [],
placement_group: {
affinity_type: 'anti_affinity',
id: 1,
label: 'test',
strict: true,
},
region: 'us-west',
specs: {
disk: 25600,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('LinodeRow', () => {
ipv6={linode.ipv6 || ''}
key={`linode-row-${1}`}
label={linode.label}
placement_groups={linode.placement_groups}
placement_group={linode.placement_group}
region={linode.region}
specs={linode.specs}
status={linode.status}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ListView = (props: RenderLinodesProps) => {
ipv6={linode.ipv6 || ''}
key={`linode-row-${idx}`}
label={linode.label}
placement_groups={linode.placement_groups}
placement_group={linode.placement_group}
region={linode.region}
specs={linode.specs}
status={linode.status}
Expand Down

0 comments on commit 0107d5d

Please sign in to comment.