diff --git a/cmd/cloudinitexecute/cloudinitexecute.go b/cmd/cloudinitexecute/cloudinitexecute.go index cafebcca..a5d655de 100644 --- a/cmd/cloudinitexecute/cloudinitexecute.go +++ b/cmd/cloudinitexecute/cloudinitexecute.go @@ -184,7 +184,11 @@ func resizeDevice(cfg *rancherConfig.CloudConfig) error { return err } - cmd = exec.Command("resize2fs", fmt.Sprintf("%s1", cfg.Rancher.ResizeDevice)) + targetPartition := fmt.Sprintf("%s1", cfg.Rancher.ResizeDevice) + if strings.Contains(cfg.Rancher.ResizeDevice, "nvme") { + targetPartition = fmt.Sprintf("%sp1", cfg.Rancher.ResizeDevice) + } + cmd = exec.Command("resize2fs", targetPartition) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err = cmd.Run() diff --git a/config/cloudinit/datasource/datasource.go b/config/cloudinit/datasource/datasource.go index 2b86357c..dfd522eb 100755 --- a/config/cloudinit/datasource/datasource.go +++ b/config/cloudinit/datasource/datasource.go @@ -38,6 +38,7 @@ type Metadata struct { Hostname string SSHPublicKeys map[string]string NetworkConfig netconf.NetworkConfig + RootDisk string PublicIPv4 net.IP PublicIPv6 net.IP diff --git a/config/cloudinit/datasource/metadata/ec2/metadata.go b/config/cloudinit/datasource/metadata/ec2/metadata.go index 73db565c..e918ba94 100755 --- a/config/cloudinit/datasource/metadata/ec2/metadata.go +++ b/config/cloudinit/datasource/metadata/ec2/metadata.go @@ -32,6 +32,9 @@ const ( apiVersion = "latest/" userdataPath = apiVersion + "user-data" metadataPath = apiVersion + "meta-data/" + + defaultXVRootDisk = "/dev/xvda" + defaultNVMeRootDisk = "/dev/nvme0n1" ) type MetadataService struct { @@ -137,6 +140,17 @@ func (ms MetadataService) FetchMetadata() (datasource.Metadata, error) { } } + // With C5 and M5 instances, EBS volumes are exposed as NVMe block devices. + // http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html + metadata.RootDisk = defaultXVRootDisk + if instanceType, err := ms.FetchAttribute("instance-type"); err == nil { + if strings.HasPrefix(instanceType, "m5") || strings.HasPrefix(instanceType, "c5") { + metadata.RootDisk = defaultNVMeRootDisk + } + } else if _, ok := err.(pkg.ErrNotFound); !ok { + return metadata, err + } + return metadata, nil } diff --git a/config/cloudinit/datasource/metadata/ec2/metadata_test.go b/config/cloudinit/datasource/metadata/ec2/metadata_test.go index cafa93e1..87ceff97 100755 --- a/config/cloudinit/datasource/metadata/ec2/metadata_test.go +++ b/config/cloudinit/datasource/metadata/ec2/metadata_test.go @@ -67,6 +67,7 @@ func TestFetchMetadata(t *testing.T) { PrivateIPv4: net.ParseIP("1.2.3.4"), PublicIPv4: net.ParseIP("5.6.7.8"), SSHPublicKeys: map[string]string{"test1": "key"}, + RootDisk: "/dev/xvda", NetworkConfig: netconf.NetworkConfig{ Interfaces: map[string]netconf.InterfaceConfig{ /* "eth0": netconf.InterfaceConfig{ @@ -89,12 +90,14 @@ func TestFetchMetadata(t *testing.T) { "/2009-04-04/meta-data/public-keys": "0=test1\n", "/2009-04-04/meta-data/public-keys/0": "openssh-key", "/2009-04-04/meta-data/public-keys/0/openssh-key": "key", + "/2009-04-04/meta-data/instance-type": "m5.large", }, expect: datasource.Metadata{ Hostname: "host", PrivateIPv4: net.ParseIP("21.2.3.4"), PublicIPv4: net.ParseIP("25.6.7.8"), SSHPublicKeys: map[string]string{"test1": "key"}, + RootDisk: "/dev/nvme0n1", NetworkConfig: netconf.NetworkConfig{ Interfaces: map[string]netconf.InterfaceConfig{ /* "eth0": netconf.InterfaceConfig{ diff --git a/config/disk.go b/config/disk.go index ebe01113..ab54a91e 100755 --- a/config/disk.go +++ b/config/disk.go @@ -205,6 +205,11 @@ func mergeMetadata(rawCfg map[interface{}]interface{}, md datasource.Metadata) m out["ssh_authorized_keys"] = finalKeys + rancherOut, _ := out["rancher"].(map[interface{}]interface{}) + if _, ok := rancherOut["resize_device"]; md.RootDisk != "" && !ok { + rancherOut["resize_device"] = md.RootDisk + } + return out }