diff --git a/pkg/actuators/machine/instances.go b/pkg/actuators/machine/instances.go index 201f57a9c..3bf950a38 100644 --- a/pkg/actuators/machine/instances.go +++ b/pkg/actuators/machine/instances.go @@ -841,6 +841,14 @@ func getCPUOptionsRequest(providerConfig *machinev1beta1.AWSMachineProviderConfi } } + if providerConfig.CPUOptions.CoreCount != nil { + cpuOptions.CoreCount = providerConfig.CPUOptions.CoreCount + } + + if providerConfig.CPUOptions.ThreadsPerCore != nil { + cpuOptions.ThreadsPerCore = providerConfig.CPUOptions.ThreadsPerCore + } + if *cpuOptions == (ec2.CpuOptionsRequest{}) { return nil } diff --git a/pkg/actuators/machine/instances_test.go b/pkg/actuators/machine/instances_test.go index 7aa28bad0..bb773d49b 100644 --- a/pkg/actuators/machine/instances_test.go +++ b/pkg/actuators/machine/instances_test.go @@ -1737,6 +1737,56 @@ func TestGetCPUOptionsRequest(t *testing.T) { }, expectedRequest: nil, }, + { + name: "with CoreCount set", + providerConfig: &machinev1beta1.AWSMachineProviderConfig{ + CPUOptions: &machinev1beta1.CPUOptions{ + CoreCount: ptr.To[int64](4), + }, + }, + expectedRequest: &ec2.CpuOptionsRequest{ + CoreCount: aws.Int64(4), + }, + }, + { + name: "with ThreadsPerCore set", + providerConfig: &machinev1beta1.AWSMachineProviderConfig{ + CPUOptions: &machinev1beta1.CPUOptions{ + ThreadsPerCore: ptr.To[int64](1), + }, + }, + expectedRequest: &ec2.CpuOptionsRequest{ + ThreadsPerCore: aws.Int64(1), + }, + }, + { + name: "with CoreCount and ThreadsPerCore set", + providerConfig: &machinev1beta1.AWSMachineProviderConfig{ + CPUOptions: &machinev1beta1.CPUOptions{ + CoreCount: ptr.To[int64](2), + ThreadsPerCore: ptr.To[int64](2), + }, + }, + expectedRequest: &ec2.CpuOptionsRequest{ + CoreCount: aws.Int64(2), + ThreadsPerCore: aws.Int64(2), + }, + }, + { + name: "with all CPUOptions fields set", + providerConfig: &machinev1beta1.AWSMachineProviderConfig{ + CPUOptions: &machinev1beta1.CPUOptions{ + ConfidentialCompute: ptr.To(machinev1beta1.AWSConfidentialComputePolicySEVSNP), + CoreCount: ptr.To[int64](4), + ThreadsPerCore: ptr.To[int64](1), + }, + }, + expectedRequest: &ec2.CpuOptionsRequest{ + AmdSevSnp: aws.String(ec2.AmdSevSnpSpecificationEnabled), + CoreCount: aws.Int64(4), + ThreadsPerCore: aws.Int64(1), + }, + }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { diff --git a/vendor/github.com/openshift/api/machine/v1beta1/types_awsprovider.go b/vendor/github.com/openshift/api/machine/v1beta1/types_awsprovider.go index e3508d667..7b3b08960 100644 --- a/vendor/github.com/openshift/api/machine/v1beta1/types_awsprovider.go +++ b/vendor/github.com/openshift/api/machine/v1beta1/types_awsprovider.go @@ -154,6 +154,26 @@ type CPUOptions struct { // which is subject to change without notice. The current default is Disabled. // +optional ConfidentialCompute *AWSConfidentialComputePolicy `json:"confidentialCompute,omitempty"` + // coreCount specifies the number of CPU cores for the instance. + // The number of valid CPU cores depends on the instance type. + // When omitted, this means no opinion and the platform chooses the default, + // which is subject to change without notice. + // More details: + // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/cpu-options-supported-instances-values.html + // +kubebuilder:validation:Minimum=1 + // +optional + CoreCount *int64 `json:"coreCount,omitempty"` + // threadsPerCore specifies the number of threads per CPU core for the instance. + // To disable multithreading, specify a value of 1. + // Otherwise, specify a value of 2 to enable multithreading. + // The number of valid threads per core depends on the instance type. + // When omitted, this means no opinion and the platform chooses the default, + // which is subject to change without notice. + // More details: + // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/cpu-options-supported-instances-values.html + // +kubebuilder:validation:Enum=1;2 + // +optional + ThreadsPerCore *int64 `json:"threadsPerCore,omitempty"` } // BlockDeviceMappingSpec describes a block device mapping diff --git a/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.deepcopy.go b/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.deepcopy.go index 63b9bb5ff..0245fc66f 100644 --- a/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.deepcopy.go +++ b/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.deepcopy.go @@ -429,6 +429,16 @@ func (in *CPUOptions) DeepCopyInto(out *CPUOptions) { *out = new(AWSConfidentialComputePolicy) **out = **in } + if in.CoreCount != nil { + in, out := &in.CoreCount, &out.CoreCount + *out = new(int64) + **out = **in + } + if in.ThreadsPerCore != nil { + in, out := &in.ThreadsPerCore, &out.ThreadsPerCore + *out = new(int64) + **out = **in + } return } diff --git a/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.swagger_doc_generated.go b/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.swagger_doc_generated.go index 2c4a9030c..f0fa83f30 100644 --- a/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.swagger_doc_generated.go +++ b/vendor/github.com/openshift/api/machine/v1beta1/zz_generated.swagger_doc_generated.go @@ -87,6 +87,8 @@ func (BlockDeviceMappingSpec) SwaggerDoc() map[string]string { var map_CPUOptions = map[string]string{ "": "CPUOptions defines CPU-related settings for the instance, including the confidential computing policy. If provided, it must not be empty — at least one field must be set.", "confidentialCompute": "confidentialCompute specifies whether confidential computing should be enabled for the instance, and, if so, which confidential computing technology to use. Valid values are: Disabled, AMDEncryptedVirtualizationNestedPaging and omitted. When set to Disabled, confidential computing will be disabled for the instance. When set to AMDEncryptedVirtualizationNestedPaging, AMD SEV-SNP will be used as the confidential computing technology for the instance. In this case, ensure the following conditions are met: 1) The selected instance type supports AMD SEV-SNP. 2) The selected AWS region supports AMD SEV-SNP. 3) The selected AMI supports AMD SEV-SNP. More details can be checked at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/sev-snp.html When omitted, this means no opinion and the AWS platform is left to choose a reasonable default, which is subject to change without notice. The current default is Disabled.", + "coreCount": "coreCount specifies the number of CPU cores for the instance. The number of valid CPU cores depends on the instance type. When omitted, this means no opinion and the platform chooses the default, which is subject to change without notice.", + "threadsPerCore": "threadsPerCore specifies the number of threads per CPU core for the instance. To disable multithreading, specify a value of 1. Otherwise, specify a value of 2 to enable multithreading. The number of valid threads per core depends on the instance type. When omitted, this means no opinion and the platform chooses the default, which is subject to change without notice.", } func (CPUOptions) SwaggerDoc() map[string]string {