mirror of
https://github.com/rancher/os.git
synced 2025-07-31 06:32:09 +00:00
Auto resize root disk on AWS (#2191)
This commit is contained in:
parent
dab1c4ffb3
commit
55368a3897
@ -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()
|
||||
|
@ -38,6 +38,7 @@ type Metadata struct {
|
||||
Hostname string
|
||||
SSHPublicKeys map[string]string
|
||||
NetworkConfig netconf.NetworkConfig
|
||||
RootDisk string
|
||||
|
||||
PublicIPv4 net.IP
|
||||
PublicIPv6 net.IP
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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{
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user