Skip to content

Commit c7d8bce

Browse files
committed
wip: perform IPI installation on AWS dedicated hosts
1 parent 55b3518 commit c7d8bce

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

pkg/asset/machines/aws/awsmachines.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type MachineInput struct {
3333
PublicIP bool
3434
PublicIpv4Pool string
3535
Ignition *capa.Ignition
36+
HostAffinity string
37+
HostID string
3638
}
3739

3840
// GenerateMachines returns manifests and runtime objects to provision the control plane (including bootstrap, if applicable) nodes using CAPI.
@@ -103,6 +105,8 @@ func GenerateMachines(clusterID string, in *MachineInput) ([]*asset.RuntimeFile,
103105
Subnet: subnet,
104106
PublicIP: ptr.To(in.PublicIP),
105107
AdditionalTags: in.Tags,
108+
HostID: ptr.To(in.HostID),
109+
HostAffinity: ptr.To(in.HostAffinity),
106110
RootVolume: &capa.Volume{
107111
Size: int64(mpool.EC2RootVolume.Size),
108112
Type: capa.VolumeType(mpool.EC2RootVolume.Type),

pkg/types/aws/platform.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const (
1414
VolumeTypeGp2 = "gp2"
1515
// VolumeTypeGp3 is the type of EBS volume for General Purpose SSD gp3.
1616
VolumeTypeGp3 = "gp3"
17+
18+
// HostAffinityDefault if an instance is stopped and restarted, it can be restarted on any available host.
19+
HostAffinityDefault = "default"
20+
// HostAffinityHost an instance started onto a specific host always restarts on the same host if stopped.
21+
HostAffinityHost = "host"
1722
)
1823

1924
// Platform stores all the global configuration that all machinesets
@@ -128,6 +133,18 @@ type Platform struct {
128133
// +default="Disabled"
129134
// +kubebuilder:validation:Enum="Enabled";"Disabled"
130135
UserProvisionedDNS dns.UserProvisionedDNS `json:"userProvisionedDNS,omitempty"`
136+
137+
// HostAffinity specifies the dedicated host affinity setting for the instance.
138+
// When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
139+
// When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
140+
// When HostAffinity is defined, HostID is required.
141+
// +optional
142+
// +kubebuilder:validation:Enum:=default;host
143+
HostAffinity string `json:"hostAffinity,omitempty"`
144+
145+
// HostID specifies the dedicated host on which the instance should be started.
146+
// +optional
147+
HostID string `json:"hostID,omitempty"`
131148
}
132149

133150
// ServiceEndpoint store the configuration for services to

pkg/types/aws/validation/platform.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ func ValidatePlatform(p *aws.Platform, publish types.PublishingStrategy, cm type
6060
allErrs = append(allErrs, ValidateMachinePool(p, p.DefaultMachinePlatform, fldPath.Child("defaultMachinePlatform"))...)
6161
}
6262

63+
if p.HostAffinity != "" {
64+
if p.HostID == "" {
65+
allErrs = append(allErrs, field.Required(fldPath.Child("hostID"), "hostID must be specified when hostAffinity is set"))
66+
}
67+
switch p.HostAffinity {
68+
case aws.HostAffinityDefault:
69+
case aws.HostAffinityHost:
70+
default:
71+
allErrs = append(allErrs, field.Invalid(fldPath.Child("hostAffinity"), p.HostAffinity, "hostAffinity must be either default or host"))
72+
}
73+
}
74+
6375
return allErrs
6476
}
6577

pkg/types/aws/validation/platform_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ func TestValidatePlatform(t *testing.T) {
8787
},
8888
expected: `^test-path\.serviceEndpoints\[0\]\.url: Invalid value: "(.*)": no path or request parameters must be provided, "/\?foo=some" was provided$`,
8989
},
90+
{
91+
name: "valid dedicated hosts",
92+
platform: &aws.Platform{
93+
HostAffinity: "default",
94+
HostID: "h-09dcf61cb388b0149",
95+
},
96+
},
97+
{
98+
name: "invalid dedicated hosts - invalid affinity type",
99+
platform: &aws.Platform{
100+
HostAffinity: "unknown",
101+
HostID: "h-09dcf61cb388b0149",
102+
},
103+
},
104+
{
105+
name: "invalid dedicated hosts - missing hostID",
106+
platform: &aws.Platform{
107+
HostAffinity: "host",
108+
},
109+
},
90110
{
91111
name: "valid url for service endpoint",
92112
platform: &aws.Platform{

0 commit comments

Comments
 (0)