Skip to content

Commit fccfce2

Browse files
Merge pull request #324 from PierreBeucher/gcp-provisioning-enhancements
Gcp provisioning enhancements
2 parents d2531a7 + 71093b0 commit fccfce2

12 files changed

Lines changed: 1237 additions & 329 deletions

File tree

src/providers/gcp/cli.ts

Lines changed: 504 additions & 259 deletions
Large diffs are not rendered by default.

src/providers/gcp/const.ts

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Machine families to show in the machine type prompt (gaming-oriented)
2+
export const MACHINE_TYPE_FAMILIES_GAMING = ["n1", "g2"] as const;
3+
4+
// User-facing descriptions for GCP machine type families
5+
export const MACHINE_TYPE_FAMILY_DESCRIPTIONS: Record<string, string> = {
6+
n1: 'N1: General purpose, good price/performance for most workloads (supports T4, P4, P100, V100 GPUs)',
7+
g2: 'G2: Newer generation, optimized for graphics and gaming (supports L4 GPU)',
8+
a2: 'A2: High performance, AI/ML workloads (supports A100 GPUs)',
9+
c3: 'C3: Compute-optimized, high CPU performance',
10+
c3d: 'C3D: Compute-optimized with local NVMe SSD',
11+
a3: 'A3: AI-optimized, very high performance',
12+
h3: 'H3: High memory, high performance',
13+
};
14+
15+
// GPU descriptions for acceleratorType prompt
16+
export const GPU_DESCRIPTIONS: Record<string, { label: string, type: string }> = {
17+
'nvidia-tesla-t4': { label: 'NVIDIA T4 (great for cloud gaming, 16GB VRAM)', type: 'T4' },
18+
'nvidia-l4': { label: 'NVIDIA L4 (new generation, 24GB VRAM, very performant for streaming)', type: 'L4' },
19+
'nvidia-a10g': { label: 'NVIDIA A10G (high-end, 24GB VRAM, advanced AI and gaming)', type: 'A10G' },
20+
'nvidia-p4': { label: 'NVIDIA P4 (entry-level, 8GB VRAM, sufficient for light games)', type: 'P4' },
21+
'nvidia-p100': { label: 'NVIDIA P100 (16GB VRAM, compute and advanced gaming)', type: 'P100' },
22+
'nvidia-v100': { label: 'NVIDIA V100 (16/32GB VRAM, very performant, overkill for gaming)', type: 'V100' },
23+
'nvidia-a100-40gb': { label: 'NVIDIA A100 40GB (AI/ML, compute, gaming)', type: 'A100-40GB' },
24+
'nvidia-a100-80gb': { label: 'NVIDIA A100 80GB (AI/ML, compute, gaming)', type: 'A100-80GB' },
25+
};
26+
27+
// Families eligible for TIER_1 (egress bandwidth)
28+
export const TIER1_FAMILIES = ["c3", "c3d", "a3", "h3"] as const;
29+
30+
// GCP machine type family → compatible acceleratorTypes (GPUs)
31+
export const MACHINE_GPU_COMPAT: Record<string, string[]> = {
32+
n1: ['nvidia-tesla-t4'],
33+
g2: ['nvidia-l4'],
34+
a2: ['nvidia-a100-40gb', 'nvidia-a100-80gb'],
35+
// Add more families if needed
36+
};
37+
38+
// Named constants for better readability
39+
export const DISK_TYPE_STANDARD = 'pd-standard';
40+
export const DISK_TYPE_BALANCED = 'pd-balanced';
41+
export const DISK_TYPE_SSD = 'pd-ssd';
42+
43+
export const NETWORK_TIER_STANDARD = 'STANDARD';
44+
export const NETWORK_TIER_PREMIUM = 'PREMIUM';
45+
46+
export const NIC_TYPE_AUTO = 'auto';
47+
export const NIC_TYPE_GVNIC = 'GVNIC';
48+
export const NIC_TYPE_VIRTIO_NET = 'VIRTIO_NET';
49+
50+
// Central GCP constants for allowed values
51+
export const DISK_TYPES: string[] = [
52+
DISK_TYPE_STANDARD,
53+
DISK_TYPE_BALANCED,
54+
DISK_TYPE_SSD,
55+
] as const;
56+
57+
export const NETWORK_TIERS: string[] = [
58+
NETWORK_TIER_STANDARD,
59+
NETWORK_TIER_PREMIUM,
60+
] as const;
61+
62+
export const NIC_TYPES: string[] = [
63+
NIC_TYPE_AUTO,
64+
NIC_TYPE_GVNIC,
65+
NIC_TYPE_VIRTIO_NET,
66+
] as const;
67+
68+
// Families eligible for TIER_1 (egress bandwidth) - using named constant
69+
export const TIER1_NIC = NIC_TYPE_GVNIC;
70+
71+
export type DiskType = typeof DISK_TYPES[number];
72+
export type NetworkTier = typeof NETWORK_TIERS[number];
73+
export type NicType = typeof NIC_TYPES[number];
74+
75+
// Default values for prompts (explicit names)
76+
export const DEFAULT_DISK_TYPE = DISK_TYPE_BALANCED;
77+
export const DEFAULT_NETWORK_TIER = NETWORK_TIER_STANDARD;
78+
export const DEFAULT_NIC_TYPE = NIC_TYPE_AUTO;
79+
80+
// User-facing descriptions for disk, network tier, and NIC types
81+
export const DISK_TYPE_DESCRIPTIONS: Record<string, string> = {
82+
[DISK_TYPE_STANDARD]: 'Standard (cheapest, slowest)',
83+
[DISK_TYPE_BALANCED]: 'Balanced (good compromise)',
84+
[DISK_TYPE_SSD]: 'SSD (best performance, highest cost)',
85+
};
86+
87+
export const NETWORK_TIER_DESCRIPTIONS: Record<string, string> = {
88+
[NETWORK_TIER_STANDARD]: 'Standard (higher latency, lower cost, includes 200 GiB/month free)',
89+
[NETWORK_TIER_PREMIUM]: 'Premium (lower latency, more expensive)',
90+
};
91+
92+
export const NIC_TYPE_DESCRIPTIONS: Record<string, string> = {
93+
[NIC_TYPE_AUTO]: 'Auto (let GCP choose, recommended)',
94+
[NIC_TYPE_GVNIC]: 'GVNIC (high throughput / low latency, supported on some VMs)',
95+
[NIC_TYPE_VIRTIO_NET]: 'Virtio Net (legacy, broad compatibility)',
96+
};
97+
98+
// Region prefix -> user-friendly label used in the continent/group prompt
99+
// Note: Prefixes are derived from region names (e.g. "europe-west4" -> "europe-").
100+
// If a prefix is not known here, the UI will show "<UNKNOWN>".
101+
export const REGION_PREFIX_LABELS: Record<string, string> = {
102+
'europe-': 'Europe',
103+
'us-': 'United States / Canada',
104+
'asia-': 'Asia / Pacific',
105+
'southamerica-': 'South America',
106+
'me-': 'Middle East',
107+
'africa-': 'Africa',
108+
'australia-': 'Australia',
109+
'northamerica-': 'North America',
110+
};
111+
112+
// Region name -> Country/Location label for display in region selection.
113+
// Best-effort mapping based on public GCP region locations. Not exhaustive.
114+
// If a region is not listed here, we won't display a country label for it.
115+
export const REGION_COUNTRY_BY_REGION: Record<string, string> = {
116+
// Europe
117+
'europe-west1': 'Belgium',
118+
'europe-west2': 'London, United Kingdom',
119+
'europe-west3': 'Frankfurt, Germany',
120+
'europe-west4': 'Netherlands',
121+
'europe-west6': 'Zurich, Switzerland',
122+
'europe-west8': 'Milan, Italy',
123+
'europe-west9': 'Paris, France',
124+
'europe-west10': 'Berlin, Germany',
125+
'europe-west12': 'Turin, Italy',
126+
'europe-north1': 'Finland',
127+
'europe-central2': 'Warsaw, Poland',
128+
129+
// North America
130+
'us-central1': 'Iowa, USA',
131+
'us-east1': 'South Carolina, USA',
132+
'us-east4': 'Northern Virginia, USA',
133+
'us-west1': 'Oregon, USA',
134+
'us-west2': 'Los Angeles, USA',
135+
'us-west3': 'Salt Lake City, USA',
136+
'us-west4': 'Las Vegas, USA',
137+
'northamerica-northeast1': 'Montréal, Canada',
138+
'northamerica-northeast2': 'Toronto, Canada',
139+
140+
// Asia / Pacific
141+
'asia-east1': 'Taiwan',
142+
'asia-northeast1': 'Tokyo, Japan',
143+
'asia-northeast2': 'Osaka, Japan',
144+
'asia-northeast3': 'Seoul, South Korea',
145+
'asia-southeast1': 'Singapore',
146+
'asia-southeast2': 'Jakarta, Indonesia',
147+
'asia-south1': 'Mumbai, India',
148+
'asia-south2': 'Delhi, India',
149+
'asia-east2': 'Hong Kong',
150+
151+
// Australia
152+
'australia-southeast1': 'Sydney, Australia',
153+
'australia-southeast2': 'Melbourne, Australia',
154+
155+
// South America
156+
'southamerica-east1': 'São Paulo, Brazil',
157+
158+
// Middle East
159+
'me-west1': 'Tel Aviv, Israel',
160+
'me-central1': 'Doha, Qatar',
161+
162+
// Africa
163+
'africa-south1': 'Johannesburg, South Africa',
164+
};

src/providers/gcp/provisioner.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AbstractInstanceProvisioner, InstanceProvisionerArgs, ProvisionerAction
33
import { GcpPulumiClient, PulumiStackConfigGcp } from './pulumi';
44
import { GcpClient } from './sdk-client';
55
import { GcpProvisionInputV1, GcpProvisionOutputV1} from './state';
6+
import { NIC_TYPE_AUTO } from './const';
67

78
export type GcpProvisionerArgs = InstanceProvisionerArgs<GcpProvisionInputV1, GcpProvisionOutputV1>
89

@@ -39,6 +40,17 @@ export class GcpProvisioner extends AbstractInstanceProvisioner<GcpProvisionInpu
3940
region: this.args.provisionInput.region,
4041
zone: this.args.provisionInput.zone,
4142
rootDiskSize: this.args.provisionInput.diskSize,
43+
// diskType: pd-standard (cheapest, slowest), pd-balanced (good compromise), pd-ssd (best performance, highest cost)
44+
// See: https://cloud.google.com/compute/docs/disks#disk-types
45+
diskType: this.args.provisionInput.diskType, // User selects: pd-standard, pd-balanced, pd-ssd
46+
// networkTier: STANDARD (cheaper, higher latency), PREMIUM (better, lower latency, more expensive)
47+
// See: https://cloud.google.com/network-tiers/docs/overview
48+
networkTier: this.args.provisionInput.networkTier, // User selects: STANDARD, PREMIUM
49+
// nicType: undefined (auto, let GCP choose), GVNIC (best performance, lowest latency, only supported on some machine types), VIRTIO_NET (legacy, compatible)
50+
// See: https://cloud.google.com/compute/docs/network-interfaces#nic-types
51+
// Default is undefined (auto), which lets GCP select the best available NIC type.
52+
// If user selects 'auto', map to undefined so GCP auto-selects NIC type.
53+
nicType: this.args.provisionInput.nicType === NIC_TYPE_AUTO ? undefined : this.args.provisionInput.nicType,
4254
publicSshKeyContent: sshPublicKeyContent,
4355
useSpot: this.args.provisionInput.useSpot,
4456
costAlert: this.args.provisionInput.costAlert ?? undefined,

0 commit comments

Comments
 (0)