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 rootfs size option for zmachines #1419

Merged
merged 3 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 14 additions & 20 deletions pkg/gridtypes/zos/zmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ type ZMachine struct {
FList string `json:"flist"`
// Network configuration for machine network
Network MachineNetwork `json:"network"`
// Size of zmachine (deprecated)
Size uint8 `json:"size"` // deprecated, use compute_capacity instead
// Size of zmachine disk
Size gridtypes.Unit `json:"size"`
// ComputeCapacity configuration for machine cpu+memory
ComputeCapacity MachineCapacity `json:"compute_capacity"`
// Mounts configure mounts/disks attachments to this machine
Expand All @@ -129,16 +129,14 @@ func (v ZMachine) Valid(getter gridtypes.WorkloadGetter) error {
return fmt.Errorf("invalid IP")
}
}

if v.Size == 0 {
if v.ComputeCapacity.CPU == 0 {
return fmt.Errorf("cpu capcity can't be 0")
}
if v.ComputeCapacity.Memory < 250*gridtypes.Megabyte {
return fmt.Errorf("mem capacity can't be less that 250M")
}
} else if v.Size < 1 || v.Size > 18 {
return fmt.Errorf("unsupported vm size %d, only size 1 to 18 are supported", v.Size)
if v.ComputeCapacity.CPU == 0 {
return fmt.Errorf("cpu capcity can't be 0")
}
if v.ComputeCapacity.Memory < 250*gridtypes.Megabyte {
return fmt.Errorf("mem capacity can't be less that 250M")
}
if v.Size != 0 && v.Size < 250*gridtypes.Megabyte {
return fmt.Errorf("disk size can't be less that 250M")
}
if !v.Network.PublicIP.IsEmpty() {
wl, err := getter.Get(v.Network.PublicIP)
Expand All @@ -162,18 +160,14 @@ func (v ZMachine) Valid(getter gridtypes.WorkloadGetter) error {

// Capacity implementation
func (v ZMachine) Capacity() (gridtypes.Capacity, error) {
if v.Size > 0 {
rsu, ok := vmSize[v.Size]
if !ok {
return gridtypes.Capacity{}, fmt.Errorf("VM size %d is not supported", v.Size)
}
return rsu, nil
var hru uint64
if v.Size > 250*gridtypes.Megabyte {
hru += uint64(v.Size) - 250*uint64(gridtypes.Megabyte)
}

// otherwise
return gridtypes.Capacity{
CRU: uint64(v.ComputeCapacity.CPU),
MRU: v.ComputeCapacity.Memory,
HRU: gridtypes.Unit(hru),
}, nil
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/primitives/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,15 @@ func (p *Primitives) virtualMachineProvisionImpl(ctx context.Context, wl *gridty
if err := flist.Unmount(ctx, wl.ID.String()); err != nil {
return result, errors.Wrapf(err, "failed to unmount flist: %s", wl.ID.String())
}
rootfsSize := config.Size
if rootfsSize < 250*gridtypes.Megabyte {
rootfsSize = 250 * gridtypes.Megabyte
}
// remounting in RW mode
mnt, err = flist.Mount(ctx, wl.ID.String(), config.FList, pkg.DefaultMountOptions)
mnt, err = flist.Mount(ctx, wl.ID.String(), config.FList, pkg.MountOptions{
ReadOnly: false,
Limit: rootfsSize,
})
if err != nil {
return result, errors.Wrapf(err, "failed to mount flist: %s", wl.ID.String())
}
Expand Down