Skip to content

Commit

Permalink
Merge pull request #4664 from MaxFedotov/issues/4653
Browse files Browse the repository at this point in the history
✨ feat: support setting HostnameType options for subnets and machines
  • Loading branch information
k8s-ci-robot authored Jan 29, 2024
2 parents ccd5e16 + d6b1fc2 commit 836e77c
Show file tree
Hide file tree
Showing 24 changed files with 381 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api/v1beta1/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
if restored.Status.Bastion != nil {
dst.Status.Bastion.InstanceMetadataOptions = restored.Status.Bastion.InstanceMetadataOptions
dst.Status.Bastion.PlacementGroupName = restored.Status.Bastion.PlacementGroupName
dst.Status.Bastion.PrivateDNSName = restored.Status.Bastion.PrivateDNSName
}
dst.Spec.Partition = restored.Spec.Partition

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

dst.Spec.NetworkSpec.VPC.EmptyRoutesDefaultVPCSecurityGroup = restored.Spec.NetworkSpec.VPC.EmptyRoutesDefaultVPCSecurityGroup
dst.Spec.NetworkSpec.VPC.PrivateDNSHostnameTypeOnLaunch = restored.Spec.NetworkSpec.VPC.PrivateDNSHostnameTypeOnLaunch

// Restore SubnetSpec.ResourceID field, if any.
for _, subnet := range restored.Spec.NetworkSpec.Subnets {
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/awsmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func (src *AWSMachine) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Ignition = restored.Spec.Ignition
dst.Spec.InstanceMetadataOptions = restored.Spec.InstanceMetadataOptions
dst.Spec.PlacementGroupName = restored.Spec.PlacementGroupName
dst.Spec.PrivateDNSName = restored.Spec.PrivateDNSName

return nil
}
Expand Down Expand Up @@ -85,6 +86,7 @@ func (r *AWSMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.Template.Spec.Ignition = restored.Spec.Template.Spec.Ignition
dst.Spec.Template.Spec.InstanceMetadataOptions = restored.Spec.Template.Spec.InstanceMetadataOptions
dst.Spec.Template.Spec.PlacementGroupName = restored.Spec.Template.Spec.PlacementGroupName
dst.Spec.Template.Spec.PrivateDNSName = restored.Spec.Template.Spec.PrivateDNSName

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/v1beta2/awsmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ type AWSMachineSpec struct {
// +optional
// +kubebuilder:validation:Enum:=default;dedicated;host
Tenancy string `json:"tenancy,omitempty"`

// PrivateDNSName is the options for the instance hostname.
// +optional
PrivateDNSName *PrivateDNSName `json:"privateDnsName,omitempty"`
}

// CloudInit defines options related to the bootstrapping systems where
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta2/awsmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ func (r *AWSMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, err
delete(cloudInit, "secureSecretsBackend")
}

// allow changes to enableResourceNameDNSAAAARecord and enableResourceNameDNSARecord
if privateDNSName, ok := oldAWSMachineSpec["privateDnsName"].(map[string]interface{}); ok {
delete(privateDNSName, "enableResourceNameDnsAAAARecord")
delete(privateDNSName, "enableResourceNameDnsARecord")
}

if privateDNSName, ok := newAWSMachineSpec["privateDnsName"].(map[string]interface{}); ok {
delete(privateDNSName, "enableResourceNameDnsAAAARecord")
delete(privateDNSName, "enableResourceNameDnsARecord")
}

if !cmp.Equal(oldAWSMachineSpec, newAWSMachineSpec) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "cannot be modified"))
}
Expand Down
6 changes: 5 additions & 1 deletion api/v1beta2/awsmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestAWSMachineUpdate(t *testing.T) {
wantErr bool
}{
{
name: "change in providerid, cloudinit, tags and securitygroups",
name: "change in providerid, cloudinit, tags, securitygroups",
oldMachine: &AWSMachine{
Spec: AWSMachineSpec{
ProviderID: nil,
Expand Down Expand Up @@ -325,6 +325,10 @@ func TestAWSMachineUpdate(t *testing.T) {
ID: ptr.To[string]("ID"),
},
},
PrivateDNSName: &PrivateDNSName{
EnableResourceNameDNSAAAARecord: aws.Bool(true),
EnableResourceNameDNSARecord: aws.Bool(true),
},
},
},
wantErr: true,
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta2/network_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ type VPCSpec struct {
//
// +optional
EmptyRoutesDefaultVPCSecurityGroup bool `json:"emptyRoutesDefaultVPCSecurityGroup,omitempty"`

// PrivateDNSHostnameTypeOnLaunch is the type of hostname to assign to instances in the subnet at launch.
// For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an instance DNS name can be based on the instance IPv4 address (ip-name)
// or the instance ID (resource-name). For IPv6 only subnets, an instance DNS name must be based on the instance ID (resource-name).
// +optional
// +kubebuilder:validation:Enum:=ip-name;resource-name
PrivateDNSHostnameTypeOnLaunch *string `json:"privateDnsHostnameTypeOnLaunch,omitempty"`
}

// String returns a string representation of the VPC.
Expand Down
18 changes: 18 additions & 0 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ type Instance struct {
// InstanceMetadataOptions is the metadata options for the EC2 instance.
// +optional
InstanceMetadataOptions *InstanceMetadataOptions `json:"instanceMetadataOptions,omitempty"`

// PrivateDNSName is the options for the instance hostname.
// +optional
PrivateDNSName *PrivateDNSName `json:"privateDnsName,omitempty"`
}

// InstanceMetadataState describes the state of InstanceMetadataOptions.HttpEndpoint and InstanceMetadataOptions.InstanceMetadataTags
Expand Down Expand Up @@ -407,3 +411,17 @@ const (
// AmazonLinuxGPU is the AmazonLinux GPU AMI type.
AmazonLinuxGPU EKSAMILookupType = "AmazonLinuxGPU"
)

// PrivateDNSName is the options for the instance hostname.
type PrivateDNSName struct {
// EnableResourceNameDNSAAAARecord indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.
// +optional
EnableResourceNameDNSAAAARecord *bool `json:"enableResourceNameDnsAAAARecord,omitempty"`
// EnableResourceNameDNSARecord indicates whether to respond to DNS queries for instance hostnames with DNS A records.
// +optional
EnableResourceNameDNSARecord *bool `json:"enableResourceNameDnsARecord,omitempty"`
// The type of hostname to assign to an instance.
// +optional
// +kubebuilder:validation:Enum:=ip-name;resource-name
HostnameType *string `json:"hostnameType,omitempty"`
}
45 changes: 45 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,18 @@ spec:
is set. Mutually exclusive with IPAMPool.
type: string
type: object
privateDnsHostnameTypeOnLaunch:
description: PrivateDNSHostnameTypeOnLaunch is the type of
hostname to assign to instances in the subnet at launch.
For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an
instance DNS name can be based on the instance IPv4 address
(ip-name) or the instance ID (resource-name). For IPv6 only
subnets, an instance DNS name must be based on the instance
ID (resource-name).
enum:
- ip-name
- resource-name
type: string
tags:
additionalProperties:
type: string
Expand Down Expand Up @@ -1096,6 +1108,26 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
enableResourceNameDnsAAAARecord:
description: EnableResourceNameDNSAAAARecord indicates whether
to respond to DNS queries for instance hostnames with DNS
AAAA records.
type: boolean
enableResourceNameDnsARecord:
description: EnableResourceNameDNSARecord indicates whether
to respond to DNS queries for instance hostnames with DNS
A records.
type: boolean
hostnameType:
description: The type of hostname to assign to an instance.
enum:
- ip-name
- resource-name
type: string
type: object
privateIp:
description: The private IPv4 address assigned to the instance.
type: string
Expand Down Expand Up @@ -2244,6 +2276,18 @@ spec:
is set. Mutually exclusive with IPAMPool.
type: string
type: object
privateDnsHostnameTypeOnLaunch:
description: PrivateDNSHostnameTypeOnLaunch is the type of
hostname to assign to instances in the subnet at launch.
For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an
instance DNS name can be based on the instance IPv4 address
(ip-name) or the instance ID (resource-name). For IPv6 only
subnets, an instance DNS name must be based on the instance
ID (resource-name).
enum:
- ip-name
- resource-name
type: string
tags:
additionalProperties:
type: string
Expand Down Expand Up @@ -2706,6 +2750,26 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
enableResourceNameDnsAAAARecord:
description: EnableResourceNameDNSAAAARecord indicates whether
to respond to DNS queries for instance hostnames with DNS
AAAA records.
type: boolean
enableResourceNameDnsARecord:
description: EnableResourceNameDNSARecord indicates whether
to respond to DNS queries for instance hostnames with DNS
A records.
type: boolean
hostnameType:
description: The type of hostname to assign to an instance.
enum:
- ip-name
- resource-name
type: string
type: object
privateIp:
description: The private IPv4 address assigned to the instance.
type: string
Expand Down
32 changes: 32 additions & 0 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_awsclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,18 @@ spec:
is set. Mutually exclusive with IPAMPool.
type: string
type: object
privateDnsHostnameTypeOnLaunch:
description: PrivateDNSHostnameTypeOnLaunch is the type of
hostname to assign to instances in the subnet at launch.
For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an
instance DNS name can be based on the instance IPv4 address
(ip-name) or the instance ID (resource-name). For IPv6 only
subnets, an instance DNS name must be based on the instance
ID (resource-name).
enum:
- ip-name
- resource-name
type: string
tags:
additionalProperties:
type: string
Expand Down Expand Up @@ -1687,6 +1699,26 @@ spec:
description: PlacementGroupName specifies the name of the placement
group in which to launch the instance.
type: string
privateDnsName:
description: PrivateDNSName is the options for the instance hostname.
properties:
enableResourceNameDnsAAAARecord:
description: EnableResourceNameDNSAAAARecord indicates whether
to respond to DNS queries for instance hostnames with DNS
AAAA records.
type: boolean
enableResourceNameDnsARecord:
description: EnableResourceNameDNSARecord indicates whether
to respond to DNS queries for instance hostnames with DNS
A records.
type: boolean
hostnameType:
description: The type of hostname to assign to an instance.
enum:
- ip-name
- resource-name
type: string
type: object
privateIp:
description: The private IPv4 address assigned to the instance.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,18 @@ spec:
with IPAMPool.
type: string
type: object
privateDnsHostnameTypeOnLaunch:
description: PrivateDNSHostnameTypeOnLaunch is the
type of hostname to assign to instances in the subnet
at launch. For IPv4-only and dual-stack (IPv4 and
IPv6) subnets, an instance DNS name can be based
on the instance IPv4 address (ip-name) or the instance
ID (resource-name). For IPv6 only subnets, an instance
DNS name must be based on the instance ID (resource-name).
enum:
- ip-name
- resource-name
type: string
tags:
additionalProperties:
type: string
Expand Down
Loading

0 comments on commit 836e77c

Please sign in to comment.