Skip to content

[Spot] Handle spot parameters in VPC instance creation #533

@meomnzak

Description

@meomnzak

Description

Parent: #501
Design Doc: #523
Depends on: #529, #532


Summary

Create() in the VPC instance provider currently assumes on-demand capacity.

Spot support requires:

  • resolving capacity type from the NodeClaim
  • setting VPC spot-specific API fields when applicable
  • labelling the resulting node dynamically

Goal

Update:

pkg/providers/vpc/instance/provider.go

to support spot-aware instance creation.


Required Changes

1. Resolve capacity type

Early in Create(), call:

capacityType := capacitytype.ResolveCapacityType(nodeClaim, instanceTypes)

2. Update availability policy

Current code:

instancePrototype.AvailabilityPolicy = &vpcv1.InstanceAvailabilityPolicyPrototype{
    HostFailure: &[]string{"restart"}[0],
}

Replace with capacity-type handling:

if capacityType == karpv1.CapacityTypeSpot {
    instancePrototype.Availability = &vpcv1.InstanceAvailabilityPrototype{
        Class: core.StringPtr(karpv1.CapacityTypeSpot),
    }
    instancePrototype.AvailabilityPolicy = &vpcv1.InstanceAvailabilityPolicyPrototype{
        Preemption: core.StringPtr("stop"),
    }
    instancePrototype.ReservationAffinity = &vpcv1.InstanceReservationAffinityPrototype{
        Policy: core.StringPtr("disabled"),
    }
} else {
    // Preserve existing on-demand behavior
    instancePrototype.AvailabilityPolicy = &vpcv1.InstanceAvailabilityPolicyPrototype{
        HostFailure: &[]string{"restart"}[0],
    }
}

Notes:

  • Preemption: "stop" ensures an unambiguous stopped_by_preemption signal.
  • reservation_affinity.policy = "disabled" is required for spot.

3. Set capacity-type label dynamically

Current code:

karpv1.CapacityTypeLabelKey: "on-demand",

Replace with:

karpv1.CapacityTypeLabelKey: capacityType,

Acceptance Criteria

  • Create() resolves capacity type using helper
  • Spot-specific VPC fields set when capacity type is spot
  • Capacity-type label set dynamically
  • Add Unit tests

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions