From 24fbb6f3cfd830515b34fda25a5f1b2727ffaa0b Mon Sep 17 00:00:00 2001 From: Alec Fong Date: Mon, 8 Dec 2025 16:27:36 -0800 Subject: [PATCH 1/3] fix instance type id --- v1/providers/nebius/instance.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/v1/providers/nebius/instance.go b/v1/providers/nebius/instance.go index 5047341..826452c 100644 --- a/v1/providers/nebius/instance.go +++ b/v1/providers/nebius/instance.go @@ -341,8 +341,8 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance * CloudID: instanceID, Location: location, CreatedAt: createdAt, - InstanceType: instanceTypeID, // Full instance type ID (e.g., "gpu-h100-sxm.8gpu-128vcpu-1600gb") - InstanceTypeID: v1.InstanceTypeID(instanceTypeID), // Same as InstanceType - required for dev-plane lookup + InstanceType: instanceTypeID, // Full instance type ID (e.g., "gpu-h100-sxm.8gpu-128vcpu-1600gb") + InstanceTypeID: v1.InstanceTypeID(getInstanceTypeID(instanceTypeID, location)), ImageID: imageFamily, DiskSize: units.Base2Bytes(diskSize), DiskSizeBytes: v1.NewBytes(v1.BytesValue(diskSize), v1.Byte), // diskSize is already in bytes from getBootDiskSize @@ -358,6 +358,10 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance * }, nil } +func getInstanceTypeID(instanceType string, region string) string { + return fmt.Sprintf("%v-%v", instanceType, region) +} + // waitForInstanceRunning polls the instance until it reaches RUNNING state or fails // This prevents orphaned resources when instances fail after the create API call succeeds func (c *NebiusClient) waitForInstanceRunning(ctx context.Context, instanceID v1.CloudProviderInstanceID, refID string, timeout time.Duration) (*v1.Instance, error) { From ccaac598908b6c315f709c7f59f2f480b4c06271 Mon Sep 17 00:00:00 2001 From: Alec Fong Date: Mon, 8 Dec 2025 16:38:56 -0800 Subject: [PATCH 2/3] use proper constructor and improve tests --- internal/validation/suite.go | 4 +++- v1/instance.go | 5 ++++- v1/providers/nebius/instance.go | 11 ++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/validation/suite.go b/internal/validation/suite.go index dfcf2f9..c4e04e1 100644 --- a/internal/validation/suite.go +++ b/internal/validation/suite.go @@ -79,15 +79,17 @@ func RunInstanceLifecycleValidation(t *testing.T, config ProviderConfig) { t.Run("ValidateCreateInstance", func(t *testing.T) { attrs := v1.CreateInstanceAttrs{} + selectedType := v1.InstanceType{} for _, typ := range types { if typ.IsAvailable { attrs.InstanceType = typ.Type attrs.Location = typ.Location attrs.PublicKey = ssh.GetTestPublicKey() + selectedType = typ break } } - instance, err := v1.ValidateCreateInstance(ctx, client, attrs) + instance, err := v1.ValidateCreateInstance(ctx, client, attrs, selectedType) if err != nil { t.Fatalf("ValidateCreateInstance failed: %v", err) } diff --git a/v1/instance.go b/v1/instance.go index 82f4afb..003e052 100644 --- a/v1/instance.go +++ b/v1/instance.go @@ -28,7 +28,7 @@ type CloudCreateTerminateInstance interface { CloudInstanceReader } -func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInstance, attrs CreateInstanceAttrs) (*Instance, error) { +func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInstance, attrs CreateInstanceAttrs, selectedType InstanceType) (*Instance, error) { t0 := time.Now().Add(-time.Minute) attrs.RefID = uuid.New().String() name, err := makeDebuggableName(attrs.Name) @@ -67,6 +67,9 @@ func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInst if attrs.InstanceType != "" && attrs.InstanceType != i.InstanceType { validationErr = errors.Join(validationErr, fmt.Errorf("instanceType mismatch: %s != %s", attrs.InstanceType, i.InstanceType)) } + if selectedType.ID != "" && selectedType.ID != i.InstanceTypeID { + validationErr = errors.Join(validationErr, fmt.Errorf("instanceTypeID mismatch: %s != %s", selectedType.ID, i.InstanceTypeID)) + } return i, validationErr } diff --git a/v1/providers/nebius/instance.go b/v1/providers/nebius/instance.go index 826452c..6593313 100644 --- a/v1/providers/nebius/instance.go +++ b/v1/providers/nebius/instance.go @@ -334,7 +334,7 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance * sshUser = "admin" } - return &v1.Instance{ + inst := &v1.Instance{ RefID: refID, CloudCredRefID: c.refID, Name: instance.Metadata.Name, @@ -342,7 +342,6 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance * Location: location, CreatedAt: createdAt, InstanceType: instanceTypeID, // Full instance type ID (e.g., "gpu-h100-sxm.8gpu-128vcpu-1600gb") - InstanceTypeID: v1.InstanceTypeID(getInstanceTypeID(instanceTypeID, location)), ImageID: imageFamily, DiskSize: units.Base2Bytes(diskSize), DiskSizeBytes: v1.NewBytes(v1.BytesValue(diskSize), v1.Byte), // diskSize is already in bytes from getBootDiskSize @@ -355,11 +354,9 @@ func (c *NebiusClient) convertNebiusInstanceToV1(ctx context.Context, instance * Hostname: hostname, SSHUser: sshUser, SSHPort: 22, // Standard SSH port - }, nil -} - -func getInstanceTypeID(instanceType string, region string) string { - return fmt.Sprintf("%v-%v", instanceType, region) + } + inst.InstanceTypeID = v1.MakeGenericInstanceTypeIDFromInstance(*inst) + return inst, nil } // waitForInstanceRunning polls the instance until it reaches RUNNING state or fails From fbe701addb587e722a9931d13e059ac7ffc3fefd Mon Sep 17 00:00:00 2001 From: Alec Fong Date: Mon, 8 Dec 2025 16:41:48 -0800 Subject: [PATCH 3/3] ignore lint --- v1/instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v1/instance.go b/v1/instance.go index 003e052..d56a5e0 100644 --- a/v1/instance.go +++ b/v1/instance.go @@ -28,7 +28,7 @@ type CloudCreateTerminateInstance interface { CloudInstanceReader } -func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInstance, attrs CreateInstanceAttrs, selectedType InstanceType) (*Instance, error) { +func ValidateCreateInstance(ctx context.Context, client CloudCreateTerminateInstance, attrs CreateInstanceAttrs, selectedType InstanceType) (*Instance, error) { //nolint:gocyclo // ok t0 := time.Now().Add(-time.Minute) attrs.RefID = uuid.New().String() name, err := makeDebuggableName(attrs.Name)