Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BlockDeviceMappings to the AWS cloudprovider #1420

Merged
merged 5 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pelletier/go-toml/v2 v2.0.0-beta.5
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
go.uber.org/multierr v1.7.0
Expand Down
6 changes: 5 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,10 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml/v2 v2.0.0-beta.5 h1:zRY68WYiDE9YZLflUWuyOny5YA+DwvyFzZBfb8E/9wk=
github.com/pelletier/go-toml/v2 v2.0.0-beta.5/go.mod h1:ke6xncR3W76Ba8xnVxkrZG0js6Rd2BsQEAYrfgJ6eQA=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
Expand Down Expand Up @@ -687,8 +690,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU=
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
139 changes: 0 additions & 139 deletions pkg/cloudprovider/aws/ami.go

This file was deleted.

101 changes: 77 additions & 24 deletions pkg/cloudprovider/aws/apis/v1alpha1/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ import (
"encoding/json"
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/aws/karpenter/pkg/apis/provisioning/v1alpha5"
)

const (
DefaultMetadataOptionsHTTPEndpoint = ec2.LaunchTemplateInstanceMetadataEndpointStateEnabled
DefaultMetadataOptionsHTTPProtocolIPv6 = ec2.LaunchTemplateInstanceMetadataProtocolIpv6Disabled
DefaultMetadataOptionsHTTPPutResponseHopLimit = 2
DefaultMetadataOptionsHTTPTokens = ec2.LaunchTemplateHttpTokensStateRequired
)

// Constraints wraps generic constraints with AWS specific parameters
type Constraints struct {
*v1alpha5.Constraints
Expand All @@ -50,9 +42,6 @@ type AWS struct {
// InstanceProfile is the AWS identity that instances use.
// +optional
InstanceProfile *string `json:"instanceProfile,omitempty"`
// LaunchTemplate for the node. If not specified, a launch template will be generated.
// +optional
LaunchTemplate *string `json:"launchTemplate,omitempty"`
// SubnetSelector discovers subnets by tags. A value of "" is a wildcard.
// +optional
SubnetSelector map[string]string `json:"subnetSelector,omitempty"`
Expand All @@ -62,6 +51,16 @@ type AWS struct {
// Tags to be applied on ec2 resources like instances and launch templates.
// +optional
Tags map[string]string `json:"tags,omitempty"`
// LaunchTemplate parameters to use when generating an LT
LaunchTemplate `json:",inline,omitempty"`
}

type LaunchTemplate struct {
// LaunchTemplateName for the node. If not specified, a launch template will be generated.
// NOTE: This field is for specifying a custom launch template and is exposed in the Spec
// as `launchTemplate` for backwards compatibility.
// +optional
LaunchTemplateName *string `json:"launchTemplate,omitempty"`
// MetadataOptions for the generated launch template of provisioned nodes.
//
// This specifies the exposure of the Instance Metadata Service to
Expand All @@ -78,6 +77,9 @@ type AWS struct {
// required.
// +optional
MetadataOptions *MetadataOptions `json:"metadataOptions,omitempty"`
// BlockDeviceMappings to be applied to provisioned nodes.
// +optionals
BlockDeviceMappings []*BlockDeviceMapping `json:"blockDeviceMappings,omitempty"`
bwagner5 marked this conversation as resolved.
Show resolved Hide resolved
}

// MetadataOptions contains parameters for specifying the exposure of the
Expand Down Expand Up @@ -124,6 +126,69 @@ type MetadataOptions struct {
HTTPTokens *string `json:"httpTokens,omitempty"`
}

type BlockDeviceMapping struct {
// The device name (for example, /dev/sdh or xvdh).
DeviceName *string `json:"deviceName,omitempty"`
// EBS contains parameters used to automatically set up EBS volumes when an instance is launched.
EBS *BlockDevice `json:"ebs,omitempty"`
}

type BlockDevice struct {
// DeleteOnTermination indicates whether the EBS volume is deleted on instance termination.
DeleteOnTermination *bool `json:"deleteOnTermination,omitempty"`

// Encrypted indicates whether the EBS volume is encrypted. Encrypted volumes can only
// be attached to instances that support Amazon EBS encryption. If you are creating
// a volume from a snapshot, you can't specify an encryption value.
Encrypted *bool `json:"encrypted,omitempty"`

// IOPS is the number of I/O operations per second (IOPS). For gp3, io1, and io2 volumes,
// this represents the number of IOPS that are provisioned for the volume. For
// gp2 volumes, this represents the baseline performance of the volume and the
// rate at which the volume accumulates I/O credits for bursting.
//
// The following are the supported values for each volume type:
//
// * gp3: 3,000-16,000 IOPS
//
// * io1: 100-64,000 IOPS
//
// * io2: 100-64,000 IOPS
//
// For io1 and io2 volumes, we guarantee 64,000 IOPS only for Instances built
// on the Nitro System (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances).
// Other instance families guarantee performance up to 32,000 IOPS.
//
// This parameter is supported for io1, io2, and gp3 volumes only. This parameter
// is not supported for gp2, st1, sc1, or standard volumes.
IOPS *int64 `json:"iops,omitempty"`

// KMSKeyID (ARN) of the symmetric Key Management Service (KMS) CMK used for encryption.
KMSKeyID *string `json:"kmsKeyID,omitempty"`

// Throughput to provision for a gp3 volume, with a maximum of 1,000 MiB/s.
// Valid Range: Minimum value of 125. Maximum value of 1000.
Throughput *int64 `json:"throughput,omitempty"`

// VolumeSize in GiBs. You must specify either a snapshot ID or
// a volume size. The following are the supported volumes sizes for each volume
// type:
//
// * gp2 and gp3: 1-16,384
//
// * io1 and io2: 4-16,384
//
// * st1 and sc1: 125-16,384
//
// * standard: 1-1,024
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`

// VolumeType of the block device.
// For more information, see Amazon EBS volume types (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html)
// in the Amazon Elastic Compute Cloud User Guide.
VolumeType *string `json:"volumeType,omitempty"`
}

func Deserialize(constraints *v1alpha5.Constraints) (*Constraints, error) {
if constraints.Provider == nil {
return nil, fmt.Errorf("invariant violated: spec.provider is not defined. Is the defaulting webhook installed?")
Expand All @@ -150,15 +215,3 @@ func (a *AWS) Serialize(constraints *v1alpha5.Constraints) error {
constraints.Provider.Raw = bytes
return nil
}

func (a *AWS) GetMetadataOptions() *MetadataOptions {
if a.MetadataOptions == nil {
return &MetadataOptions{
HTTPEndpoint: aws.String(DefaultMetadataOptionsHTTPEndpoint),
HTTPProtocolIPv6: aws.String(DefaultMetadataOptionsHTTPProtocolIPv6),
HTTPPutResponseHopLimit: aws.Int64(DefaultMetadataOptionsHTTPPutResponseHopLimit),
HTTPTokens: aws.String(DefaultMetadataOptionsHTTPTokens),
}
}
return a.MetadataOptions
}
11 changes: 0 additions & 11 deletions pkg/cloudprovider/aws/apis/v1alpha1/provider_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
func (c *Constraints) Default(ctx context.Context) {
c.defaultArchitecture()
c.defaultCapacityTypes()
c.defaultAMIFamily()
bwagner5 marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *Constraints) defaultCapacityTypes() {
Expand Down Expand Up @@ -56,13 +55,3 @@ func (c *Constraints) defaultArchitecture() {
Values: []string{v1alpha5.ArchitectureAmd64},
})
}

func (c *Constraints) defaultAMIFamily() {
if c.AMIFamily != nil {
return
}
if c.LaunchTemplate != nil {
return
}
c.AMIFamily = &AMIFamilyAL2
}
Loading