Skip to content

Commit f5332d7

Browse files
authored
Merge pull request #3847 from Ankitasw/remove-failure-domain
Remove failure domain from AWSMachineSpec to respect CAPI's Machine/MD failure domain field
2 parents 0b55547 + b7cae76 commit f5332d7

File tree

18 files changed

+37
-120
lines changed

18 files changed

+37
-120
lines changed

api/v1beta1/conversion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ func Convert_v1beta2_AWSClusterSpec_To_v1beta1_AWSClusterSpec(in *v1beta2.AWSClu
2828
func Convert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in *AWSResourceReference, out *v1beta2.AWSResourceReference, s conversion.Scope) error {
2929
return autoConvert_v1beta1_AWSResourceReference_To_v1beta2_AWSResourceReference(in, out, s)
3030
}
31+
32+
func Convert_v1beta1_AWSMachineSpec_To_v1beta2_AWSMachineSpec(in *AWSMachineSpec, out *v1beta2.AWSMachineSpec, s conversion.Scope) error {
33+
return autoConvert_v1beta1_AWSMachineSpec_To_v1beta2_AWSMachineSpec(in, out, s)
34+
}

api/v1beta1/conversion_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
3939
func AWSMachineFuzzer(obj *AWSMachine, c fuzz.Continue) {
4040
c.FuzzNoCustom(obj)
4141

42-
// AWSMachine.Spec.Subnet.ARN and AWSMachine.Spec.AdditionalSecurityGroups.ARN has been removed in v1beta2, so setting it to nil in order to avoid v1beta1 --> v1beta2 --> v1beta1 round trip errors.
42+
// AWSMachine.Spec.FailureDomain, AWSMachine.Spec.Subnet.ARN and AWSMachine.Spec.AdditionalSecurityGroups.ARN has been removed in v1beta2, so setting it to nil in order to avoid v1beta1 --> v1beta2 --> v1beta1 round trip errors.
4343
if obj.Spec.Subnet != nil {
4444
obj.Spec.Subnet.ARN = nil
4545
}
@@ -49,6 +49,7 @@ func AWSMachineFuzzer(obj *AWSMachine, c fuzz.Continue) {
4949
restored = append(restored, sg)
5050
}
5151
obj.Spec.AdditionalSecurityGroups = restored
52+
obj.Spec.FailureDomain = nil
5253
}
5354

5455
func AWSMachineTemplateFuzzer(obj *AWSMachineTemplate, c fuzz.Continue) {
@@ -64,6 +65,7 @@ func AWSMachineTemplateFuzzer(obj *AWSMachineTemplate, c fuzz.Continue) {
6465
restored = append(restored, sg)
6566
}
6667
obj.Spec.Template.Spec.AdditionalSecurityGroups = restored
68+
obj.Spec.Template.Spec.FailureDomain = nil
6769
}
6870

6971
func TestFuzzyConversion(t *testing.T) {

api/v1beta1/zz_generated.conversion.go

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

api/v1beta2/awsmachine_types.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ type AWSMachineSpec struct {
105105
// +optional
106106
AdditionalSecurityGroups []AWSResourceReference `json:"additionalSecurityGroups,omitempty"`
107107

108-
// FailureDomain is the failure domain unique identifier this Machine should be attached to, as defined in Cluster API.
109-
// For this infrastructure provider, the ID is equivalent to an AWS Availability Zone.
110-
// If multiple subnets are matched for the availability zone, the first one returned is picked.
111-
FailureDomain *string `json:"failureDomain,omitempty"`
112-
113108
// Subnet is a reference to the subnet to use for this instance. If not specified,
114109
// the cluster subnet will be used.
115110
// +optional

api/v1beta2/zz_generated.deepcopy.go

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

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachines.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,6 @@ spec:
625625
- ssm-parameter-store
626626
type: string
627627
type: object
628-
failureDomain:
629-
description: FailureDomain is the failure domain unique identifier
630-
this Machine should be attached to, as defined in Cluster API. For
631-
this infrastructure provider, the ID is equivalent to an AWS Availability
632-
Zone. If multiple subnets are matched for the availability zone,
633-
the first one returned is picked.
634-
type: string
635628
iamInstanceProfile:
636629
description: IAMInstanceProfile is a name of an IAM instance profile
637630
to assign to the instance

config/crd/bases/infrastructure.cluster.x-k8s.io_awsmachinetemplates.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,6 @@ spec:
571571
- ssm-parameter-store
572572
type: string
573573
type: object
574-
failureDomain:
575-
description: FailureDomain is the failure domain unique identifier
576-
this Machine should be attached to, as defined in Cluster
577-
API. For this infrastructure provider, the ID is equivalent
578-
to an AWS Availability Zone. If multiple subnets are matched
579-
for the availability zone, the first one returned is picked.
580-
type: string
581574
iamInstanceProfile:
582575
description: IAMInstanceProfile is a name of an IAM instance
583576
profile to assign to the instance

pkg/cloud/services/ec2/instances.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ func (s *Service) CreateInstance(scope *scope.MachineScope, userData []byte, use
261261
func (s *Service) findSubnet(scope *scope.MachineScope) (string, error) {
262262
// Check Machine.Spec.FailureDomain first as it's used by KubeadmControlPlane to spread machines across failure domains.
263263
failureDomain := scope.Machine.Spec.FailureDomain
264-
if failureDomain == nil {
265-
failureDomain = scope.AWSMachine.Spec.FailureDomain
266-
}
267264

268265
// We basically have 2 sources for subnets:
269266
// 1. If subnet.id or subnet.filters are specified, we directly query AWS

pkg/cloud/services/ec2/instances_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,14 @@ func TestCreateInstance(t *testing.T) {
404404
Bootstrap: clusterv1.Bootstrap{
405405
DataSecretName: pointer.StringPtr("bootstrap-data"),
406406
},
407+
FailureDomain: aws.String("us-east-1c"),
407408
},
408409
},
409410
machineConfig: &infrav1.AWSMachineSpec{
410411
AMI: infrav1.AMIReference{
411412
ID: aws.String("abc"),
412413
},
413-
InstanceType: "m5.2xlarge",
414-
FailureDomain: aws.String("us-east-1c"),
414+
InstanceType: "m5.2xlarge",
415415
},
416416
awsCluster: &infrav1.AWSCluster{
417417
ObjectMeta: metav1.ObjectMeta{Name: "test"},
@@ -906,6 +906,7 @@ func TestCreateInstance(t *testing.T) {
906906
Bootstrap: clusterv1.Bootstrap{
907907
DataSecretName: pointer.StringPtr("bootstrap-data"),
908908
},
909+
FailureDomain: aws.String("us-east-1b"),
909910
},
910911
},
911912
machineConfig: &infrav1.AWSMachineSpec{
@@ -919,7 +920,6 @@ func TestCreateInstance(t *testing.T) {
919920
Values: []string{"some-value"},
920921
}},
921922
},
922-
FailureDomain: aws.String("us-east-1b"),
923923
},
924924
awsCluster: &infrav1.AWSCluster{
925925
ObjectMeta: metav1.ObjectMeta{Name: "test"},
@@ -1300,6 +1300,7 @@ func TestCreateInstance(t *testing.T) {
13001300
Bootstrap: clusterv1.Bootstrap{
13011301
DataSecretName: pointer.StringPtr("bootstrap-data"),
13021302
},
1303+
FailureDomain: aws.String("us-east-1b"),
13031304
},
13041305
},
13051306
machineConfig: &infrav1.AWSMachineSpec{
@@ -1310,7 +1311,6 @@ func TestCreateInstance(t *testing.T) {
13101311
Subnet: &infrav1.AWSResourceReference{
13111312
ID: aws.String("subnet-1"),
13121313
},
1313-
FailureDomain: aws.String("us-east-1b"),
13141314
},
13151315
awsCluster: &infrav1.AWSCluster{
13161316
ObjectMeta: metav1.ObjectMeta{Name: "test"},
@@ -1381,15 +1381,15 @@ func TestCreateInstance(t *testing.T) {
13811381
Bootstrap: clusterv1.Bootstrap{
13821382
DataSecretName: pointer.StringPtr("bootstrap-data"),
13831383
},
1384+
FailureDomain: aws.String("us-east-1b"),
13841385
},
13851386
},
13861387
machineConfig: &infrav1.AWSMachineSpec{
13871388
AMI: infrav1.AMIReference{
13881389
ID: aws.String("abc"),
13891390
},
1390-
InstanceType: "m5.large",
1391-
FailureDomain: aws.String("us-east-1b"),
1392-
PublicIP: aws.Bool(true),
1391+
InstanceType: "m5.large",
1392+
PublicIP: aws.Bool(true),
13931393
},
13941394
awsCluster: &infrav1.AWSCluster{
13951395
ObjectMeta: metav1.ObjectMeta{Name: "test"},

test/e2e/data/infrastructure-aws/withclusterclass/clusterclassbase/clusterclass-ci-default.yaml

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,9 @@ spec:
262262
valueFrom:
263263
template: |
264264
- id: "{{ .publicSubnetID }}"
265+
availabilityZone: "{{ .fdForBYOSubnets }}"
265266
- id: "{{ .privateSubnetID }}"
266-
- name: awsMachineTemplateControlPlaneForBYO
267-
enabledIf: '{{ eq .byoInfra "true" }}'
268-
definitions:
269-
- selector:
270-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
271-
kind: AWSMachineTemplate
272-
matchResources:
273-
controlPlane: true
274-
jsonPatches:
275-
- op: add
276-
path: "/spec/template/spec/failureDomain"
277-
valueFrom:
278-
variable: fdForBYOSubnets
279-
- name: awsMachineTemplateWorkerForBYO
280-
enabledIf: '{{ eq .byoInfra "true" }}'
281-
definitions:
282-
- selector:
283-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
284-
kind: AWSMachineTemplate
285-
matchResources:
286-
machineDeploymentClass:
287-
names:
288-
- default-worker
289-
jsonPatches:
290-
- op: add
291-
path: "/spec/template/spec/failureDomain"
292-
valueFrom:
293-
variable: fdForBYOSubnets
267+
availabilityZone: "{{ .fdForBYOSubnets }}"
294268
---
295269
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
296270
kind: AWSClusterTemplate

test/e2e/data/infrastructure-aws/withclusterclass/kustomize_sources/topology/clusterclass-ci-default.yaml

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,9 @@ spec:
262262
valueFrom:
263263
template: |
264264
- id: "{{ .publicSubnetID }}"
265+
availabilityZone: "{{ .fdForBYOSubnets }}"
265266
- id: "{{ .privateSubnetID }}"
266-
- name: awsMachineTemplateControlPlaneForBYO
267-
enabledIf: '{{ eq .byoInfra "true" }}'
268-
definitions:
269-
- selector:
270-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
271-
kind: AWSMachineTemplate
272-
matchResources:
273-
controlPlane: true
274-
jsonPatches:
275-
- op: add
276-
path: "/spec/template/spec/failureDomain"
277-
valueFrom:
278-
variable: fdForBYOSubnets
279-
- name: awsMachineTemplateWorkerForBYO
280-
enabledIf: '{{ eq .byoInfra "true" }}'
281-
definitions:
282-
- selector:
283-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
284-
kind: AWSMachineTemplate
285-
matchResources:
286-
machineDeploymentClass:
287-
names:
288-
- default-worker
289-
jsonPatches:
290-
- op: add
291-
path: "/spec/template/spec/failureDomain"
292-
valueFrom:
293-
variable: fdForBYOSubnets
267+
availabilityZone: "{{ .fdForBYOSubnets }}"
294268
---
295269
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
296270
kind: AWSClusterTemplate

test/e2e/data/infrastructure-aws/withoutclusterclass/e2e_test_templates/cluster-template-internal-elb.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ metadata:
7676
spec:
7777
template:
7878
spec:
79-
failureDomain: us-west-2a
8079
iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io
8180
instanceType: ${AWS_CONTROL_PLANE_MACHINE_TYPE}
8281
sshKeyName: ${AWS_SSH_KEY_NAME}
@@ -98,6 +97,7 @@ spec:
9897
kind: KubeadmConfigTemplate
9998
name: ${CLUSTER_NAME}-md-0
10099
clusterName: ${CLUSTER_NAME}
100+
failureDomain: us-west-2a
101101
infrastructureRef:
102102
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
103103
kind: AWSMachineTemplate
@@ -111,7 +111,6 @@ metadata:
111111
spec:
112112
template:
113113
spec:
114-
failureDomain: us-west-2a
115114
iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io
116115
instanceType: ${AWS_NODE_MACHINE_TYPE}
117116
sshKeyName: ${AWS_SSH_KEY_NAME}

test/e2e/data/infrastructure-aws/withoutclusterclass/e2e_test_templates/cluster-template-peered-remote.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ spec:
111111
kind: KubeadmConfigTemplate
112112
name: ${CLUSTER_NAME}-md-0
113113
clusterName: ${CLUSTER_NAME}
114+
failureDomain: us-west-2a
114115
infrastructureRef:
115116
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
116117
kind: AWSMachineTemplate
@@ -124,7 +125,6 @@ metadata:
124125
spec:
125126
template:
126127
spec:
127-
failureDomain: us-west-2a
128128
iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io
129129
instanceType: ${AWS_NODE_MACHINE_TYPE}
130130
sshKeyName: ${AWS_SSH_KEY_NAME}

test/e2e/data/infrastructure-aws/withoutclusterclass/kustomize_sources/internal-elb/patches/az-select.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ spec:
1515
template:
1616
spec:
1717
failureDomain: "us-west-2a"
18-

test/e2e/data/infrastructure-aws/withoutclusterclass/kustomize_sources/internal-elb/patches/internal-elb.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ spec:
1010
id: "${WL_VPC_ID}"
1111
subnets:
1212
- id: "${WL_PRIVATE_SUBNET_ID}"
13-

test/e2e/data/infrastructure-aws/withoutclusterclass/kustomize_sources/peered-remote/patches/az-select.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ spec:
1515
template:
1616
spec:
1717
failureDomain: "us-west-2a"
18-
19-

test/e2e/suites/unmanaged/helpers_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ func getAWSMachinesForDeployment(namespace string, machineDeployment clusterv1.M
460460
return awsMachineList
461461
}
462462

463-
func makeAWSMachineTemplate(namespace, name, instanceType string, az, subnetID *string) *infrav1.AWSMachineTemplate {
463+
func makeAWSMachineTemplate(namespace, name, instanceType string, subnetID *string) *infrav1.AWSMachineTemplate {
464464
awsMachine := &infrav1.AWSMachineTemplate{
465465
ObjectMeta: metav1.ObjectMeta{
466466
Name: name,
@@ -476,9 +476,6 @@ func makeAWSMachineTemplate(namespace, name, instanceType string, az, subnetID *
476476
},
477477
},
478478
}
479-
if az != nil {
480-
awsMachine.Spec.Template.Spec.FailureDomain = az
481-
}
482479

483480
if subnetID != nil {
484481
resRef := &infrav1.AWSResourceReference{
@@ -511,8 +508,8 @@ func makeJoinBootstrapConfigTemplate(namespace, name string) *bootstrapv1.Kubead
511508
}
512509
}
513510

514-
func makeMachineDeployment(namespace, mdName, clusterName string, replicas int32) *clusterv1.MachineDeployment {
515-
return &clusterv1.MachineDeployment{
511+
func makeMachineDeployment(namespace, mdName, clusterName string, az *string, replicas int32) *clusterv1.MachineDeployment {
512+
machineDeployment := &clusterv1.MachineDeployment{
516513
ObjectMeta: metav1.ObjectMeta{
517514
Name: mdName,
518515
Namespace: namespace,
@@ -558,6 +555,10 @@ func makeMachineDeployment(namespace, mdName, clusterName string, replicas int32
558555
},
559556
},
560557
}
558+
if az != nil {
559+
machineDeployment.Spec.Template.Spec.FailureDomain = az
560+
}
561+
return machineDeployment
561562
}
562563

563564
func assertSpotInstanceType(instanceID string) {

0 commit comments

Comments
 (0)