Skip to content

Commit 1f6e295

Browse files
committed
ec2: support option HTTPProtocolIPv6 for EC2 IMDS
The httpProtocolIPv6 field enables or disables the IPv6 endpoint of the instance metadata service. The SDK only applies this field if httpEndpoint is enabled. When running on single-stack IPv6, pods only have IPv6, thus requiring an IPv6 endpoint to query IMDS as IPv4 network is unreachable.
1 parent 1496b34 commit 1f6e295

11 files changed

+100
-0
lines changed

api/v1beta2/awsmachinetemplate_webhook_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func TestAWSMachineTemplateValidateUpdate(t *testing.T) {
127127
InstanceType: "test",
128128
InstanceMetadataOptions: &InstanceMetadataOptions{
129129
HTTPEndpoint: InstanceMetadataEndpointStateEnabled,
130+
HTTPProtocolIPv6: InstanceMetadataEndpointStateDisabled,
130131
HTTPPutResponseHopLimit: 1,
131132
HTTPTokens: HTTPTokensStateOptional,
132133
InstanceMetadataTags: InstanceMetadataEndpointStateDisabled,

api/v1beta2/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,15 @@ type InstanceMetadataOptions struct {
360360
// +kubebuilder:default=enabled
361361
HTTPEndpoint InstanceMetadataState `json:"httpEndpoint,omitempty"`
362362

363+
// Enables or disables the IPv6 endpoint for the instance metadata service.
364+
// This applies only if you enabled the HTTP metadata endpoint.
365+
//
366+
// Default: disabled
367+
//
368+
// +kubebuilder:validation:Enum:=enabled;disabled
369+
// +kubebuilder:default=disabled
370+
HTTPProtocolIPv6 InstanceMetadataState `json:"httpProtocolIpv6,omitempty"`
371+
363372
// The desired HTTP PUT response hop limit for instance metadata requests. The
364373
// larger the number, the further instance metadata requests can travel.
365374
//
@@ -406,6 +415,9 @@ func (obj *InstanceMetadataOptions) SetDefaults() {
406415
if obj.HTTPEndpoint == "" {
407416
obj.HTTPEndpoint = InstanceMetadataEndpointStateEnabled
408417
}
418+
if obj.HTTPProtocolIPv6 == "" {
419+
obj.HTTPProtocolIPv6 = InstanceMetadataEndpointStateDisabled
420+
}
409421
if obj.HTTPPutResponseHopLimit == 0 {
410422
obj.HTTPPutResponseHopLimit = 1
411423
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,17 @@ spec:
12771277
- enabled
12781278
- disabled
12791279
type: string
1280+
httpProtocolIpv6:
1281+
default: disabled
1282+
description: |-
1283+
Enables or disables the IPv6 endpoint for the instance metadata service.
1284+
This applies only if you enabled the HTTP metadata endpoint.
1285+
1286+
Default: disabled
1287+
enum:
1288+
- enabled
1289+
- disabled
1290+
type: string
12801291
httpPutResponseHopLimit:
12811292
default: 1
12821293
description: |-
@@ -3489,6 +3500,17 @@ spec:
34893500
- enabled
34903501
- disabled
34913502
type: string
3503+
httpProtocolIpv6:
3504+
default: disabled
3505+
description: |-
3506+
Enables or disables the IPv6 endpoint for the instance metadata service.
3507+
This applies only if you enabled the HTTP metadata endpoint.
3508+
3509+
Default: disabled
3510+
enum:
3511+
- enabled
3512+
- disabled
3513+
type: string
34923514
httpPutResponseHopLimit:
34933515
default: 1
34943516
description: |-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,17 @@ spec:
22592259
- enabled
22602260
- disabled
22612261
type: string
2262+
httpProtocolIpv6:
2263+
default: disabled
2264+
description: |-
2265+
Enables or disables the IPv6 endpoint for the instance metadata service.
2266+
This applies only if you enabled the HTTP metadata endpoint.
2267+
2268+
Default: disabled
2269+
enum:
2270+
- enabled
2271+
- disabled
2272+
type: string
22622273
httpPutResponseHopLimit:
22632274
default: 1
22642275
description: |-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,17 @@ spec:
707707
- enabled
708708
- disabled
709709
type: string
710+
httpProtocolIpv6:
711+
default: disabled
712+
description: |-
713+
Enables or disables the IPv6 endpoint for the instance metadata service.
714+
This applies only if you enabled the HTTP metadata endpoint.
715+
716+
Default: disabled
717+
enum:
718+
- enabled
719+
- disabled
720+
type: string
710721
httpPutResponseHopLimit:
711722
default: 1
712723
description: |-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,17 @@ spec:
876876
- enabled
877877
- disabled
878878
type: string
879+
httpProtocolIpv6:
880+
default: disabled
881+
description: |-
882+
Enables or disables the IPv6 endpoint for the instance metadata service.
883+
This applies only if you enabled the HTTP metadata endpoint.
884+
885+
Default: disabled
886+
enum:
887+
- enabled
888+
- disabled
889+
type: string
879890
httpPutResponseHopLimit:
880891
default: 1
881892
description: |-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,17 @@ spec:
795795
- enabled
796796
- disabled
797797
type: string
798+
httpProtocolIpv6:
799+
default: disabled
800+
description: |-
801+
Enables or disables the IPv6 endpoint for the instance metadata service.
802+
This applies only if you enabled the HTTP metadata endpoint.
803+
804+
Default: disabled
805+
enum:
806+
- enabled
807+
- disabled
808+
type: string
798809
httpPutResponseHopLimit:
799810
default: 1
800811
description: |-

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,17 @@ spec:
716716
- enabled
717717
- disabled
718718
type: string
719+
httpProtocolIpv6:
720+
default: disabled
721+
description: |-
722+
Enables or disables the IPv6 endpoint for the instance metadata service.
723+
This applies only if you enabled the HTTP metadata endpoint.
724+
725+
Default: disabled
726+
enum:
727+
- enabled
728+
- disabled
729+
type: string
719730
httpPutResponseHopLimit:
720731
default: 1
721732
description: |-

controllers/awsmachine_controller_unit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,7 @@ func TestAWSMachineReconcilerReconcileDefaultsToLoadBalancerTypeClassic(t *testi
27332733
},
27342734
MetadataOptions: &ec2types.InstanceMetadataOptionsResponse{
27352735
HttpEndpoint: ec2types.InstanceMetadataEndpointState(string(infrav1.InstanceMetadataEndpointStateEnabled)),
2736+
HttpProtocolIpv6: ec2types.InstanceMetadataProtocolState(string(infrav1.InstanceMetadataEndpointStateDisabled)),
27362737
HttpPutResponseHopLimit: aws.Int32(1),
27372738
HttpTokens: ec2types.HttpTokensState(string(infrav1.HTTPTokensStateOptional)),
27382739
InstanceMetadataTags: ec2types.InstanceMetadataTagsState(string(infrav1.InstanceMetadataEndpointStateDisabled)),

pkg/cloud/services/ec2/instances.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ func (s *Service) SDKToInstance(v types.Instance) (*infrav1.Instance, error) {
962962
metadataOptions.HTTPEndpoint = infrav1.InstanceMetadataState(string(v.MetadataOptions.HttpEndpoint))
963963
metadataOptions.HTTPTokens = infrav1.HTTPTokensState(string(v.MetadataOptions.HttpTokens))
964964
metadataOptions.InstanceMetadataTags = infrav1.InstanceMetadataState(string(v.MetadataOptions.InstanceMetadataTags))
965+
metadataOptions.HTTPProtocolIPv6 = infrav1.InstanceMetadataState(v.MetadataOptions.HttpProtocolIpv6)
965966
if v.MetadataOptions.HttpPutResponseHopLimit != nil {
966967
metadataOptions.HTTPPutResponseHopLimit = int64(*v.MetadataOptions.HttpPutResponseHopLimit)
967968
}
@@ -1117,6 +1118,7 @@ func (s *Service) ModifyInstanceMetadataOptions(instanceID string, options *infr
11171118
HttpPutResponseHopLimit: utils.ToInt32Pointer(&options.HTTPPutResponseHopLimit),
11181119
HttpTokens: types.HttpTokensState(string(options.HTTPTokens)),
11191120
InstanceMetadataTags: types.InstanceMetadataTagsState(string(options.InstanceMetadataTags)),
1121+
HttpProtocolIpv6: types.InstanceMetadataProtocolState(string(options.HTTPProtocolIPv6)),
11201122
InstanceId: aws.String(instanceID),
11211123
}
11221124

@@ -1270,6 +1272,9 @@ func getInstanceMetadataOptionsRequest(metadataOptions *infrav1.InstanceMetadata
12701272
if metadataOptions.HTTPEndpoint != "" {
12711273
request.HttpEndpoint = types.InstanceMetadataEndpointState(string(metadataOptions.HTTPEndpoint))
12721274
}
1275+
if metadataOptions.HTTPProtocolIPv6 != "" {
1276+
request.HttpProtocolIpv6 = types.InstanceMetadataProtocolState(string(metadataOptions.HTTPProtocolIPv6))
1277+
}
12731278
if metadataOptions.HTTPPutResponseHopLimit != 0 {
12741279
request.HttpPutResponseHopLimit = utils.ToInt32Pointer(&metadataOptions.HTTPPutResponseHopLimit)
12751280
}

0 commit comments

Comments
 (0)