Skip to content

Commit 2fc32cc

Browse files
committed
Added support for dynamic AWS dedicated hosts
1 parent 6ab113c commit 2fc32cc

5 files changed

Lines changed: 398 additions & 32 deletions

File tree

machine/v1beta1/types_awsprovider.go

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,16 @@ type Filter struct {
331331

332332
// TagSpecification is the name/value pair for a tag
333333
type TagSpecification struct {
334-
// name of the tag
334+
// name of the tag.
335+
// This field is required and must be a non-empty string.
336+
// Must be between 1 and 128 characters in length.
337+
// +kubebuilder:validation:MinLength=1
338+
// +kubebuilder:validation:MaxLength=128
339+
// +required
335340
Name string `json:"name"`
336-
// value of the tag
341+
// value of the tag.
342+
// When omitted, this creates a tag with an empty string as the value.
343+
// +optional
337344
Value string `json:"value"`
338345
}
339346

@@ -407,6 +414,26 @@ type AWSMachineProviderStatus struct {
407414
// +listType=map
408415
// +listMapKey=type
409416
Conditions []metav1.Condition `json:"conditions,omitempty"`
417+
// dedicatedHost tracks the dynamically allocated dedicated host.
418+
// This field is populated when allocationStrategy is Dynamic (with or without DynamicHostAllocation).
419+
// When omitted, this indicates that the dedicated host has not yet been allocated, or allocation is in progress.
420+
// +optional
421+
DedicatedHost *DedicatedHostStatus `json:"dedicatedHost,omitempty"`
422+
}
423+
424+
// DedicatedHostStatus defines the observed state of a dynamically allocated dedicated host
425+
// associated with an AWSMachine. This struct is used to track the ID of the dedicated host.
426+
type DedicatedHostStatus struct {
427+
// id tracks the dynamically allocated dedicated host ID.
428+
// This field is populated when allocationStrategy is Dynamic (with or without DynamicHostAllocation).
429+
// The value must start with "h-" followed by either 8 or 17 lowercase hexadecimal characters (0-9 and a-f).
430+
// The use of 8 lowercase hexadecimal characters is for older legacy hosts that may not have been migrated to newer format.
431+
// Must be either 10 or 19 characters in length.
432+
// +kubebuilder:validation:XValidation:rule="self.matches('^h-([0-9a-f]{8}|[0-9a-f]{17})$')",message="id must start with 'h-' followed by either 8 or 17 lowercase hexadecimal characters (0-9 and a-f)"
433+
// +kubebuilder:validation:MinLength=10
434+
// +kubebuilder:validation:MaxLength=19
435+
// +required
436+
ID string `json:"id,omitempty"`
410437
}
411438

412439
// MarketType describes the market type of an EC2 Instance
@@ -454,21 +481,77 @@ type HostAffinity string
454481

455482
const (
456483
// HostAffinityAnyAvailable lets the platform select any available dedicated host.
484+
457485
HostAffinityAnyAvailable HostAffinity = "AnyAvailable"
458486

459487
// HostAffinityDedicatedHost requires specifying a particular host via dedicatedHost.host.hostID.
460488
HostAffinityDedicatedHost HostAffinity = "DedicatedHost"
461489
)
462490

491+
// AllocationStrategy selects how a dedicated host is provided to the system for assigning to the instance.
492+
// +kubebuilder:validation:Enum:=UserProvided;Dynamic
493+
// +enum
494+
type AllocationStrategy string
495+
496+
const (
497+
// AllocationStrategyUserProvided specifies that the system should assign instances to a user-provided dedicated host.
498+
AllocationStrategyUserProvided AllocationStrategy = "UserProvided"
499+
500+
// AllocationStrategyDynamic specifies that the system should dynamically allocate a dedicated host for instances.
501+
AllocationStrategyDynamic AllocationStrategy = "Dynamic"
502+
)
503+
463504
// DedicatedHost represents the configuration for the usage of dedicated host.
505+
// +kubebuilder:validation:XValidation:rule="self.allocationStrategy == 'UserProvided' ? has(self.id) : !has(self.id)",message="id is required when allocationStrategy is UserProvided, and forbidden otherwise"
506+
// +kubebuilder:validation:XValidation:rule="has(self.dynamicHostAllocation) ? self.allocationStrategy == 'Dynamic' : true",message="dynamicHostAllocation is only allowed when allocationStrategy is Dynamic"
507+
// +union
464508
type DedicatedHost struct {
509+
// allocationStrategy specifies if the dedicated host will be provided by the admin through the id field or if the host will be dynamically allocated.
510+
// Valid values are UserProvided and Dynamic.
511+
// When omitted, the value defaults to "UserProvided", which requires the id field to be set.
512+
// When allocationStrategy is set to UserProvided, an ID of the dedicated host to assign must be provided.
513+
// When allocationStrategy is set to Dynamic, a dedicated host will be allocated and used to assign instances.
514+
// When allocationStrategy is set to Dynamic, and dynamicHostAllocation is configured, a dedicated host will be allocated and the tags in dynamicHostAllocation will be assigned to that host.
515+
// +optional
516+
// +unionDiscriminator
517+
// +default="UserProvided"
518+
AllocationStrategy *AllocationStrategy `json:"allocationStrategy,omitempty"`
519+
465520
// id identifies the AWS Dedicated Host on which the instance must run.
466521
// The value must start with "h-" followed by either 8 or 17 lowercase hexadecimal characters (0-9 and a-f).
467522
// The use of 8 lowercase hexadecimal characters is for older legacy hosts that may not have been migrated to newer format.
468523
// Must be either 10 or 19 characters in length.
469-
// +kubebuilder:validation:XValidation:rule="self.matches('^h-([0-9a-f]{8}|[0-9a-f]{17})$')",message="hostID must start with 'h-' followed by either 8 or 17 lowercase hexadecimal characters (0-9 and a-f)"
524+
// This field is required when allocationStrategy is UserProvided, and forbidden otherwise.
525+
// When omitted with allocationStrategy set to Dynamic, the platform will dynamically allocate a dedicated host.
526+
// +kubebuilder:validation:XValidation:rule="self.matches('^h-([0-9a-f]{8}|[0-9a-f]{17})$')",message="id must start with 'h-' followed by either 8 or 17 lowercase hexadecimal characters (0-9 and a-f)"
470527
// +kubebuilder:validation:MinLength=10
471528
// +kubebuilder:validation:MaxLength=19
472-
// +required
529+
// +optional
530+
// +unionMember=UserProvided
473531
ID string `json:"id,omitempty"`
532+
533+
// dynamicHostAllocation specifies tags to apply to a dynamically allocated dedicated host.
534+
// This field is only allowed when allocationStrategy is Dynamic, and is mutually exclusive with id.
535+
// When specified, a dedicated host will be allocated with the provided tags applied.
536+
// When omitted (and allocationStrategy is Dynamic), a dedicated host will be allocated without any additional tags.
537+
// +optional
538+
// +unionMember=Dynamic
539+
DynamicHostAllocation *DynamicHostAllocationSpec `json:"dynamicHostAllocation,omitempty"`
540+
}
541+
542+
// DynamicHostAllocationSpec defines the configuration for dynamic dedicated host allocation.
543+
// This specification always allocates exactly one dedicated host per machine.
544+
// At least one property must be specified when this struct is used.
545+
// Currently only Tags are available for configuring, but in the future more configs may become available.
546+
// +kubebuilder:validation:MinProperties=1
547+
type DynamicHostAllocationSpec struct {
548+
// tags specifies a set of key-value pairs to apply to the allocated dedicated host.
549+
// When omitted, no additional user-defined tags will be applied to the allocated host.
550+
// A maximum of 50 tags can be specified.
551+
// +kubebuilder:validation:MinItems=1
552+
// +kubebuilder:validation:MaxItems=50
553+
// +listType=map
554+
// +listMapKey=name
555+
// +optional
556+
Tags *[]TagSpecification `json:"tags,omitempty"`
474557
}

machine/v1beta1/zz_generated.deepcopy.go

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

machine/v1beta1/zz_generated.swagger_doc_generated.go

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

0 commit comments

Comments
 (0)