Skip to content

Commit 886a00d

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

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

pkg/asset/machines/aws/awsmachines.go

Lines changed: 7 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+
HostIDs []string
3638
}
3739

3840
// GenerateMachines returns manifests and runtime objects to provision the control plane (including bootstrap, if applicable) nodes using CAPI.
@@ -86,6 +88,9 @@ func GenerateMachines(clusterID string, in *MachineInput) ([]*asset.RuntimeFile,
8688
}
8789
}
8890

91+
if len(in.hostIDs) > 1 {
92+
warn
93+
}
8994
awsMachine := &capa.AWSMachine{
9095
ObjectMeta: metav1.ObjectMeta{
9196
Name: fmt.Sprintf("%s-%s-%d", clusterID, in.Pool.Name, idx),
@@ -103,6 +108,8 @@ func GenerateMachines(clusterID string, in *MachineInput) ([]*asset.RuntimeFile,
103108
Subnet: subnet,
104109
PublicIP: ptr.To(in.PublicIP),
105110
AdditionalTags: in.Tags,
111+
HostID: ptr.To(in.HostIDs[0]),
112+
HostAffinity: ptr.To(in.HostAffinity),
106113
RootVolume: &capa.Volume{
107114
Size: int64(mpool.EC2RootVolume.Size),
108115
Type: capa.VolumeType(mpool.EC2RootVolume.Type),

pkg/types/aws/machinepool.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package aws
22

3+
const (
4+
// HostAffinityDefault if an instance is stopped and restarted, it can be restarted on any available host.
5+
HostAffinityDefault = "default"
6+
// HostAffinityHost an instance started onto a specific host always restarts on the same host if stopped.
7+
HostAffinityHost = "host"
8+
)
39
// MachinePool stores the configuration for a machine pool installed
410
// on AWS.
511
type MachinePool struct {
@@ -48,6 +54,19 @@ type MachinePool struct {
4854
// +kubebuilder:validation:MaxItems=10
4955
// +optional
5056
AdditionalSecurityGroupIDs []string `json:"additionalSecurityGroupIDs,omitempty"`
57+
58+
// HostAffinity specifies the dedicated host affinity setting for the instance.
59+
// When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
60+
// When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
61+
// When HostAffinity is defined, HostID is required.
62+
// +optional
63+
// +kubebuilder:validation:Enum:=default;host
64+
HostAffinity string `json:"hostAffinity,omitempty"`
65+
66+
// HostIDs specifies a slice of dedicated hosts on which instances should be started.
67+
// +kubebuilder:validation:MaxItems=1
68+
// +optional
69+
HostIDs []string `json:"hostIDs,omitempty"`
5170
}
5271

5372
// Set sets the values from `required` to `a`.

pkg/types/aws/platform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ type Platform struct {
127127
// +kubebuilder:default:="Disabled"
128128
// +default="Disabled"
129129
// +kubebuilder:validation:Enum="Enabled";"Disabled"
130-
UserProvisionedDNS dns.UserProvisionedDNS `json:"userProvisionedDNS,omitempty"`
130+
UserProvisionedDNS dns.UserProvisionedDNS `json:"userProvisionedDNS,omitempty"`
131131
}
132132

133133
// ServiceEndpoint store the configuration for services to

pkg/types/aws/validation/machinepool.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ func ValidateMachinePool(platform *aws.Platform, p *aws.MachinePool, fldPath *fi
5454

5555
allErrs = append(allErrs, validateSecurityGroups(platform, p, fldPath)...)
5656

57+
if p.HostAffinity != "" {
58+
if len(p.HostIDs) == 0 {
59+
allErrs = append(allErrs, field.Required(fldPath.Child("hostIDs"), "a hostID must be specified when hostAffinity is set"))
60+
}
61+
switch p.HostAffinity {
62+
case aws.HostAffinityDefault:
63+
case aws.HostAffinityHost:
64+
default:
65+
allErrs = append(allErrs, field.Invalid(fldPath.Child("hostAffinity"), p.HostAffinity, "hostAffinity must be either default or host"))
66+
}
67+
}
68+
5769
return allErrs
5870
}
5971

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)