Skip to content

Commit 1ddd74a

Browse files
committed
Add licenseConfigurationArns field in AWSMAchineSpec
1 parent 64fc535 commit 1ddd74a

14 files changed

+166
-9
lines changed

api/v1beta1/awsmachine_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
4646
dst.Spec.MarketType = restored.Spec.MarketType
4747
dst.Spec.HostID = restored.Spec.HostID
4848
dst.Spec.HostResourceGroupArn = restored.Spec.HostResourceGroupArn
49+
dst.Spec.LicenseConfigurationArns = restored.Spec.LicenseConfigurationArns
4950
dst.Spec.HostAffinity = restored.Spec.HostAffinity
5051
dst.Spec.CapacityReservationPreference = restored.Spec.CapacityReservationPreference
5152
dst.Spec.NetworkInterfaceType = restored.Spec.NetworkInterfaceType
@@ -119,6 +120,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
119120
dst.Spec.Template.Spec.MarketType = restored.Spec.Template.Spec.MarketType
120121
dst.Spec.Template.Spec.HostID = restored.Spec.Template.Spec.HostID
121122
dst.Spec.Template.Spec.HostResourceGroupArn = restored.Spec.Template.Spec.HostResourceGroupArn
123+
dst.Spec.Template.Spec.LicenseConfigurationArns = restored.Spec.Template.Spec.LicenseConfigurationArns
122124
dst.Spec.Template.Spec.HostAffinity = restored.Spec.Template.Spec.HostAffinity
123125
dst.Spec.Template.Spec.CapacityReservationPreference = restored.Spec.Template.Spec.CapacityReservationPreference
124126
dst.Spec.Template.Spec.NetworkInterfaceType = restored.Spec.Template.Spec.NetworkInterfaceType

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ type AWSMachineSpec struct {
258258
// +optional
259259
HostResourceGroupArn *string `json:"hostResourceGroupArn,omitempty"`
260260

261+
// LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
262+
// This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
263+
// +kubebuilder:validation:MaxItems=10
264+
// +optional
265+
LicenseConfigurationArns []string `json:"licenseConfigurationArns,omitempty"`
266+
261267
// HostAffinity specifies the dedicated host affinity setting for the instance.
262268
// When HostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
263269
// When HostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.

api/v1beta2/awsmachine_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ func (r *AWSMachine) validateHostAllocation() field.ErrorList {
497497
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "hostID, hostResourceGroupArn, and dynamicHostAllocation are mutually exclusive"))
498498
}
499499

500+
// Validate licenseConfigurationArns is required when hostResourceGroupArn is specified
501+
if hasHostResourceGroupArn {
502+
if len(r.Spec.LicenseConfigurationArns) == 0 {
503+
allErrs = append(allErrs, field.Required(field.NewPath("spec", "licenseConfigurationArns"), "licenseConfigurationArns is required when hostResourceGroupArn is specified"))
504+
}
505+
}
506+
500507
return allErrs
501508
}
502509

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,27 @@ func TestAWSMachineCreate(t *testing.T) {
648648
},
649649
wantErr: true,
650650
},
651+
{
652+
name: "hostResourceGroupArn without licenseConfigurationArns should fail",
653+
machine: &AWSMachine{
654+
Spec: AWSMachineSpec{
655+
InstanceType: "test",
656+
HostResourceGroupArn: aws.String("arn:aws:resource-groups:us-west-2:123456789012:group/test-group"),
657+
},
658+
},
659+
wantErr: true,
660+
},
661+
{
662+
name: "hostResourceGroupArn with licenseConfigurationArns should succeed",
663+
machine: &AWSMachine{
664+
Spec: AWSMachineSpec{
665+
InstanceType: "test",
666+
HostResourceGroupArn: aws.String("arn:aws:resource-groups:us-west-2:123456789012:group/test-group"),
667+
LicenseConfigurationArns: []string{"arn:aws:license-manager:us-west-2:259732043995:license-configuration:lic-4acd3f7c117b9e314cce36e46084d071"},
668+
},
669+
},
670+
wantErr: false,
671+
},
651672
}
652673
for _, tt := range tests {
653674
t.Run(tt.name, func(t *testing.T) {

api/v1beta2/awsmachinetemplate_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ func (r *AWSMachineTemplate) validateHostAllocation() field.ErrorList {
197197
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec.template.spec"), "hostID, hostResourceGroupArn, and dynamicHostAllocation are mutually exclusive"))
198198
}
199199

200+
// Validate licenseConfigurationArns is required when hostResourceGroupArn is specified
201+
if hasHostResourceGroupArn {
202+
if len(spec.LicenseConfigurationArns) == 0 {
203+
allErrs = append(allErrs, field.Required(field.NewPath("spec", "template", "spec", "licenseConfigurationArns"), "licenseConfigurationArns is required when hostResourceGroupArn is specified"))
204+
}
205+
}
206+
200207
return allErrs
201208
}
202209

api/v1beta2/awsmachinetemplate_webhook_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,37 @@ func TestAWSMachineTemplateValidateCreate(t *testing.T) {
151151
},
152152
wantError: true,
153153
},
154+
{
155+
name: "hostResourceGroupArn without licenseConfigurationArns should fail",
156+
inputTemplate: &AWSMachineTemplate{
157+
ObjectMeta: metav1.ObjectMeta{},
158+
Spec: AWSMachineTemplateSpec{
159+
Template: AWSMachineTemplateResource{
160+
Spec: AWSMachineSpec{
161+
InstanceType: "test",
162+
HostResourceGroupArn: aws.String("arn:aws:resource-groups:us-west-2:123456789012:group/test-group"),
163+
},
164+
},
165+
},
166+
},
167+
wantError: true,
168+
},
169+
{
170+
name: "hostResourceGroupArn with licenseConfigurationArns should succeed",
171+
inputTemplate: &AWSMachineTemplate{
172+
ObjectMeta: metav1.ObjectMeta{},
173+
Spec: AWSMachineTemplateSpec{
174+
Template: AWSMachineTemplateResource{
175+
Spec: AWSMachineSpec{
176+
InstanceType: "test",
177+
HostResourceGroupArn: aws.String("arn:aws:resource-groups:us-west-2:123456789012:group/test-group"),
178+
LicenseConfigurationArns: []string{"arn:aws:license-manager:us-west-2:259732043995:license-configuration:lic-4acd3f7c117b9e314cce36e46084d071"},
179+
},
180+
},
181+
},
182+
},
183+
wantError: false,
184+
},
154185
}
155186
for _, tt := range tests {
156187
t.Run(tt.name, func(t *testing.T) {

api/v1beta2/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ type Instance struct {
291291
// +optional
292292
HostResourceGroupArn *string `json:"hostResourceGroupArn,omitempty"`
293293

294+
// LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
295+
// This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
296+
// +optional
297+
LicenseConfigurationArns []string `json:"licenseConfigurationArns,omitempty"`
298+
294299
// DynamicHostAllocation enables automatic allocation of dedicated hosts.
295300
// This field is mutually exclusive with HostID.
296301
// +optional

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 10 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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,9 @@ spec:
12961296
instance should be started.
12971297
type: string
12981298
hostResourceGroupArn:
1299-
description: HostResourceGroupArn specifies the Dedicated Host
1300-
Resource Group ARN on which the instance should be started.
1299+
description: |-
1300+
HostResourceGroupArn specifies the Dedicated Host Resource Group ARN on which the instance should be started.
1301+
Note: The instance's AMI licenses must match the licenses associated with the host resource group.
13011302
type: string
13021303
iamProfile:
13031304
description: The name of the IAM instance profile associated with
@@ -1373,6 +1374,13 @@ spec:
13731374
instanceState:
13741375
description: The current state of the instance.
13751376
type: string
1377+
licenseConfigurationArns:
1378+
description: |-
1379+
LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
1380+
This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
1381+
items:
1382+
type: string
1383+
type: array
13761384
marketType:
13771385
description: |-
13781386
MarketType specifies the type of market for the EC2 instance. Valid values include:
@@ -3588,8 +3596,9 @@ spec:
35883596
instance should be started.
35893597
type: string
35903598
hostResourceGroupArn:
3591-
description: HostResourceGroupArn specifies the Dedicated Host
3592-
Resource Group ARN on which the instance should be started.
3599+
description: |-
3600+
HostResourceGroupArn specifies the Dedicated Host Resource Group ARN on which the instance should be started.
3601+
Note: The instance's AMI licenses must match the licenses associated with the host resource group.
35933602
type: string
35943603
iamProfile:
35953604
description: The name of the IAM instance profile associated with
@@ -3665,6 +3674,13 @@ spec:
36653674
instanceState:
36663675
description: The current state of the instance.
36673676
type: string
3677+
licenseConfigurationArns:
3678+
description: |-
3679+
LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
3680+
This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
3681+
items:
3682+
type: string
3683+
type: array
36683684
marketType:
36693685
description: |-
36703686
MarketType specifies the type of market for the EC2 instance. Valid values include:

0 commit comments

Comments
 (0)