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

Make the filesystem overhead configurable #645

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ spec:
value: ${SNAPSHOT_STATUS_CHECK_RATE}
- name: CDI_EXPORT_TOKEN_TTL
value: ${CDI_EXPORT_TOKEN_TTL}
- name: FILESYSTEM_OVERHEAD
value: ${FILESYSTEM_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 @@ -34,6 +34,7 @@ controller_snapshot_status_check_rate_seconds: 10
controller_vsphere_incremental_backup: true
controller_ovirt_warm_migration: true
controller_max_vm_inflight: 20
controller_filesystem_overhead: 10
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 @@ -74,7 +74,11 @@ spec:
{% endif %}
{% if controller_cdi_export_token_ttl is number %}
- name: CDI_EXPORT_TOKEN_TTL
value: "{{ CDI_EXPORT_TOKEN_TTL }}"
value: "{{ controller_cdi_export_token_ttl }}"
{% endif %}
{% if controller_filesystem_overhead is number %}
- name: FILESYSTEM_OVERHEAD
value: "{{ controller_filesystem_overhead }}"
{% endif %}
{% if controller_vsphere_incremental_backup|bool %}
- name: FEATURE_VSPHERE_INCREMENTAL_BACKUP
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plan/adapter/openstack/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(image model.Image, storageC
}

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

// The image might be a VM Snapshot Image and has no volume associated to it
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/plan/adapter/ovirt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(diskAttachment model.XDiskA
annotations map[string]string) (pvc *core.PersistentVolumeClaim, err error) {

// 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`
diskSize := diskAttachment.Disk.ProvisionedSize

var accessModes []core.PersistentVolumeAccessMode
Expand All @@ -796,7 +797,7 @@ func (r *Builder) persistentVolumeClaimWithSourceRef(diskAttachment model.XDiskA
// 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, 0.1)
diskSize = utils.CalculateSpaceWithOverhead(diskSize)
}

annotations[AnnImportDiskId] = diskAttachment.ID
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/plan/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/provider/web/openstack",
"//pkg/controller/provider/web/ovirt",
"//pkg/settings",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
],
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/plan/util/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package util

import "math"
import (
"math"

"github.com/konveyor/forklift-controller/pkg/settings"
)

// Disk alignment size used to align FS overhead,
// its a multiple of all known hardware block sizes 512/4k/8k/32k/64k
Expand All @@ -16,8 +20,8 @@ func roundUp(requestedSpace, multiple int64) int64 {
return int64(partitions) * multiple
}

func CalculateSpaceWithOverhead(requestedSpace int64, filesystemOverhead float64) int64 {
func CalculateSpaceWithOverhead(requestedSpace int64) int64 {
alignedSize := roundUp(requestedSpace, DefaultAlignBlockSize)
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - filesystemOverhead)))
spaceWithOverhead := int64(math.Ceil(float64(alignedSize) / (1 - float64(settings.Settings.FileSystemOverhead)/100)))
return spaceWithOverhead
}
2 changes: 1 addition & 1 deletion pkg/settings/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ type Logging struct {
// Load settings.
func (r *Logging) Load() error {
r.Development = getEnvBool(LogDevelopment, false)
r.Level, _ = getEnvLimit(LogLevel, 0)
r.Level, _ = getPositiveEnvLimit(LogLevel, 0)
return nil
}
36 changes: 21 additions & 15 deletions pkg/settings/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
SnapshotRemovalTimeout = "SNAPSHOT_REMOVAL_TIMEOUT"
SnapshotStatusCheckRate = "SNAPSHOT_STATUS_CHECK_RATE"
CDIExportTokenTTL = "CDI_EXPORT_TOKEN_TTL"
FileSystemOverhead = "FILESYSTEM_OVERHEAD"
)

// Default virt-v2v image.
Expand Down Expand Up @@ -46,33 +47,35 @@ type Migration struct {
VirtV2vDontRequestKVM bool
// OCP Export token TTL minutes
CDIExportTokenTTL int
// FileSystem overhead in percantage
FileSystemOverhead int
}

// Load settings.
func (r *Migration) Load() (err error) {
r.MaxInFlight, err = getEnvLimit(MaxVmInFlight, 20)
r.MaxInFlight, err = getPositiveEnvLimit(MaxVmInFlight, 20)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}
r.HookRetry, err = getEnvLimit(HookRetry, 3)
r.HookRetry, err = getPositiveEnvLimit(HookRetry, 3)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}
r.ImporterRetry, err = getEnvLimit(ImporterRetry, 3)
r.ImporterRetry, err = getPositiveEnvLimit(ImporterRetry, 3)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}
r.PrecopyInterval, err = getEnvLimit(PrecopyInterval, 60)
r.PrecopyInterval, err = getPositiveEnvLimit(PrecopyInterval, 60)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}
r.SnapshotRemovalTimeout, err = getEnvLimit(SnapshotRemovalTimeout, 120)
r.SnapshotRemovalTimeout, err = getPositiveEnvLimit(SnapshotRemovalTimeout, 120)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}
r.SnapshotStatusCheckRate, err = getEnvLimit(SnapshotStatusCheckRate, 10)
r.SnapshotStatusCheckRate, err = getPositiveEnvLimit(SnapshotStatusCheckRate, 10)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}
if virtV2vImage, ok := os.LookupEnv(VirtV2vImage); ok {
if cold, warm, found := strings.Cut(virtV2vImage, "|"); found {
Expand All @@ -87,10 +90,13 @@ func (r *Migration) Load() (err error) {
r.VirtV2vImageWarm = DefaultVirtV2vImage
}
r.VirtV2vDontRequestKVM = getEnvBool(VirtV2vDontRequestKVM, false)

r.CDIExportTokenTTL, err = getEnvLimit(CDIExportTokenTTL, 0)
r.CDIExportTokenTTL, err = getPositiveEnvLimit(CDIExportTokenTTL, 0)
if err != nil {
return liberr.Wrap(err)
}
r.FileSystemOverhead, err = getNonNegativeEnvLimit(FileSystemOverhead, 10)
if err != nil {
err = liberr.Wrap(err)
return liberr.Wrap(err)
}

return
Expand Down
4 changes: 2 additions & 2 deletions pkg/settings/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func (r *PolicyAgent) Load() (err error) {
} else {
r.TLS.CA = ServiceCAFile
}
r.Limit.Worker, err = getEnvLimit(PolicyAgentWorkerLimit, 10)
r.Limit.Worker, err = getPositiveEnvLimit(PolicyAgentWorkerLimit, 10)
if err != nil {
return err
}
r.SearchInterval, err = getEnvLimit(PolicyAgentSearchInterval, 600)
r.SearchInterval, err = getPositiveEnvLimit(PolicyAgentSearchInterval, 600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/settings/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Profiler struct {

// Load settings.
func (r *Profiler) Load() error {
minutes, _ := getEnvLimit(ProfileDuration, 0)
minutes, _ := getPositiveEnvLimit(ProfileDuration, 0)
r.Duration = time.Duration(minutes) * time.Minute
if s, found := os.LookupEnv(ProfilePath); found {
r.Path = s
Expand Down
22 changes: 18 additions & 4 deletions pkg/settings/settings.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package settings

import (
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
"fmt"
"os"
"strconv"

liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
)

// Global
Expand Down Expand Up @@ -69,15 +71,27 @@ func (r *ControllerSettings) Load() error {

// Get positive integer limit from the environment
// using the specified variable name and default.
func getEnvLimit(name string, def int) (int, error) {
func getPositiveEnvLimit(name string, def int) (int, error) {
return getEnvLimit(name, def, 1)
}

// Get non-negative integer limit from the environment
// using the specified variable name and default.
func getNonNegativeEnvLimit(name string, def int) (int, error) {
return getEnvLimit(name, def, 0)
}

// Get an integer limit from the environment
// using the specified variable name and default.
func getEnvLimit(name string, def, minimum int) (int, error) {
limit := 0
if s, found := os.LookupEnv(name); found {
n, err := strconv.Atoi(s)
if err != nil {
return 0, liberr.New(name + " must be an integer")
}
if n < 1 {
return 0, liberr.New(name + " must be >= 1")
if n < minimum {
return 0, liberr.New(fmt.Sprintf(name+" must be >= %d", minimum))
}
limit = n
} else {
Expand Down
Loading