Skip to content

Commit 39372a0

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

File tree

6 files changed

+129
-1
lines changed

6 files changed

+129
-1
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ spec:
132132
AMIID is the AMI that should be used to boot the ec2 instance.
133133
If set, the AMI should belong to the same region as the cluster.
134134
type: string
135+
hostAffinity:
136+
description: |-
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+
enum:
142+
- default
143+
- host
144+
type: string
145+
hostIDs:
146+
description: HostIDs specifies a slice of dedicated hosts
147+
on which instances should be started.
148+
items:
149+
type: string
150+
maxItems: 1
151+
type: array
135152
iamProfile:
136153
description: |-
137154
IAMProfile is the name of the IAM instance profile to use for the machine.
@@ -1452,6 +1469,23 @@ spec:
14521469
AMIID is the AMI that should be used to boot the ec2 instance.
14531470
If set, the AMI should belong to the same region as the cluster.
14541471
type: string
1472+
hostAffinity:
1473+
description: |-
1474+
HostAffinity specifies the dedicated host affinity setting for the instance.
1475+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
1476+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
1477+
When HostAffinity is defined, HostID is required.
1478+
enum:
1479+
- default
1480+
- host
1481+
type: string
1482+
hostIDs:
1483+
description: HostIDs specifies a slice of dedicated hosts
1484+
on which instances should be started.
1485+
items:
1486+
type: string
1487+
maxItems: 1
1488+
type: array
14551489
iamProfile:
14561490
description: |-
14571491
IAMProfile is the name of the IAM instance profile to use for the machine.
@@ -2711,6 +2745,23 @@ spec:
27112745
AMIID is the AMI that should be used to boot the ec2 instance.
27122746
If set, the AMI should belong to the same region as the cluster.
27132747
type: string
2748+
hostAffinity:
2749+
description: |-
2750+
HostAffinity specifies the dedicated host affinity setting for the instance.
2751+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
2752+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
2753+
When HostAffinity is defined, HostID is required.
2754+
enum:
2755+
- default
2756+
- host
2757+
type: string
2758+
hostIDs:
2759+
description: HostIDs specifies a slice of dedicated hosts
2760+
on which instances should be started.
2761+
items:
2762+
type: string
2763+
maxItems: 1
2764+
type: array
27142765
iamProfile:
27152766
description: |-
27162767
IAMProfile is the name of the IAM instance profile to use for the machine.
@@ -4193,6 +4244,23 @@ spec:
41934244
AMIID is the AMI that should be used to boot the ec2 instance.
41944245
If set, the AMI should belong to the same region as the cluster.
41954246
type: string
4247+
hostAffinity:
4248+
description: |-
4249+
HostAffinity specifies the dedicated host affinity setting for the instance.
4250+
When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
4251+
When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
4252+
When HostAffinity is defined, HostID is required.
4253+
enum:
4254+
- default
4255+
- host
4256+
type: string
4257+
hostIDs:
4258+
description: HostIDs specifies a slice of dedicated hosts
4259+
on which instances should be started.
4260+
items:
4261+
type: string
4262+
maxItems: 1
4263+
type: array
41964264
iamProfile:
41974265
description: |-
41984266
IAMProfile is the name of the IAM instance profile to use for the machine.

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
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+
)
9+
310
// MachinePool stores the configuration for a machine pool installed
411
// on AWS.
512
type MachinePool struct {
@@ -48,6 +55,20 @@ type MachinePool struct {
4855
// +kubebuilder:validation:MaxItems=10
4956
// +optional
5057
AdditionalSecurityGroupIDs []string `json:"additionalSecurityGroupIDs,omitempty"`
58+
59+
// HostAffinity specifies the dedicated host affinity setting for the instance.
60+
// When hostAffinity is set to host, an instance started onto a specific host always restarts on the same host if stopped.
61+
// When hostAffinity is set to default, and you stop and restart the instance, it can be restarted on any available host.
62+
// When HostAffinity is defined, HostID is required.
63+
// +optional
64+
// +kubebuilder:validation:Enum:=default;host
65+
HostAffinity string `json:"hostAffinity,omitempty"`
66+
67+
// HostIDs specifies a slice of dedicated hosts on which instances should be started.
68+
// presently, only a single dedicated host can be specified per pool.
69+
// +kubebuilder:validation:MaxItems=1
70+
// +optional
71+
HostIDs []string `json:"hostIDs,omitempty"`
5172
}
5273

5374
// 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)