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

Dynamically lookup the RootDeviceName of the AMI being used #779

Merged
merged 10 commits into from
May 10, 2019
14 changes: 14 additions & 0 deletions pkg/ami/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ func IsAvailable(api ec2iface.EC2API, id string) (bool, error) {
return *output.Images[0].State == "available", nil
}

// LookupRootDeviceName gets the root block device mapping
func LookupRootDeviceName(api ec2iface.EC2API, id string) (string, error) {
adamjohnson01 marked this conversation as resolved.
Show resolved Hide resolved
input := &ec2.DescribeImagesInput{
ImageIds: []*string{&id},
}

output, err := api.DescribeImages(input)
if err != nil {
return "", errors.Wrapf(err, "unable to determine root device name for %q", id)
}

return *output.Images[0].RootDeviceName, nil
adamjohnson01 marked this conversation as resolved.
Show resolved Hide resolved
}

// FindImage will get the AMI to use for the EKS nodes by querying AWS EC2 API.
// It will only look for images with a status of available and it will pick the
// image with the newest creation date.
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ type NodeGroup struct {
// +optional
VolumeType string `json:"volumeType"`
// +optional
RootDevice string `json:"rootDevice,omitempty"`
adamjohnson01 marked this conversation as resolved.
Show resolved Hide resolved
// +optional
MaxPodsPerNode int `json:"maxPodsPerNode,omitempty"`

// +optional
Expand Down
2 changes: 2 additions & 0 deletions pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ var _ = Describe("CloudFormation template builder API", func() {
ng.AMIFamily = "AmazonLinux2"
ng.VolumeSize = 2
ng.VolumeType = api.NodeVolumeTypeIO1
ng.RootDevice = "/dev/xvda"

if withFullVPC {
cfg.VPC = testVPC()
Expand Down Expand Up @@ -354,6 +355,7 @@ var _ = Describe("CloudFormation template builder API", func() {
DesiredCapacity: nil,
VolumeSize: 2,
VolumeType: api.NodeVolumeTypeIO1,
RootDevice: "/dev/xvda",
IAM: &api.NodeGroupIAM{
WithAddonPolicies: api.NodeGroupIAMAddonPolicies{
ImageBuilder: api.Disabled(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cfn/builder/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (n *NodeGroupResourceSet) addResourcesForNodeGroup() error {

if n.spec.VolumeSize > 0 {
launchTemplateData.BlockDeviceMappings = []gfn.AWSEC2LaunchTemplate_BlockDeviceMapping{{
DeviceName: gfn.NewString("/dev/xvda"),
DeviceName: gfn.NewString(n.spec.RootDevice),
Ebs: &gfn.AWSEC2LaunchTemplate_Ebs{
VolumeSize: gfn.NewInteger(n.spec.VolumeSize),
VolumeType: gfn.NewString(n.spec.VolumeType),
Expand Down
6 changes: 6 additions & 0 deletions pkg/ctl/create/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ func doCreateCluster(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg stri
}
logger.Info("nodegroup %q will use %q [%s/%s]", ng.Name, ng.AMI, ng.AMIFamily, cfg.Metadata.Version)

// Lookup AMI root device name
if err := ctl.GetRootDevice(ng); err != nil {
adamjohnson01 marked this conversation as resolved.
Show resolved Hide resolved
return err
}
logger.Info("%q has root device %q [%s/%s]", ng.AMI, ng.RootDevice, cfg.Metadata.Version)

if err := ctl.SetNodeLabels(ng, meta); err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func doCreateNodeGroups(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg s
}
logger.Info("nodegroup %q will use %q [%s/%s]", ng.Name, ng.AMI, ng.AMIFamily, cfg.Metadata.Version)

// Lookup AMI root device name
if err := ctl.GetRootDevice(ng); err != nil {
return err
}
logger.Info("%q has root device %q [%s/%s]", ng.AMI, ng.RootDevice, cfg.Metadata.Version)

if err := ctl.SetNodeLabels(ng, meta); err != nil {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/eks/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ func (c *ClusterProvider) EnsureAMI(version string, ng *api.NodeGroup) error {
return nil
}

// GetRootDevice looks up the root device for the ami
func (c *ClusterProvider) GetRootDevice(ng *api.NodeGroup) (error) {

// Get Root Device Name
rootDevice, err := ami.LookupRootDeviceName(c.Provider.EC2(), ng.AMI)
if err != nil {
return errors.Wrapf(err, "%s root device name is not available", ng.AMI)
}

ng.RootDevice = rootDevice

return nil
}

// SetNodeLabels initialises and validate node labels based on cluster and nodegroup names
func (c *ClusterProvider) SetNodeLabels(ng *api.NodeGroup, meta *api.ClusterMeta) error {
if ng.Labels == nil {
Expand Down