Skip to content

Commit

Permalink
Make the block overhead configurable
Browse files Browse the repository at this point in the history
This patch will allow the user to configure the block overhead.
Currently it defaults to 0%. The overhead is required when migrating to
encrypted Ceph RBD (block). The pod may see less space on the disk and
therefore the migration will fail when it tries to allocate the last
sectors. See more about encrypted Ceph RBD in:
https://docs.ceph.com/en/quincy/rbd/rbd-encryption/

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 committed Dec 11, 2023
1 parent 5f52229 commit 9971796
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 12 deletions.
2 changes: 2 additions & 0 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
value: ${CDI_EXPORT_TOKEN_TTL}
- name: FILESYSTEM_OVERHEAD
value: ${FILESYSTEM_OVERHEAD}
- name: BLOCK_OVERHEAD
value: ${BLOCK_OVERHEAD}
- name: POPULATOR_CONTROLLER_IMAGE
value: ${POPULATOR_CONTROLLER_IMAGE}
- name: OVIRT_POPULATOR_IMAGE
Expand Down
1 change: 1 addition & 0 deletions operator/roles/forkliftcontroller/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ controller_vsphere_incremental_backup: true
controller_ovirt_warm_migration: true
controller_max_vm_inflight: 20
controller_filesystem_overhead: 10
controller_block_overhead: 0
profiler_volume_path: "/var/cache/profiler"

inventory_volume_path: "/var/cache/inventory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ spec:
- name: FILESYSTEM_OVERHEAD
value: "{{ controller_filesystem_overhead }}"
{% endif %}
{% if controller_block_overhead is number %}
- name: BLOCK_OVERHEAD
value: "{{ controller_block_overhead }}"
{% endif %}
{% if controller_vsphere_incremental_backup|bool %}
- name: FEATURE_VSPHERE_INCREMENTAL_BACKUP
value: "true"
Expand Down
5 changes: 1 addition & 4 deletions pkg/controller/plan/adapter/openstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(image model.Image, storageC
err = liberr.Wrap(err)
return
}

if *volumeMode == core.PersistentVolumeFilesystem {
virtualSize = utils.CalculateSpaceWithOverhead(virtualSize)
}
virtualSize = utils.CalculateSpaceWithOverhead(virtualSize, volumeMode)

// The image might be a VM Snapshot Image and has no volume associated to it
if originalVolumeDiskId, ok := image.Properties["forklift_original_volume_id"]; ok {
Expand Down
9 changes: 3 additions & 6 deletions pkg/controller/plan/adapter/ovirt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(diskAttachment model.XDiskA

// We add 10% overhead because of the fsOverhead in CDI, around 5% to ext4 and 5% for root partition.
// This value is configurable using `FILESYSTEM_OVERHEAD`
// Encrypted Ceph RBD causes the pod to see less space, it might be required an overhead in this case.
// For Block the value is configurable using `BLOCK_OVERHEAD`
diskSize := diskAttachment.Disk.ProvisionedSize

var accessModes []core.PersistentVolumeAccessMode
Expand All @@ -805,12 +807,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(diskAttachment model.XDiskA
err = liberr.Wrap(err)
return
}

// Accounting for fsOverhead is only required for `volumeMode: Filesystem`, as we may not have enough space
// after creating a filesystem on an underlying block device
if *volumeMode == core.PersistentVolumeFilesystem {
diskSize = utils.CalculateSpaceWithOverhead(diskSize)
}
diskSize = utils.CalculateSpaceWithOverhead(diskSize, volumeMode)

annotations[AnnImportDiskId] = diskAttachment.ID

Expand Down
11 changes: 9 additions & 2 deletions pkg/controller/plan/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math"

"github.com/konveyor/forklift-controller/pkg/settings"
core "k8s.io/api/core/v1"
)

// Disk alignment size used to align FS overhead,
Expand All @@ -20,8 +21,14 @@ func roundUp(requestedSpace, multiple int64) int64 {
return int64(partitions) * multiple
}

func CalculateSpaceWithOverhead(requestedSpace int64) int64 {
func CalculateSpaceWithOverhead(requestedSpace int64, volumeMode *core.PersistentVolumeMode) int64 {
var overhead int
if *volumeMode == core.PersistentVolumeFilesystem {
overhead = settings.Settings.FileSystemOverhead
} else {
overhead = settings.Settings.BlockOverhead
}
alignedSize := roundUp(requestedSpace, DefaultAlignBlockSize)
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - float64(settings.Settings.FileSystemOverhead)/100)))
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - float64(overhead)/100)))
return spaceWithOverhead
}
6 changes: 6 additions & 0 deletions pkg/settings/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
SnapshotStatusCheckRate = "SNAPSHOT_STATUS_CHECK_RATE"
CDIExportTokenTTL = "CDI_EXPORT_TOKEN_TTL"
FileSystemOverhead = "FILESYSTEM_OVERHEAD"
BlockOverhead = "BLOCK_OVERHEAD"
)

// Migration settings
Expand All @@ -45,6 +46,8 @@ type Migration struct {
CDIExportTokenTTL int
// FileSystem overhead in percantage
FileSystemOverhead int
// Block overhead in percantage
BlockOverhead int
}

// Load settings.
Expand Down Expand Up @@ -85,6 +88,9 @@ func (r *Migration) Load() (err error) {
if r.FileSystemOverhead, err = getNonNegativeEnvLimit(FileSystemOverhead, 10); err != nil {
return liberr.Wrap(err)
}
if r.BlockOverhead, err = getNonNegativeEnvLimit(BlockOverhead, 0); err != nil {
return liberr.Wrap(err)
}

return
}

0 comments on commit 9971796

Please sign in to comment.