Skip to content

Commit bbf4d9c

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 bbf4d9c

14 files changed

+270
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ const (
7373
NetworkInterfaceTypeEFAWithENAInterface NetworkInterfaceType = NetworkInterfaceType("efa")
7474
)
7575

76+
// CpuOptions defines the cpu options for the instance.
77+
type CpuOptions struct {
78+
// AmdSevSnp enables AMD SEV-SNP on the instance.
79+
// +optional
80+
AmdSevSnp *bool `json:"amdSevSnp,omitempty"`
81+
}
82+
83+
// Confidentail computing support depends on the instance type.
84+
// 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
85+
var (
86+
instanceTypesSupportingAmdSevsnp = []string{"m6a.large", "m6a.xlarge", "m6a.2xlarge", "m6a.4xlarge", "m6a.8xlarge",
87+
"c6a.large", "c6a.xlarge", "c6a.2xlarge", "c6a.4xlarge", "c6a.8xlarge", "c6a.12xlarge", "c6a.16xlarge",
88+
"r6a.large", "r6a.xlarge", "r6a.2xlarge", "r6a.4xlarge"}
89+
)
90+
91+
7692
// AWSMachineSpec defines the desired state of an Amazon EC2 instance.
7793
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.marketType) || self.marketType != 'Spot'",message="capacityReservationId may not be set when marketType is Spot"
7894
// +kubebuilder:validation:XValidation:rule="!has(self.capacityReservationId) || !has(self.spotMarketOptions)",message="capacityReservationId cannot be set when spotMarketOptions is specified"
@@ -116,6 +132,10 @@ type AWSMachineSpec struct {
116132
// +kubebuilder:validation:MinLength:=2
117133
InstanceType string `json:"instanceType"`
118134

135+
// CpuOptions is the set of cpu options for the instance
136+
// +optional
137+
CpuOptions *CpuOptions `json:"cpuOptions,omitempty"`
138+
119139
// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
120140
// AWS provider. If both the AWSCluster and the AWSMachine specify the same tag name with different values, the
121141
// 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 != nil && *r.Spec.CpuOptions.AmdSevSnp && !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: aws.Bool(true),
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: aws.Bool(true),
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: 30 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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,13 @@ 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 enables AMD SEV-SNP on the instance.
1222+
type: boolean
1223+
type: object
12171224
ebsOptimized:
12181225
description: Indicates whether the instance is optimized for Amazon
12191226
EBS I/O.
@@ -3395,6 +3402,13 @@ spec:
33953402
description: CapacityReservationID specifies the target Capacity
33963403
Reservation into which the instance should be launched.
33973404
type: string
3405+
cpuOptions:
3406+
description: The cpu options of the instance.
3407+
properties:
3408+
amdSevSnp:
3409+
description: AmdSevSnp enables AMD SEV-SNP on the instance.
3410+
type: boolean
3411+
type: object
33983412
ebsOptimized:
33993413
description: Indicates whether the instance is optimized for Amazon
34003414
EBS I/O.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,13 @@ 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 enables AMD SEV-SNP on the instance.
2205+
type: boolean
2206+
type: object
22002207
ebsOptimized:
22012208
description: Indicates whether the instance is optimized for Amazon
22022209
EBS I/O.

0 commit comments

Comments
 (0)