Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions api/karpenter/v1beta1/karpenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ type OpenshiftEC2NodeClassSpec struct {
// +optional
Monitoring MonitoringState `json:"monitoring,omitempty"`

// metadataOptions contains parameters for specifying the exposure of the
// Instance Metadata Service to provisioned EC2 nodes.
// When omitted, the platform preserves control over default behaviour
// which is subject to change over time. Currently defaults to access
// HTTPEndpoint, httpIPProtocol IPv4, httpPutResponseHopLimit of 1,
// and httpTokens Required (IMDSv2).
// +optional
MetadataOptions MetadataOptions `json:"metadataOptions,omitzero"`

// version is an OpenShift version (e.g., "4.20.1") specifying the release version
// for nodes managed by this NodeClass. When set, the controller resolves this to a
// release image via the Cincinnati graph API. When not set, nodes use the control plane's
Expand Down Expand Up @@ -400,6 +409,82 @@ type BlockDevice struct {
VolumeType VolumeType `json:"volumeType,omitempty"`
}

// MetadataAccess specifies how the instance metadata endpoint is accessed on provisioned nodes.
// +kubebuilder:validation:Enum=HTTPEndpoint;None
type MetadataAccess string

const (
// MetadataAccessHTTPEndpoint enables access to instance metadata via the HTTP endpoint.
MetadataAccessHTTPEndpoint MetadataAccess = "HTTPEndpoint"
// MetadataAccessNone disables access to instance metadata.
MetadataAccessNone MetadataAccess = "None"
)

// MetadataHTTPProtocol specifies the IP protocol version for the instance metadata service endpoint.
// +kubebuilder:validation:Enum=IPv4;IPv6
type MetadataHTTPProtocol string

const (
// MetadataHTTPProtocolIPv4 uses the IPv4 endpoint for the instance metadata service.
MetadataHTTPProtocolIPv4 MetadataHTTPProtocol = "IPv4"
// MetadataHTTPProtocolIPv6 uses the IPv6 endpoint for the instance metadata service.
MetadataHTTPProtocolIPv6 MetadataHTTPProtocol = "IPv6"
)

// MetadataHTTPTokensState determines the state of token usage for instance metadata requests.
// +kubebuilder:validation:Enum=Required;Optional
type MetadataHTTPTokensState string

const (
// MetadataHTTPTokensStateRequired requires a signed token header for metadata requests (IMDSv2).
MetadataHTTPTokensStateRequired MetadataHTTPTokensState = "Required"
// MetadataHTTPTokensStateOptional allows metadata retrieval with or without a token (IMDSv1/v2).
MetadataHTTPTokensStateOptional MetadataHTTPTokensState = "Optional"
)

// MetadataOptions contains parameters for specifying the exposure of the
// Instance Metadata Service to provisioned EC2 nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have a req field or minProperties 1

// When omitted, the platform preserves control over default behaviour which
// is subject to change over time. Currently defaults to HTTP endpoint access
// with IPv4, a hop limit of 1, and required tokens (IMDSv2).
// +kubebuilder:validation:MinProperties=1
type MetadataOptions struct {
// access specifies how the instance metadata endpoint is accessed on
// provisioned nodes. Valid values are "HTTPEndpoint" and "None".
// When set to "HTTPEndpoint", the instance metadata service is accessible
// via the HTTP endpoint. When set to "None", instance metadata is not
// accessible on the node.
// When omitted, the platform defaults to HTTP endpoint access.
// +optional
Access MetadataAccess `json:"access,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need cel to prevent the rest of the fields from being set, when Access is None?

// httpIPProtocol specifies the IP protocol version for the instance metadata
// service endpoint on provisioned nodes. Valid values are "IPv4" and "IPv6".
// When set to "IPv4", the metadata endpoint uses the IPv4 protocol.
// When set to "IPv6", the metadata endpoint uses the IPv6 protocol.
// When omitted, the platform defaults to IPv4.
// +optional
HTTPIPProtocol MetadataHTTPProtocol `json:"httpIPProtocol,omitempty"`
// httpPutResponseHopLimit is the desired HTTP PUT response hop limit for
// instance metadata requests. Possible values are integers from 1 to 64.
// A value of 1 restricts IMDS access to the EC2 instance only, preventing
// pods from reaching it. A value of 2 allows pods to access IMDS through
// the container network bridge. Values above 2 are for advanced networking
// scenarios such as nested virtualization.
// When omitted, the platform defaults to a hop limit of 1.
Comment on lines +467 to +473

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would I, as an end user, ever want this to be more than 1? What is the use case?

// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=64
// +optional
HTTPPutResponseHopLimit int64 `json:"httpPutResponseHopLimit,omitempty"`
// httpTokens determines the state of token usage for instance metadata
// requests. Valid values are "Required" and "Optional".
// When set to "Required", a signed token header (IMDSv2) must be used for
// all metadata requests. When set to "Optional", metadata can be retrieved
// with or without a token (IMDSv1/v2).
// When omitted, the platform defaults to requiring tokens (IMDSv2).
// +optional

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to be a pointer.
Use capital letter for enum, Required / Optional

HTTPTokens MetadataHTTPTokensState `json:"httpTokens,omitempty"`
}

// OpenshiftEC2NodeClassStatus defines the observed state of OpenshiftEC2NodeClass.
// +kubebuilder:validation:MinProperties=1
type OpenshiftEC2NodeClassStatus struct {
Expand Down
30 changes: 30 additions & 0 deletions api/karpenter/v1beta1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ func (spec OpenshiftEC2NodeClassSpec) KarpenterAssociatePublicIPAddress() *bool
}
}

func (spec OpenshiftEC2NodeClassSpec) KarpenterMetadataOptions() *awskarpenterv1.MetadataOptions {
mo := spec.MetadataOptions
if mo.Access == "" && mo.HTTPIPProtocol == "" && mo.HTTPPutResponseHopLimit == 0 && mo.HTTPTokens == "" {
return nil
}
opts := &awskarpenterv1.MetadataOptions{}
switch mo.Access {
case MetadataAccessHTTPEndpoint:
opts.HTTPEndpoint = ptr.To("enabled")
case MetadataAccessNone:
opts.HTTPEndpoint = ptr.To("disabled")
}
switch mo.HTTPIPProtocol {
case MetadataHTTPProtocolIPv6:
opts.HTTPProtocolIPv6 = ptr.To("enabled")
case MetadataHTTPProtocolIPv4:
opts.HTTPProtocolIPv6 = ptr.To("disabled")
}
if mo.HTTPPutResponseHopLimit != 0 {
opts.HTTPPutResponseHopLimit = ptr.To(mo.HTTPPutResponseHopLimit)
}
switch mo.HTTPTokens {
case MetadataHTTPTokensStateRequired:
opts.HTTPTokens = ptr.To("required")
case MetadataHTTPTokensStateOptional:
opts.HTTPTokens = ptr.To("optional")
}
return opts
}

func (spec OpenshiftEC2NodeClassSpec) KarpenterDetailedMonitoring() *bool {
switch spec.Monitoring {
case MonitoringStateDetailed:
Expand Down
16 changes: 16 additions & 0 deletions api/karpenter/v1beta1/zz_generated.deepcopy.go

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

69 changes: 69 additions & 0 deletions client/applyconfiguration/karpenter/v1beta1/metadataoptions.go

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

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

2 changes: 2 additions & 0 deletions client/applyconfiguration/utils.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 @@ -191,6 +191,65 @@ spec:
- Public
- SubnetDefault
type: string
metadataOptions:
description: |-
metadataOptions contains parameters for specifying the exposure of the
Instance Metadata Service to provisioned EC2 nodes.
When omitted, the platform preserves control over default behaviour
which is subject to change over time. Currently defaults to access
HTTPEndpoint, httpIPProtocol IPv4, httpPutResponseHopLimit of 1,
and httpTokens Required (IMDSv2).
minProperties: 1
properties:
access:
description: |-
access specifies how the instance metadata endpoint is accessed on
provisioned nodes. Valid values are "HTTPEndpoint" and "None".
When set to "HTTPEndpoint", the instance metadata service is accessible
via the HTTP endpoint. When set to "None", instance metadata is not
accessible on the node.
When omitted, the platform defaults to HTTP endpoint access.
enum:
- HTTPEndpoint
- None
type: string
httpIPProtocol:
description: |-
httpIPProtocol specifies the IP protocol version for the instance metadata
service endpoint on provisioned nodes. Valid values are "IPv4" and "IPv6".
When set to "IPv4", the metadata endpoint uses the IPv4 protocol.
When set to "IPv6", the metadata endpoint uses the IPv6 protocol.
When omitted, the platform defaults to IPv4.
enum:
- IPv4
- IPv6
type: string
httpPutResponseHopLimit:
description: |-
httpPutResponseHopLimit is the desired HTTP PUT response hop limit for
instance metadata requests. Possible values are integers from 1 to 64.
A value of 1 restricts IMDS access to the EC2 instance only, preventing
pods from reaching it. A value of 2 allows pods to access IMDS through
the container network bridge. Values above 2 are for advanced networking
scenarios such as nested virtualization.
When omitted, the platform defaults to a hop limit of 1.
format: int64
maximum: 64
minimum: 1
type: integer
httpTokens:
description: |-
httpTokens determines the state of token usage for instance metadata
requests. Valid values are "Required" and "Optional".
When set to "Required", a signed token header (IMDSv2) must be used for
all metadata requests. When set to "Optional", metadata can be retrieved
with or without a token (IMDSv1/v2).
When omitted, the platform defaults to requiring tokens (IMDSv2).
enum:
- Required
- Optional
type: string
type: object
monitoring:
description: |-
monitoring controls the monitoring level for instances that are launched.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ func reconcileEC2NodeClass(ctx context.Context, ec2NodeClass *awskarpenterv1.EC2
DetailedMonitoring: openshiftEC2NodeClass.Spec.KarpenterDetailedMonitoring(),
BlockDeviceMappings: openshiftEC2NodeClass.Spec.KarpenterBlockDeviceMapping(),
InstanceStorePolicy: openshiftEC2NodeClass.Spec.KarpenterInstanceStorePolicy(),
MetadataOptions: openshiftEC2NodeClass.Spec.KarpenterMetadataOptions(),
}

// Set instance profile from HostedCluster annotation (platform-controlled)
Expand Down
Loading