Skip to content

Commit 7f675da

Browse files
committed
Add support for AMD SEV-SNP instances
This commit adds support for AMD SEV-SNP instances. AMD SEV-SNP can be configured by cpuOptions.AmdSevSnp, valid values: true, false. Signed-off-by: Fangge Jin <[email protected]>
1 parent 8d4c7f2 commit 7f675da

14 files changed

+286
-0
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
6363
dst.Status.Bastion.NetworkInterfaceType = restored.Status.Bastion.NetworkInterfaceType
6464
dst.Status.Bastion.CapacityReservationID = restored.Status.Bastion.CapacityReservationID
6565
dst.Status.Bastion.MarketType = restored.Status.Bastion.MarketType
66+
dst.Status.Bastion.CpuOptions = restored.Status.Bastion.CpuOptions
6667
}
6768
dst.Spec.Partition = restored.Spec.Partition
6869

api/v1beta1/awsmachine_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
4545
dst.Spec.CapacityReservationID = restored.Spec.CapacityReservationID
4646
dst.Spec.MarketType = restored.Spec.MarketType
4747
dst.Spec.NetworkInterfaceType = restored.Spec.NetworkInterfaceType
48+
dst.Spec.CpuOptions = restored.Spec.CpuOptions
4849
if restored.Spec.ElasticIPPool != nil {
4950
if dst.Spec.ElasticIPPool == nil {
5051
dst.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}
@@ -109,6 +110,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
109110
dst.Spec.Template.Spec.CapacityReservationID = restored.Spec.Template.Spec.CapacityReservationID
110111
dst.Spec.Template.Spec.MarketType = restored.Spec.Template.Spec.MarketType
111112
dst.Spec.Template.Spec.NetworkInterfaceType = restored.Spec.Template.Spec.NetworkInterfaceType
113+
dst.Spec.Template.Spec.CpuOptions = restored.Spec.Template.Spec.CpuOptions
112114
if restored.Spec.Template.Spec.ElasticIPPool != nil {
113115
if dst.Spec.Template.Spec.ElasticIPPool == nil {
114116
dst.Spec.Template.Spec.ElasticIPPool = &infrav1.ElasticIPPool{}

api/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awsmachine_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ const (
7373
NetworkInterfaceTypeEFAWithENAInterface NetworkInterfaceType = NetworkInterfaceType("efa")
7474
)
7575

76+
// AmdSevSnpSpecification defines the different values for AmdSevSnp
77+
type AmdSevSnpSpecification string
78+
79+
const (
80+
// AmdSevSnpSpecificationEnabled means AMD SEV SNP is enabled for the instance.
81+
AmdSevSnpSpecificationEnabled AmdSevSnpSpecification = "enabled"
82+
83+
// AmdSevSnpSpecificationDisabled means AMD SEV SNP is disabled for the instance.
84+
AmdSevSnpSpecificationDisabled AmdSevSnpSpecification = "disabled"
85+
)
86+
87+
// CpuOptions defines the cpu options for the instance.
88+
type CpuOptions struct {
89+
// AmdSevSnp specifies AMD SEV-SNP for the instance.
90+
// +kubebuilder:validation:Enum=enabled;disabled
91+
// +optional
92+
AmdSevSnp AmdSevSnpSpecification `json:"amdSevSnp,omitempty"`
93+
}
94+
95+
// Confidentail computing support depends on the instance type.
96+
// Only certain instance types in M6a, R6a and C6a series support AMD SEV-SNP. Reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/sev-snp.html
97+
var (
98+
instanceTypesSupportingAmdSevsnp = []string{"m6a.large", "m6a.xlarge", "m6a.2xlarge", "m6a.4xlarge", "m6a.8xlarge",
99+
"c6a.large", "c6a.xlarge", "c6a.2xlarge", "c6a.4xlarge", "c6a.8xlarge", "c6a.12xlarge", "c6a.16xlarge",
100+
"r6a.large", "r6a.xlarge", "r6a.2xlarge", "r6a.4xlarge"}
101+
)
102+
76103
// AWSMachineSpec defines the desired state of an Amazon EC2 instance.
77104
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.marketType) || self.marketType != 'Spot'",message="capacityReservationId may not be set when marketType is Spot"
78105
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.spotMarketOptions)",message="capacityReservationId cannot be set when spotMarketOptions is specified"
@@ -116,6 +143,10 @@ type AWSMachineSpec struct {
116143
// +kubebuilder:validation:MinLength:=2
117144
InstanceType string `json:"instanceType"`
118145

146+
// CpuOptions is the set of cpu options for the instance
147+
// +optional
148+
CpuOptions *CpuOptions `json:"cpuOptions,omitempty"`
149+
119150
// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
120151
// AWS provider. If both the AWSCluster and the AWSMachine specify the same tag name with different values, the
121152
// AWSMachine's value takes precedence.

api/v1beta2/awsmachine_webhook.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"net/url"
2525
"strings"
2626

27+
"k8s.io/utils/strings/slices"
28+
2729
"github.com/google/go-cmp/cmp"
2830
"github.com/pkg/errors"
2931
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -78,6 +80,7 @@ func (*awsMachineWebhook) ValidateCreate(_ context.Context, obj runtime.Object)
7880
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)
7981
allErrs = append(allErrs, r.validateNetworkElasticIPPool()...)
8082
allErrs = append(allErrs, r.validateInstanceMarketType()...)
83+
allErrs = append(allErrs, r.validateInstanceTypeForConfidentialCompute()...)
8184

8285
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
8386
}
@@ -417,6 +420,17 @@ func (r *AWSMachine) validateNonRootVolumes() field.ErrorList {
417420
return allErrs
418421
}
419422

423+
func (r *AWSMachine) validateInstanceTypeForConfidentialCompute() field.ErrorList {
424+
var allErrs field.ErrorList
425+
if r.Spec.CpuOptions != nil {
426+
if r.Spec.CpuOptions.AmdSevSnp != "" && r.Spec.CpuOptions.AmdSevSnp == "enabled" && !slices.Contains(instanceTypesSupportingAmdSevsnp, r.Spec.InstanceType) {
427+
allErrs = append(allErrs, field.Required(field.NewPath("spec.InstanceType"), "this instance type doesn't support AMD SEV-SNP"))
428+
}
429+
}
430+
431+
return allErrs
432+
}
433+
420434
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
421435
func (*awsMachineWebhook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
422436
return nil, nil

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,30 @@ func TestAWSMachineCreate(t *testing.T) {
279279
},
280280
wantErr: true,
281281
},
282+
{
283+
name: "invalid instance type for AMD SEV-SNP",
284+
machine: &AWSMachine{
285+
Spec: AWSMachineSpec{
286+
InstanceType: "test",
287+
CpuOptions: &CpuOptions{
288+
AmdSevSnp: "enabled",
289+
},
290+
},
291+
},
292+
wantErr: true,
293+
},
294+
{
295+
name: "valid instance type for AMD SEV-SNP",
296+
machine: &AWSMachine{
297+
Spec: AWSMachineSpec{
298+
InstanceType: "m6a.large",
299+
CpuOptions: &CpuOptions{
300+
AmdSevSnp: "enabled",
301+
},
302+
},
303+
},
304+
wantErr: false,
305+
},
282306
{
283307
name: "invalid tags return error",
284308
machine: &AWSMachine{

api/v1beta2/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ type Instance struct {
172172
// The instance type.
173173
Type string `json:"type,omitempty"`
174174

175+
// The cpu options of the instance.
176+
CpuOptions *CpuOptions `json:"cpuOptions,omitempty"`
177+
175178
// The ID of the subnet of the instance.
176179
SubnetID string `json:"subnetId,omitempty"`
177180

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,16 @@ spec:
12141214
description: CapacityReservationID specifies the target Capacity
12151215
Reservation into which the instance should be launched.
12161216
type: string
1217+
cpuOptions:
1218+
description: The cpu options of the instance.
1219+
properties:
1220+
amdSevSnp:
1221+
description: AmdSevSnp specifies AMD SEV-SNP for the instance.
1222+
enum:
1223+
- enabled
1224+
- disabled
1225+
type: string
1226+
type: object
12171227
ebsOptimized:
12181228
description: Indicates whether the instance is optimized for Amazon
12191229
EBS I/O.
@@ -3395,6 +3405,16 @@ spec:
33953405
description: CapacityReservationID specifies the target Capacity
33963406
Reservation into which the instance should be launched.
33973407
type: string
3408+
cpuOptions:
3409+
description: The cpu options of the instance.
3410+
properties:
3411+
amdSevSnp:
3412+
description: AmdSevSnp specifies AMD SEV-SNP for the instance.
3413+
enum:
3414+
- enabled
3415+
- disabled
3416+
type: string
3417+
type: object
33983418
ebsOptimized:
33993419
description: Indicates whether the instance is optimized for Amazon
34003420
EBS I/O.

config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,16 @@ spec:
21972197
description: CapacityReservationID specifies the target Capacity
21982198
Reservation into which the instance should be launched.
21992199
type: string
2200+
cpuOptions:
2201+
description: The cpu options of the instance.
2202+
properties:
2203+
amdSevSnp:
2204+
description: AmdSevSnp specifies AMD SEV-SNP for the instance.
2205+
enum:
2206+
- enabled
2207+
- disabled
2208+
type: string
2209+
type: object
22002210
ebsOptimized:
22012211
description: Indicates whether the instance is optimized for Amazon
22022212
EBS I/O.

0 commit comments

Comments
 (0)