Skip to content

Commit c2d0608

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

5 files changed

Lines changed: 404 additions & 36 deletions

File tree

machine/v1beta1/types_awsprovider.go

Lines changed: 88 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,27 @@ 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+
// +optional
420+
DedicatedHost *DedicatedHostStatus `json:"dedicatedHost,omitempty"`
421+
}
422+
423+
// DedicatedHostStatus defines the observed state of a dynamically allocated dedicated host
424+
// associated with an AWSMachine. This struct is used to track the ID of the dedicated host.
425+
// +kubebuilder:validation:MinProperties=1
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+
// When omitted, this indicates that the dedicated host has not yet been allocated, or allocation is in progress.
430+
// The value must start with "h-" followed by either 8 or 17 lowercase hexadecimal characters (0-9 and a-f).
431+
// The use of 8 lowercase hexadecimal characters is for older legacy hosts that may not have been migrated to newer format.
432+
// Must be either 10 or 19 characters in length.
433+
// +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)"
434+
// +kubebuilder:validation:MinLength=10
435+
// +kubebuilder:validation:MaxLength=19
436+
// +optional
437+
ID *string `json:"id,omitempty"`
410438
}
411439

412440
// MarketType describes the market type of an EC2 Instance
@@ -454,21 +482,77 @@ type HostAffinity string
454482

455483
const (
456484
// HostAffinityAnyAvailable lets the platform select any available dedicated host.
485+
457486
HostAffinityAnyAvailable HostAffinity = "AnyAvailable"
458487

459488
// HostAffinityDedicatedHost requires specifying a particular host via dedicatedHost.host.hostID.
460489
HostAffinityDedicatedHost HostAffinity = "DedicatedHost"
461490
)
462491

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

machine/v1beta1/zz_generated.deepcopy.go

Lines changed: 62 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)