Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/builder/vm/lcow/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func BuildSandboxConfig(
return nil, nil, fmt.Errorf("failed to parse CPU parameters: %w", err)
}

// Parse resource partition ID.
resourcePartitionID, err := parseResourcePartitionOptions(ctx, spec.Annotations, cpuConfig)
if err != nil {
return nil, nil, fmt.Errorf("failed to parse resource partition parameters: %w", err)
}

// Parse memory configuration.
memoryConfig, err := parseMemoryOptions(ctx, opts, spec.Annotations, sandboxOptions.FullyPhysicallyBacked)
if err != nil {
Expand Down Expand Up @@ -252,7 +258,8 @@ func BuildSandboxConfig(
Processor: cpuConfig,
Numa: numa,
},
StorageQoS: storageQOSConfig,
StorageQoS: storageQOSConfig,
ResourcePartitionId: resourcePartitionID,
Devices: &hcsschema.Devices{
Scsi: scsiCtrl,
VirtualPci: vpciDevices,
Expand Down
7 changes: 6 additions & 1 deletion internal/builder/vm/lcow/specs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,12 @@ func TestBuildSandboxConfig(t *testing.T) {
shimannotations.ResourcePartitionID: "87654321-4321-8765-4321-876543218765",
},
},
// A valid GUID should be accepted without error.
validate: func(t *testing.T, doc *hcsschema.ComputeSystem, sandboxOpts *SandboxOptions) {
t.Helper()
if doc.VirtualMachine.ResourcePartitionId != "87654321-4321-8765-4321-876543218765" {
t.Errorf("expected ResourcePartitionId %q, got %q", "87654321-4321-8765-4321-876543218765", doc.VirtualMachine.ResourcePartitionId)
}
},
},
{
name: "CPU group and resource partition conflict",
Expand Down
37 changes: 22 additions & 15 deletions internal/builder/vm/lcow/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ func parseCPUOptions(ctx context.Context, opts *runhcsoptions.Options, annotatio
cpu.CpuGroup = &hcsschema.CpuGroup{Id: cpuGroupID}
}

// Resource Partition ID parsing.
resourcePartitionID := oci.ParseAnnotationsString(annotations, shimannotations.ResourcePartitionID, "")
if resourcePartitionID != "" {
log.G(ctx).WithField("resourcePartitionID", resourcePartitionID).Debug("setting resource partition ID")

if _, err = guid.FromString(resourcePartitionID); err != nil {
return nil, fmt.Errorf("failed to parse resource_partition_id %q to GUID: %w", resourcePartitionID, err)
}

// CPU group and resource partition are mutually exclusive.
if cpuGroupID != "" {
return nil, fmt.Errorf("cpu_group_id and resource_partition_id cannot be set at the same time")
}
}

log.G(ctx).WithFields(logrus.Fields{
"processorCount": count,
"processorLimit": limit,
Expand All @@ -81,6 +66,28 @@ func parseCPUOptions(ctx context.Context, opts *runhcsoptions.Options, annotatio
return cpu, nil
}

// parseResourcePartitionOptions parses the resource partition ID annotation and validates it.
// Resource partition ID and CPU group ID are mutually exclusive.
func parseResourcePartitionOptions(ctx context.Context, annotations map[string]string, cpuConfig *hcsschema.VirtualMachineProcessor) (string, error) {
resourcePartitionID := oci.ParseAnnotationsString(annotations, shimannotations.ResourcePartitionID, "")
if resourcePartitionID == "" {
return "", nil
}

log.G(ctx).WithField("resourcePartitionID", resourcePartitionID).Debug("setting resource partition ID")

if _, err := guid.FromString(resourcePartitionID); err != nil {
return "", fmt.Errorf("failed to parse resource_partition_id %q to GUID: %w", resourcePartitionID, err)
}

// CPU group and resource partition are mutually exclusive.
if cpuConfig.CpuGroup != nil {
return "", fmt.Errorf("cpu_group_id and resource_partition_id cannot be set at the same time")
}

return resourcePartitionID, nil
}

// parseMemoryOptions parses memory options from annotations and options.
func parseMemoryOptions(ctx context.Context, opts *runhcsoptions.Options, annotations map[string]string, isFullyPhysicallyBacked bool) (*hcsschema.VirtualMachineMemory, error) {
log.G(ctx).Debug("parseMemoryOptions: starting memory options parsing")
Expand Down
3 changes: 2 additions & 1 deletion internal/hcs/schema2/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type VirtualMachine struct {
StorageQoS *StorageQoS `json:"StorageQoS,omitempty"`
DebugOptions *DebugOptions `json:"DebugOptions,omitempty"`
GuestConnection *GuestConnection `json:"GuestConnection,omitempty"`
SecuritySettings *SecuritySettings `json:"SecuritySettings,omitempty"`
SecuritySettings *SecuritySettings `json:"SecuritySettings,omitempty"`
ResourcePartitionId string `json:"ResourcePartitionId,omitempty"`
// Live migration options to be used on destination.
MigrationOptions *MigrationInitializeOptions `json:"MigrationOptions,omitempty"`
}
2 changes: 1 addition & 1 deletion internal/uvm/create_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ func MakeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs
}

if opts.ResourcePartitionID != nil {
// TODO (maksiman): assign pod to resource partition and potentially do an OS version check before that
log.G(ctx).WithField("resource-partition-id", opts.ResourcePartitionID.String()).Debug("setting resource partition ID")
doc.VirtualMachine.ResourcePartitionId = opts.ResourcePartitionID.String()
}

// Add optional devices that were specified on the UVM spec
Expand Down
2 changes: 1 addition & 1 deletion internal/uvm/create_wcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ func prepareCommonConfigDoc(ctx context.Context, uvm *UtilityVM, opts *OptionsWC
}

if opts.ResourcePartitionID != nil {
// TODO (maksiman): assign pod to resource partition and potentially do an OS version check before that
log.G(ctx).WithField("resource-partition-id", opts.ResourcePartitionID.String()).Debug("setting resource partition ID")
doc.VirtualMachine.ResourcePartitionId = opts.ResourcePartitionID.String()
}

maps.Copy(doc.VirtualMachine.Devices.HvSocket.HvSocketConfig.ServiceTable, opts.AdditionalHyperVConfig)
Expand Down
Loading