Skip to content

Commit

Permalink
MTV-1493 | Add missing resource limits and requests
Browse files Browse the repository at this point in the history
Issue:
If the user sets ClusterResourceQuota the Forklift will start failing as it
does not have the limits or requests on the pods which are created form
the Forklift Controller.

Fix:
Add a new parameters to Forklift operator which can be configured
depedning on the user env.

Ref: https://issues.redhat.com/browse/MTV-1493
Signed-off-by: Martin Necas <[email protected]>
  • Loading branch information
mnecas committed Dec 13, 2024
1 parent 3929eaf commit c9911dd
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 22 deletions.
13 changes: 13 additions & 0 deletions operator/roles/forkliftcontroller/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,21 @@ virt_v2v_image_fqin: "{{ lookup( 'env', 'VIRT_V2V_IMAGE') or lookup( 'env', 'REL
virt_v2v_dont_request_kvm: "{{ lookup( 'env', 'VIRT_V2V_DONT_REQUEST_KVM') }}"
virt_v2v_extra_args: "{{ lookup( 'env', 'VIRT_V2V_EXTRA_ARGS') }}"
virt_v2v_extra_conf_config_map: "{{ lookup( 'env', 'VIRT_V2V_EXTRA_CONF_CONFIG_MAP') }}"
virt_v2v_container_limits_cpu: "1000m"
virt_v2v_container_limits_memory: "8Gi"
virt_v2v_container_requests_cpu: "1000m"
virt_v2v_container_requests_memory: "1Gi"

hooks_container_limits_cpu: "1000m"
hooks_container_limits_memory: "1Gi"
hooks_container_requests_cpu: "100m"
hooks_container_requests_memory: "150Mi"

ova_provider_server_fqin: "{{ lookup( 'env', 'OVA_PROVIDER_SERVER_IMAGE') or lookup( 'env', 'RELATED_IMAGE_OVA_PROVIDER_SERVER') }}"
ova_container_limits_cpu: "1000m"
ova_container_limits_memory: "1Gi"
ova_container_requests_cpu: "100m"
ova_container_requests_memory: "150Mi"

metric_service_name: "{{ app_name }}-metrics"
metric_servicemonitor_name: "{{ app_name }}-metrics"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ spec:
value: "{{ virt_v2v_extra_args }}"
- name: VIRT_V2V_EXTRA_CONF_CONFIG_MAP
value: "{{ virt_v2v_extra_conf_config_map }}"
- name: VIRT_V2V_CONTAINER_LIMITS_CPU
value: "{{ virt_v2v_container_limits_cpu }}"
- name: VIRT_V2V_CONTAINER_LIMITS_MEMORY
value: "{{ virt_v2v_container_limits_memory }}"
- name: VIRT_V2V_CONTAINER_REQUESTS_CPU
value: "{{ virt_v2v_container_requests_cpu }}"
- name: VIRT_V2V_CONTAINER_REQUESTS_MEMORY
value: "{{ virt_v2v_container_requests_memory }}"
- name: HOOKS_CONTAINER_LIMITS_CPU
value: "{{ hooks_container_limits_cpu }}"
- name: HOOKS_CONTAINER_LIMITS_MEMORY
value: "{{ hooks_container_limits_memory }}"
- name: HOOKS_CONTAINER_REQUESTS_CPU
value: "{{ hooks_container_requests_cpu }}"
- name: HOOKS_CONTAINER_REQUESTS_MEMORY
value: "{{ hooks_container_requests_memory }}"
- name: OVA_CONTAINER_LIMITS_CPU
value: "{{ ova_container_limits_cpu }}"
- name: OVA_CONTAINER_LIMITS_MEMORY
value: "{{ ova_container_limits_memory }}"
- name: OVA_CONTAINER_REQUESTS_CPU
value: "{{ ova_container_requests_cpu }}"
- name: OVA_CONTAINER_REQUESTS_MEMORY
value: "{{ ova_container_requests_memory }}"
envFrom:
- configMapRef:
name: {{ controller_configmap_name }}
Expand Down Expand Up @@ -186,6 +210,8 @@ spec:
value: '8082'
- name: OVA_PROVIDER_SERVER_IMAGE
value: {{ ova_provider_server_fqin }}
- name: OVA_PROVIDER_SERVER_IMAGE
value: {{ ova_provider_server_fqin }}
{% if feature_validation|bool %}
- name: POLICY_AGENT_URL
value: "https://{{ validation_service_name }}.{{ app_namespace }}.svc.cluster.local:8181"
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/plan/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plan
import (
"context"
"encoding/base64"
"k8s.io/apimachinery/pkg/api/resource"

Check failure on line 6 in pkg/controller/plan/hook.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"path"
"strings"

Expand Down Expand Up @@ -181,6 +182,16 @@ func (r *HookRunner) template(mp *core.ConfigMap) (template *core.PodTemplateSpe
{
Name: "hook",
Image: r.hook.Spec.Image,
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.Migration.HooksContainerRequestsCpu),
core.ResourceMemory: resource.MustParse(Settings.Migration.HooksContainerRequestsMemory),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.Migration.HooksContainerLimitCpu),
core.ResourceMemory: resource.MustParse(Settings.Migration.HooksContainerLimitMemory),
},
},
VolumeMounts: []core.VolumeMount{
{
Name: "hook",
Expand Down
30 changes: 30 additions & 0 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,16 @@ func (r *KubeVirt) createPodToBindPVCs(vm *plan.VMStatus, pvcNames []string) (er
// In that case, we could benefit from pulling the image of the conversion pod, so it will be present on the node.
Image: Settings.Migration.VirtV2vImage,
Command: []string{"/bin/sh"},
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.Migration.VirtV2vContainerRequestsCpu),
core.ResourceMemory: resource.MustParse(Settings.Migration.VirtV2vContainerRequestsMemory),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.Migration.VirtV2vContainerLimitCpu),
core.ResourceMemory: resource.MustParse(Settings.Migration.VirtV2vContainerLimitMemory),
},
},
SecurityContext: &core.SecurityContext{
AllowPrivilegeEscalation: &allowPrivilageEscalation,
RunAsNonRoot: &nonRoot,
Expand Down Expand Up @@ -1738,6 +1748,16 @@ func (r *KubeVirt) guestConversionPod(vm *plan.VMStatus, vmVolumes []cnv.Volume,
MountPath: "/opt",
},
},
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("150Mi"),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("150Mi"),
},
},
SecurityContext: &core.SecurityContext{
AllowPrivilegeEscalation: &allowPrivilageEscalation,
Capabilities: &core.Capabilities{
Expand Down Expand Up @@ -1823,6 +1843,16 @@ func (r *KubeVirt) guestConversionPod(vm *plan.VMStatus, vmVolumes []cnv.Volume,
Name: "virt-v2v",
Env: environment,
ImagePullPolicy: core.PullAlways,
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.Migration.VirtV2vContainerRequestsCpu),
core.ResourceMemory: resource.MustParse(Settings.Migration.VirtV2vContainerRequestsMemory),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.Migration.VirtV2vContainerLimitCpu),
core.ResourceMemory: resource.MustParse(Settings.Migration.VirtV2vContainerLimitMemory),
},
},
EnvFrom: []core.EnvFromSource{
{
Prefix: "V2V_",
Expand Down
23 changes: 22 additions & 1 deletion pkg/controller/plan/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
core "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
k8svalidation "k8s.io/apimachinery/pkg/util/validation"
Expand Down Expand Up @@ -1016,6 +1017,16 @@ func createVddkCheckJob(plan *api.Plan) *batchv1.Job {
Drop: []core.Capability{"ALL"},
},
},
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("150Mi"),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse("1000m"),
core.ResourceMemory: resource.MustParse("500Mi"),
},
},
},
}

Expand Down Expand Up @@ -1057,7 +1068,17 @@ func createVddkCheckJob(plan *api.Plan) *batchv1.Job {
InitContainers: initContainers,
Containers: []core.Container{
{
Name: "validator",
Name: "validator",
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse("100m"),
core.ResourceMemory: resource.MustParse("150Mi"),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse("1000m"),
core.ResourceMemory: resource.MustParse("500Mi"),
},
},
Image: Settings.Migration.VirtV2vImage,
SecurityContext: &core.SecurityContext{
AllowPrivilegeEscalation: ptr.To(false),
Expand Down
10 changes: 10 additions & 0 deletions pkg/controller/provider/ova-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ func (r *Reconciler) makeOvaProviderPodSpec(pvcName, providerName, providerNames
MountPath: mountPath,
},
},
Resources: core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.OvaContainerRequestsCpu),
core.ResourceMemory: resource.MustParse(Settings.OvaContainerRequestsMemory),
},
Limits: core.ResourceList{
core.ResourceCPU: resource.MustParse(Settings.OvaContainerLimitCpu),
core.ResourceMemory: resource.MustParse(Settings.OvaContainerRequestsMemory),
},
},
SecurityContext: securityContext,
}

Expand Down
102 changes: 81 additions & 21 deletions pkg/settings/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,38 @@ import (

// Environment variables.
const (
MaxVmInFlight = "MAX_VM_INFLIGHT"
HookRetry = "HOOK_RETRY"
ImporterRetry = "IMPORTER_RETRY"
VirtV2vImage = "VIRT_V2V_IMAGE"
PrecopyInterval = "PRECOPY_INTERVAL"
VirtV2vDontRequestKVM = "VIRT_V2V_DONT_REQUEST_KVM"
SnapshotRemovalTimeout = "SNAPSHOT_REMOVAL_TIMEOUT"
SnapshotStatusCheckRate = "SNAPSHOT_STATUS_CHECK_RATE"
CDIExportTokenTTL = "CDI_EXPORT_TOKEN_TTL"
FileSystemOverhead = "FILESYSTEM_OVERHEAD"
BlockOverhead = "BLOCK_OVERHEAD"
CleanupRetries = "CLEANUP_RETRIES"
DvStatusCheckRetries = "DV_STATUS_CHECK_RETRIES"
SnapshotRemovalCheckRetries = "SNAPSHOT_REMOVAL_CHECK_RETRIES"
OvirtOsConfigMap = "OVIRT_OS_MAP"
VsphereOsConfigMap = "VSPHERE_OS_MAP"
VirtCustomizeConfigMap = "VIRT_CUSTOMIZE_MAP"
VddkJobActiveDeadline = "VDDK_JOB_ACTIVE_DEADLINE"
VirtV2vExtraArgs = "VIRT_V2V_EXTRA_ARGS"
VirtV2vExtraConfConfigMap = "VIRT_V2V_EXTRA_CONF_CONFIG_MAP"
MaxVmInFlight = "MAX_VM_INFLIGHT"
HookRetry = "HOOK_RETRY"
ImporterRetry = "IMPORTER_RETRY"
VirtV2vImage = "VIRT_V2V_IMAGE"
PrecopyInterval = "PRECOPY_INTERVAL"
VirtV2vDontRequestKVM = "VIRT_V2V_DONT_REQUEST_KVM"
SnapshotRemovalTimeout = "SNAPSHOT_REMOVAL_TIMEOUT"
SnapshotStatusCheckRate = "SNAPSHOT_STATUS_CHECK_RATE"
CDIExportTokenTTL = "CDI_EXPORT_TOKEN_TTL"
FileSystemOverhead = "FILESYSTEM_OVERHEAD"
BlockOverhead = "BLOCK_OVERHEAD"
CleanupRetries = "CLEANUP_RETRIES"
DvStatusCheckRetries = "DV_STATUS_CHECK_RETRIES"
SnapshotRemovalCheckRetries = "SNAPSHOT_REMOVAL_CHECK_RETRIES"
OvirtOsConfigMap = "OVIRT_OS_MAP"
VsphereOsConfigMap = "VSPHERE_OS_MAP"
VirtCustomizeConfigMap = "VIRT_CUSTOMIZE_MAP"
VddkJobActiveDeadline = "VDDK_JOB_ACTIVE_DEADLINE"
VirtV2vExtraArgs = "VIRT_V2V_EXTRA_ARGS"
VirtV2vExtraConfConfigMap = "VIRT_V2V_EXTRA_CONF_CONFIG_MAP"
VirtV2vContainerLimitCpu = "VIRT_V2V_CONTAINER_LIMITS_CPU"
VirtV2vContainerLimitMemory = "VIRT_V2V_CONTAINER_LIMITS_MEMORY"
VirtV2vContainerRequestsCpu = "VIRT_V2V_CONTAINER_REQUESTS_CPU"
VirtV2vContainerRequestsMemory = "VIRT_V2V_CONTAINER_REQUESTS_MEMORY"
HooksContainerLimitCpu = "HOOKS_CONTAINER_LIMITS_CPU"
HooksContainerLimitMemory = "HOOKS_CONTAINER_LIMITS_MEMORY"
HooksContainerRequestsCpu = "HOOKS_CONTAINER_REQUESTS_CPU"
HooksContainerRequestsMemory = "HOOKS_CONTAINER_REQUESTS_MEMORY"
OvaContainerLimitCpu = "OVA_CONTAINER_LIMITS_CPU"
OvaContainerLimitMemory = "OVA_CONTAINER_LIMITS_MEMORY"
OvaContainerRequestsCpu = "OVA_CONTAINER_REQUESTS_CPU"
OvaContainerRequestsMemory = "OVA_CONTAINER_REQUESTS_MEMORY"
)

// Migration settings
Expand Down Expand Up @@ -75,7 +87,19 @@ type Migration struct {
// Additional arguments for virt-v2v
VirtV2vExtraArgs string
// Additional configuration for virt-v2v
VirtV2vExtraConfConfigMap string
VirtV2vExtraConfConfigMap string
VirtV2vContainerLimitCpu string
VirtV2vContainerLimitMemory string
VirtV2vContainerRequestsCpu string
VirtV2vContainerRequestsMemory string
HooksContainerLimitCpu string
HooksContainerLimitMemory string
HooksContainerRequestsCpu string
HooksContainerRequestsMemory string
OvaContainerLimitCpu string
OvaContainerLimitMemory string
OvaContainerRequestsCpu string
OvaContainerRequestsMemory string
}

// Load settings.
Expand Down Expand Up @@ -157,5 +181,41 @@ func (r *Migration) Load() (err error) {
if val, found := os.LookupEnv(VirtV2vExtraConfConfigMap); found {
r.VirtV2vExtraConfConfigMap = val
}
if val, found := os.LookupEnv(VirtV2vContainerLimitCpu); found {
r.VirtV2vContainerLimitCpu = val
}
if val, found := os.LookupEnv(VirtV2vContainerLimitMemory); found {
r.VirtV2vContainerLimitMemory = val
}
if val, found := os.LookupEnv(VirtV2vContainerRequestsCpu); found {
r.VirtV2vContainerRequestsCpu = val
}
if val, found := os.LookupEnv(VirtV2vContainerRequestsMemory); found {
r.VirtV2vContainerRequestsMemory = val
}
if val, found := os.LookupEnv(HooksContainerLimitCpu); found {
r.HooksContainerLimitCpu = val
}
if val, found := os.LookupEnv(HooksContainerLimitMemory); found {
r.HooksContainerLimitMemory = val
}
if val, found := os.LookupEnv(HooksContainerRequestsCpu); found {
r.HooksContainerRequestsCpu = val
}
if val, found := os.LookupEnv(HooksContainerRequestsMemory); found {
r.HooksContainerRequestsMemory = val
}
if val, found := os.LookupEnv(OvaContainerLimitCpu); found {
r.HooksContainerLimitCpu = val
}
if val, found := os.LookupEnv(OvaContainerLimitMemory); found {
r.HooksContainerLimitMemory = val
}
if val, found := os.LookupEnv(OvaContainerRequestsCpu); found {
r.HooksContainerRequestsCpu = val
}
if val, found := os.LookupEnv(OvaContainerRequestsMemory); found {
r.HooksContainerRequestsMemory = val
}
return
}

0 comments on commit c9911dd

Please sign in to comment.