Skip to content

Commit 09cdc37

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 19ff09b commit 09cdc37

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
@@ -324,6 +324,15 @@ type InstanceMetadataOptions struct {
324324
// +kubebuilder:default=enabled
325325
HTTPEndpoint InstanceMetadataState `json:"httpEndpoint,omitempty"`
326326

327+
// Enables or disables the IPv6 endpoint for the instance metadata service.
328+
// This applies only if you enabled the HTTP metadata endpoint.
329+
//
330+
// Default: disabled
331+
//
332+
// +kubebuilder:validation:Enum:=enabled;disabled
333+
// +kubebuilder:default=disabled
334+
HTTPProtocolIPv6 InstanceMetadataState `json:"httpProtocolIpv6,omitempty"`
335+
327336
// The desired HTTP PUT response hop limit for instance metadata requests. The
328337
// larger the number, the further instance metadata requests can travel.
329338
//
@@ -370,6 +379,9 @@ func (obj *InstanceMetadataOptions) SetDefaults() {
370379
if obj.HTTPEndpoint == "" {
371380
obj.HTTPEndpoint = InstanceMetadataEndpointStateEnabled
372381
}
382+
if obj.HTTPProtocolIPv6 == "" {
383+
obj.HTTPProtocolIPv6 = InstanceMetadataEndpointStateDisabled
384+
}
373385
if obj.HTTPPutResponseHopLimit == 0 {
374386
obj.HTTPPutResponseHopLimit = 1
375387
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,17 @@ spec:
12451245
- enabled
12461246
- disabled
12471247
type: string
1248+
httpProtocolIpv6:
1249+
default: disabled
1250+
description: |-
1251+
Enables or disables the IPv6 endpoint for the instance metadata service.
1252+
This applies only if you enabled the HTTP metadata endpoint.
1253+
1254+
Default: disabled
1255+
enum:
1256+
- enabled
1257+
- disabled
1258+
type: string
12481259
httpPutResponseHopLimit:
12491260
default: 1
12501261
description: |-
@@ -3424,6 +3435,17 @@ spec:
34243435
- enabled
34253436
- disabled
34263437
type: string
3438+
httpProtocolIpv6:
3439+
default: disabled
3440+
description: |-
3441+
Enables or disables the IPv6 endpoint for the instance metadata service.
3442+
This applies only if you enabled the HTTP metadata endpoint.
3443+
3444+
Default: disabled
3445+
enum:
3446+
- enabled
3447+
- disabled
3448+
type: string
34273449
httpPutResponseHopLimit:
34283450
default: 1
34293451
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
@@ -2227,6 +2227,17 @@ spec:
22272227
- enabled
22282228
- disabled
22292229
type: string
2230+
httpProtocolIpv6:
2231+
default: disabled
2232+
description: |-
2233+
Enables or disables the IPv6 endpoint for the instance metadata service.
2234+
This applies only if you enabled the HTTP metadata endpoint.
2235+
2236+
Default: disabled
2237+
enum:
2238+
- enabled
2239+
- disabled
2240+
type: string
22302241
httpPutResponseHopLimit:
22312242
default: 1
22322243
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
@@ -689,6 +689,17 @@ spec:
689689
- enabled
690690
- disabled
691691
type: string
692+
httpProtocolIpv6:
693+
default: disabled
694+
description: |-
695+
Enables or disables the IPv6 endpoint for the instance metadata service.
696+
This applies only if you enabled the HTTP metadata endpoint.
697+
698+
Default: disabled
699+
enum:
700+
- enabled
701+
- disabled
702+
type: string
692703
httpPutResponseHopLimit:
693704
default: 1
694705
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
@@ -844,6 +844,17 @@ spec:
844844
- enabled
845845
- disabled
846846
type: string
847+
httpProtocolIpv6:
848+
default: disabled
849+
description: |-
850+
Enables or disables the IPv6 endpoint for the instance metadata service.
851+
This applies only if you enabled the HTTP metadata endpoint.
852+
853+
Default: disabled
854+
enum:
855+
- enabled
856+
- disabled
857+
type: string
847858
httpPutResponseHopLimit:
848859
default: 1
849860
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
@@ -763,6 +763,17 @@ spec:
763763
- enabled
764764
- disabled
765765
type: string
766+
httpProtocolIpv6:
767+
default: disabled
768+
description: |-
769+
Enables or disables the IPv6 endpoint for the instance metadata service.
770+
This applies only if you enabled the HTTP metadata endpoint.
771+
772+
Default: disabled
773+
enum:
774+
- enabled
775+
- disabled
776+
type: string
766777
httpPutResponseHopLimit:
767778
default: 1
768779
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
@@ -698,6 +698,17 @@ spec:
698698
- enabled
699699
- disabled
700700
type: string
701+
httpProtocolIpv6:
702+
default: disabled
703+
description: |-
704+
Enables or disables the IPv6 endpoint for the instance metadata service.
705+
This applies only if you enabled the HTTP metadata endpoint.
706+
707+
Default: disabled
708+
enum:
709+
- enabled
710+
- disabled
711+
type: string
701712
httpPutResponseHopLimit:
702713
default: 1
703714
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
@@ -927,6 +927,7 @@ func (s *Service) SDKToInstance(v types.Instance) (*infrav1.Instance, error) {
927927
metadataOptions.HTTPEndpoint = infrav1.InstanceMetadataState(string(v.MetadataOptions.HttpEndpoint))
928928
metadataOptions.HTTPTokens = infrav1.HTTPTokensState(string(v.MetadataOptions.HttpTokens))
929929
metadataOptions.InstanceMetadataTags = infrav1.InstanceMetadataState(string(v.MetadataOptions.InstanceMetadataTags))
930+
metadataOptions.HTTPProtocolIPv6 = infrav1.InstanceMetadataState(v.MetadataOptions.HttpProtocolIpv6)
930931
if v.MetadataOptions.HttpPutResponseHopLimit != nil {
931932
metadataOptions.HTTPPutResponseHopLimit = int64(*v.MetadataOptions.HttpPutResponseHopLimit)
932933
}
@@ -1082,6 +1083,7 @@ func (s *Service) ModifyInstanceMetadataOptions(instanceID string, options *infr
10821083
HttpPutResponseHopLimit: utils.ToInt32Pointer(&options.HTTPPutResponseHopLimit),
10831084
HttpTokens: types.HttpTokensState(string(options.HTTPTokens)),
10841085
InstanceMetadataTags: types.InstanceMetadataTagsState(string(options.InstanceMetadataTags)),
1086+
HttpProtocolIpv6: types.InstanceMetadataProtocolState(string(options.HTTPProtocolIPv6)),
10851087
InstanceId: aws.String(instanceID),
10861088
}
10871089

@@ -1234,6 +1236,9 @@ func getInstanceMetadataOptionsRequest(metadataOptions *infrav1.InstanceMetadata
12341236
if metadataOptions.HTTPEndpoint != "" {
12351237
request.HttpEndpoint = types.InstanceMetadataEndpointState(string(metadataOptions.HTTPEndpoint))
12361238
}
1239+
if metadataOptions.HTTPProtocolIPv6 != "" {
1240+
request.HttpProtocolIpv6 = types.InstanceMetadataProtocolState(string(metadataOptions.HTTPProtocolIPv6))
1241+
}
12371242
if metadataOptions.HTTPPutResponseHopLimit != 0 {
12381243
request.HttpPutResponseHopLimit = utils.ToInt32Pointer(&metadataOptions.HTTPPutResponseHopLimit)
12391244
}

0 commit comments

Comments
 (0)