Skip to content

Commit 86b24cb

Browse files
punkwalkerAmitSahastra
authored andcommitted
Add licenseConfigurationArns field in AWSMAchineSpec
1 parent 599e7ab commit 86b24cb

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
@@ -45,6 +45,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
4545
dst.Spec.MarketType = restored.Spec.MarketType
4646
dst.Spec.HostID = restored.Spec.HostID
4747
dst.Spec.HostResourceGroupArn = restored.Spec.HostResourceGroupArn
48+
dst.Spec.LicenseConfigurationArns = restored.Spec.LicenseConfigurationArns
4849
dst.Spec.HostAffinity = restored.Spec.HostAffinity
4950
dst.Spec.CapacityReservationPreference = restored.Spec.CapacityReservationPreference
5051
dst.Spec.NetworkInterfaceType = restored.Spec.NetworkInterfaceType
@@ -113,6 +114,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
113114
dst.Spec.Template.Spec.MarketType = restored.Spec.Template.Spec.MarketType
114115
dst.Spec.Template.Spec.HostID = restored.Spec.Template.Spec.HostID
115116
dst.Spec.Template.Spec.HostResourceGroupArn = restored.Spec.Template.Spec.HostResourceGroupArn
117+
dst.Spec.Template.Spec.LicenseConfigurationArns = restored.Spec.Template.Spec.LicenseConfigurationArns
116118
dst.Spec.Template.Spec.HostAffinity = restored.Spec.Template.Spec.HostAffinity
117119
dst.Spec.Template.Spec.CapacityReservationPreference = restored.Spec.Template.Spec.CapacityReservationPreference
118120
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
@@ -237,6 +237,12 @@ type AWSMachineSpec struct {
237237
// +optional
238238
HostResourceGroupArn *string `json:"hostResourceGroupArn,omitempty"`
239239

240+
// LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
241+
// This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
242+
// +kubebuilder:validation:MaxItems=10
243+
// +optional
244+
LicenseConfigurationArns []string `json:"licenseConfigurationArns,omitempty"`
245+
240246
// HostAffinity specifies the dedicated host affinity setting for the instance.
241247
// When HostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
242248
// 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
@@ -481,6 +481,13 @@ func (r *AWSMachine) validateHostAllocation() field.ErrorList {
481481
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "hostID, hostResourceGroupArn, and dynamicHostAllocation are mutually exclusive"))
482482
}
483483

484+
// Validate licenseConfigurationArns is required when hostResourceGroupArn is specified
485+
if hasHostResourceGroupArn {
486+
if len(r.Spec.LicenseConfigurationArns) == 0 {
487+
allErrs = append(allErrs, field.Required(field.NewPath("spec", "licenseConfigurationArns"), "licenseConfigurationArns is required when hostResourceGroupArn is specified"))
488+
}
489+
}
490+
484491
return allErrs
485492
}
486493

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,27 @@ func TestAWSMachineCreate(t *testing.T) {
584584
},
585585
wantErr: true,
586586
},
587+
{
588+
name: "hostResourceGroupArn without licenseConfigurationArns should fail",
589+
machine: &AWSMachine{
590+
Spec: AWSMachineSpec{
591+
InstanceType: "test",
592+
HostResourceGroupArn: aws.String("arn:aws:resource-groups:us-west-2:123456789012:group/test-group"),
593+
},
594+
},
595+
wantErr: true,
596+
},
597+
{
598+
name: "hostResourceGroupArn with licenseConfigurationArns should succeed",
599+
machine: &AWSMachine{
600+
Spec: AWSMachineSpec{
601+
InstanceType: "test",
602+
HostResourceGroupArn: aws.String("arn:aws:resource-groups:us-west-2:123456789012:group/test-group"),
603+
LicenseConfigurationArns: []string{"arn:aws:license-manager:us-west-2:259732043995:license-configuration:lic-4acd3f7c117b9e314cce36e46084d071"},
604+
},
605+
},
606+
wantErr: false,
607+
},
587608
}
588609
for _, tt := range tests {
589610
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
@@ -1151,8 +1151,9 @@ spec:
11511151
instance should be started.
11521152
type: string
11531153
hostResourceGroupArn:
1154-
description: HostResourceGroupArn specifies the Dedicated Host
1155-
Resource Group ARN on which the instance should be started.
1154+
description: |-
1155+
HostResourceGroupArn specifies the Dedicated Host Resource Group ARN on which the instance should be started.
1156+
Note: The instance's AMI licenses must match the licenses associated with the host resource group.
11561157
type: string
11571158
iamProfile:
11581159
description: The name of the IAM instance profile associated with
@@ -1228,6 +1229,13 @@ spec:
12281229
instanceState:
12291230
description: The current state of the instance.
12301231
type: string
1232+
licenseConfigurationArns:
1233+
description: |-
1234+
LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
1235+
This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
1236+
items:
1237+
type: string
1238+
type: array
12311239
marketType:
12321240
description: |-
12331241
MarketType specifies the type of market for the EC2 instance. Valid values include:
@@ -3226,8 +3234,9 @@ spec:
32263234
instance should be started.
32273235
type: string
32283236
hostResourceGroupArn:
3229-
description: HostResourceGroupArn specifies the Dedicated Host
3230-
Resource Group ARN on which the instance should be started.
3237+
description: |-
3238+
HostResourceGroupArn specifies the Dedicated Host Resource Group ARN on which the instance should be started.
3239+
Note: The instance's AMI licenses must match the licenses associated with the host resource group.
32313240
type: string
32323241
iamProfile:
32333242
description: The name of the IAM instance profile associated with
@@ -3303,6 +3312,13 @@ spec:
33033312
instanceState:
33043313
description: The current state of the instance.
33053314
type: string
3315+
licenseConfigurationArns:
3316+
description: |-
3317+
LicenseConfigurationArns specifies the License Configuration ARNs to associate with the instance.
3318+
This field is required when HostResourceGroupArn is specified to ensure proper license compliance.
3319+
items:
3320+
type: string
3321+
type: array
33063322
marketType:
33073323
description: |-
33083324
MarketType specifies the type of market for the EC2 instance. Valid values include:

0 commit comments

Comments
 (0)