Skip to content

Commit 836e77c

Browse files
authored
Merge pull request #4664 from MaxFedotov/issues/4653
✨ feat: support setting HostnameType options for subnets and machines
2 parents ccd5e16 + d6b1fc2 commit 836e77c

24 files changed

+381
-5
lines changed

api/v1beta1/awscluster_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
4848
if restored.Status.Bastion != nil {
4949
dst.Status.Bastion.InstanceMetadataOptions = restored.Status.Bastion.InstanceMetadataOptions
5050
dst.Status.Bastion.PlacementGroupName = restored.Status.Bastion.PlacementGroupName
51+
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
5152
}
5253
dst.Spec.Partition = restored.Spec.Partition
5354

@@ -91,6 +92,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
9192
}
9293

9394
dst.Spec.NetworkSpec.VPC.EmptyRoutesDefaultVPCSecurityGroup = restored.Spec.NetworkSpec.VPC.EmptyRoutesDefaultVPCSecurityGroup
95+
dst.Spec.NetworkSpec.VPC.PrivateDNSHostnameTypeOnLaunch = restored.Spec.NetworkSpec.VPC.PrivateDNSHostnameTypeOnLaunch
9496

9597
// Restore SubnetSpec.ResourceID field, if any.
9698
for _, subnet := range restored.Spec.NetworkSpec.Subnets {

api/v1beta1/awsmachine_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
3838
dst.Spec.Ignition = restored.Spec.Ignition
3939
dst.Spec.InstanceMetadataOptions = restored.Spec.InstanceMetadataOptions
4040
dst.Spec.PlacementGroupName = restored.Spec.PlacementGroupName
41+
dst.Spec.PrivateDNSName = restored.Spec.PrivateDNSName
4142

4243
return nil
4344
}
@@ -85,6 +86,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
8586
dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
8687
dst.Spec.Template.Spec.InstanceMetadataOptions = restored.Spec.Template.Spec.InstanceMetadataOptions
8788
dst.Spec.Template.Spec.PlacementGroupName = restored.Spec.Template.Spec.PlacementGroupName
89+
dst.Spec.Template.Spec.PrivateDNSName = restored.Spec.Template.Spec.PrivateDNSName
8890

8991
return nil
9092
}

api/v1beta1/zz_generated.conversion.go

Lines changed: 3 additions & 0 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ type AWSMachineSpec struct {
160160
// +optional
161161
// +kubebuilder:validation:Enum:=default;dedicated;host
162162
Tenancy string `json:"tenancy,omitempty"`
163+
164+
// PrivateDNSName is the options for the instance hostname.
165+
// +optional
166+
PrivateDNSName *PrivateDNSName `json:"privateDnsName,omitempty"`
163167
}
164168

165169
// CloudInit defines options related to the bootstrapping systems where

api/v1beta2/awsmachine_webhook.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ func (r *AWSMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, err
114114
delete(cloudInit, "secureSecretsBackend")
115115
}
116116

117+
// allow changes to enableResourceNameDNSAAAARecord and enableResourceNameDNSARecord
118+
if privateDNSName, ok := oldAWSMachineSpec["privateDnsName"].(map[string]interface{}); ok {
119+
delete(privateDNSName, "enableResourceNameDnsAAAARecord")
120+
delete(privateDNSName, "enableResourceNameDnsARecord")
121+
}
122+
123+
if privateDNSName, ok := newAWSMachineSpec["privateDnsName"].(map[string]interface{}); ok {
124+
delete(privateDNSName, "enableResourceNameDnsAAAARecord")
125+
delete(privateDNSName, "enableResourceNameDnsARecord")
126+
}
127+
117128
if !cmp.Equal(oldAWSMachineSpec, newAWSMachineSpec) {
118129
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
119130
}

api/v1beta2/awsmachine_webhook_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ func TestAWSMachineUpdate(t *testing.T) {
273273
wantErr bool
274274
}{
275275
{
276-
name: "change in providerid, cloudinit, tags and securitygroups",
276+
name: "change in providerid, cloudinit, tags, securitygroups",
277277
oldMachine: &AWSMachine{
278278
Spec: AWSMachineSpec{
279279
ProviderID: nil,
@@ -325,6 +325,10 @@ func TestAWSMachineUpdate(t *testing.T) {
325325
ID: ptr.To[string]("ID"),
326326
},
327327
},
328+
PrivateDNSName: &PrivateDNSName{
329+
EnableResourceNameDNSAAAARecord: aws.Bool(true),
330+
EnableResourceNameDNSARecord: aws.Bool(true),
331+
},
328332
},
329333
},
330334
wantErr: true,

api/v1beta2/network_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ type VPCSpec struct {
335335
//
336336
// +optional
337337
EmptyRoutesDefaultVPCSecurityGroup bool `json:"emptyRoutesDefaultVPCSecurityGroup,omitempty"`
338+
339+
// PrivateDNSHostnameTypeOnLaunch is the type of hostname to assign to instances in the subnet at launch.
340+
// For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an instance DNS name can be based on the instance IPv4 address (ip-name)
341+
// or the instance ID (resource-name). For IPv6 only subnets, an instance DNS name must be based on the instance ID (resource-name).
342+
// +optional
343+
// +kubebuilder:validation:Enum:=ip-name;resource-name
344+
PrivateDNSHostnameTypeOnLaunch *string `json:"privateDnsHostnameTypeOnLaunch,omitempty"`
338345
}
339346

340347
// String returns a string representation of the VPC.

api/v1beta2/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ type Instance struct {
232232
// InstanceMetadataOptions is the metadata options for the EC2 instance.
233233
// +optional
234234
InstanceMetadataOptions *InstanceMetadataOptions `json:"instanceMetadataOptions,omitempty"`
235+
236+
// PrivateDNSName is the options for the instance hostname.
237+
// +optional
238+
PrivateDNSName *PrivateDNSName `json:"privateDnsName,omitempty"`
235239
}
236240

237241
// InstanceMetadataState describes the state of InstanceMetadataOptions.HttpEndpoint and InstanceMetadataOptions.InstanceMetadataTags
@@ -407,3 +411,17 @@ const (
407411
// AmazonLinuxGPU is the AmazonLinux GPU AMI type.
408412
AmazonLinuxGPU EKSAMILookupType = "AmazonLinuxGPU"
409413
)
414+
415+
// PrivateDNSName is the options for the instance hostname.
416+
type PrivateDNSName struct {
417+
// EnableResourceNameDNSAAAARecord indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.
418+
// +optional
419+
EnableResourceNameDNSAAAARecord *bool `json:"enableResourceNameDnsAAAARecord,omitempty"`
420+
// EnableResourceNameDNSARecord indicates whether to respond to DNS queries for instance hostnames with DNS A records.
421+
// +optional
422+
EnableResourceNameDNSARecord *bool `json:"enableResourceNameDnsARecord,omitempty"`
423+
// The type of hostname to assign to an instance.
424+
// +optional
425+
// +kubebuilder:validation:Enum:=ip-name;resource-name
426+
HostnameType *string `json:"hostnameType,omitempty"`
427+
}

api/v1beta2/zz_generated.deepcopy.go

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

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,18 @@ spec:
647647
is set. Mutually exclusive with IPAMPool.
648648
type: string
649649
type: object
650+
privateDnsHostnameTypeOnLaunch:
651+
description: PrivateDNSHostnameTypeOnLaunch is the type of
652+
hostname to assign to instances in the subnet at launch.
653+
For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an
654+
instance DNS name can be based on the instance IPv4 address
655+
(ip-name) or the instance ID (resource-name). For IPv6 only
656+
subnets, an instance DNS name must be based on the instance
657+
ID (resource-name).
658+
enum:
659+
- ip-name
660+
- resource-name
661+
type: string
650662
tags:
651663
additionalProperties:
652664
type: string
@@ -1096,6 +1108,26 @@ spec:
10961108
description: PlacementGroupName specifies the name of the placement
10971109
group in which to launch the instance.
10981110
type: string
1111+
privateDnsName:
1112+
description: PrivateDNSName is the options for the instance hostname.
1113+
properties:
1114+
enableResourceNameDnsAAAARecord:
1115+
description: EnableResourceNameDNSAAAARecord indicates whether
1116+
to respond to DNS queries for instance hostnames with DNS
1117+
AAAA records.
1118+
type: boolean
1119+
enableResourceNameDnsARecord:
1120+
description: EnableResourceNameDNSARecord indicates whether
1121+
to respond to DNS queries for instance hostnames with DNS
1122+
A records.
1123+
type: boolean
1124+
hostnameType:
1125+
description: The type of hostname to assign to an instance.
1126+
enum:
1127+
- ip-name
1128+
- resource-name
1129+
type: string
1130+
type: object
10991131
privateIp:
11001132
description: The private IPv4 address assigned to the instance.
11011133
type: string
@@ -2244,6 +2276,18 @@ spec:
22442276
is set. Mutually exclusive with IPAMPool.
22452277
type: string
22462278
type: object
2279+
privateDnsHostnameTypeOnLaunch:
2280+
description: PrivateDNSHostnameTypeOnLaunch is the type of
2281+
hostname to assign to instances in the subnet at launch.
2282+
For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an
2283+
instance DNS name can be based on the instance IPv4 address
2284+
(ip-name) or the instance ID (resource-name). For IPv6 only
2285+
subnets, an instance DNS name must be based on the instance
2286+
ID (resource-name).
2287+
enum:
2288+
- ip-name
2289+
- resource-name
2290+
type: string
22472291
tags:
22482292
additionalProperties:
22492293
type: string
@@ -2706,6 +2750,26 @@ spec:
27062750
description: PlacementGroupName specifies the name of the placement
27072751
group in which to launch the instance.
27082752
type: string
2753+
privateDnsName:
2754+
description: PrivateDNSName is the options for the instance hostname.
2755+
properties:
2756+
enableResourceNameDnsAAAARecord:
2757+
description: EnableResourceNameDNSAAAARecord indicates whether
2758+
to respond to DNS queries for instance hostnames with DNS
2759+
AAAA records.
2760+
type: boolean
2761+
enableResourceNameDnsARecord:
2762+
description: EnableResourceNameDNSARecord indicates whether
2763+
to respond to DNS queries for instance hostnames with DNS
2764+
A records.
2765+
type: boolean
2766+
hostnameType:
2767+
description: The type of hostname to assign to an instance.
2768+
enum:
2769+
- ip-name
2770+
- resource-name
2771+
type: string
2772+
type: object
27092773
privateIp:
27102774
description: The private IPv4 address assigned to the instance.
27112775
type: string

0 commit comments

Comments
 (0)