-
Notifications
You must be signed in to change notification settings - Fork 135
Change KubeVirt VM CPU assignment to not overwrite cpu alloc ratio #1906
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
Change KubeVirt VM CPU assignment to not overwrite cpu alloc ratio #1906
Conversation
Signed-off-by: soer3n <[email protected]>
e072ff1
to
4d4b946
Compare
Signed-off-by: soer3n <[email protected]>
344510c
to
33ead46
Compare
Signed-off-by: soer3n <[email protected]>
33ead46
to
0a2e73c
Compare
if isDedicatedVCPURequested(machine.Spec.Annotations) { | ||
cpusAsUint64, err := strconv.ParseUint(c.CPUs, 0, 64) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse cpu cores: %w", err) | ||
} | ||
|
||
virtualMachine.Spec.Template.Spec.Domain.CPU = &kubevirtcorev1.CPU{ | ||
Cores: uint32(cpusAsUint64), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this annotation is consumed in machine-controller then this should be configured at machine.Annotations
not in the spec.
sdk/cloudprovider/kubevirt/types.go
Outdated
@@ -25,6 +25,10 @@ import ( | |||
corev1 "k8s.io/api/core/v1" | |||
) | |||
|
|||
const ( | |||
UseDedicatedKubevirtVCPUAnnotationKey = "kubermatic.io/use-dedicated-kubevirt-cpu" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UseDedicatedKubevirtVCPUAnnotationKey = "kubermatic.io/use-dedicated-kubevirt-cpu" | |
UseDedicatedKubeVirtVCPUAnnotationKey = "kubermatic.io/use-dedicated-kubevirt-cpu" |
|
||
if isDedicatedVCPURequested(machine.Spec.Annotations) { | ||
cpusAsUint64, err := strconv.ParseUint(c.CPUs, 0, 64) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for space here
|
sdk/cloudprovider/kubevirt/types.go
Outdated
@@ -25,6 +25,10 @@ import ( | |||
corev1 "k8s.io/api/core/v1" | |||
) | |||
|
|||
const ( | |||
UseDedicatedKubevirtVCPUAnnotationKey = "kubermatic.io/use-dedicated-kubevirt-cpu" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better if you actually use the RawConfig instead of annotations.
Signed-off-by: soer3n <[email protected]>
* adapt kubevirt cpu struct for configuring vcpus for a virtual machine * modify logic in function for rendering resource requests and limits * modify validation accordingly to be a bit more specific regarding resources Signed-off-by: soer3n <[email protected]>
Signed-off-by: soer3n <[email protected]>
2162ddc
to
8b52fcc
Compare
@ahmedwaleedmalik I changed the kind to feature and modified the release notes accordingly to the changes i added after discussing the implementation with @moadqassem. |
if (c.VCPUs == nil && c.Resources.Cpu() == nil) || (c.VCPUs != nil && c.Resources.Cpu() != nil) { | ||
return fmt.Errorf("invalid/no cpus configured. Either vpus or cpus have to be configured.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message here is quite misleading since in cases where both vCPU and CPU are set, you are still returning the same message. Please split this into two different if blocks or be a bit more coherent with your error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I separated both conditions and changed the return message to be a bit more clearer.
sdk/cloudprovider/kubevirt/types.go
Outdated
Sockets int `json:"sockets,omitempty"` | ||
Threads int `json:"threads,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both Sockets and Threads are unused. We should either remove these variables or utilize them at
return &corev1.ResourceList{corev1.ResourceMemory: memoryResource}, &kubevirtcorev1.CPU{Cores: uint32(vpcus.Cores)}, nil |
machine-controller/pkg/cloudprovider/provider/kubevirt/provider.go
Lines 854 to 856 in 8b52fcc
virtualMachine.Spec.Template.Spec.Domain.CPU = &kubevirtcorev1.CPU{ | |
Cores: c.VCPUs.Cores, | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the unused values and only left cores
for now.
Looks much better as part of the providerconfig 🚀 Same feedback as the first point from #1906 (comment), in release note please explicitly mention the "new field" that you have introduced i.e. |
cd442fb
to
2d40bf8
Compare
Signed-off-by: soer3n <[email protected]>
2d40bf8
to
966a390
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: 997ea22ccf2bb767bf1bf0be0f7c512163f0e8e8
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmedwaleedmalik The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/cherrypick release/v1.61 |
@soer3n: #1906 failed to apply on top of branch "release/v1.61":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
…ubermatic#1906) * change kubevirt vm cpu assignment to not overwrite cpu alloc ratio Signed-off-by: soer3n <[email protected]> * update kubevirt testdata Signed-off-by: soer3n <[email protected]> * revert testdata change and add condition for vm cpu assignment Signed-off-by: soer3n <[email protected]> * switch to providerSpec for enabling vcpu assignment Signed-off-by: soer3n <[email protected]> * adapt kubevirt cpu struct * adapt kubevirt cpu struct for configuring vcpus for a virtual machine * modify logic in function for rendering resource requests and limits * modify validation accordingly to be a bit more specific regarding resources Signed-off-by: soer3n <[email protected]> * revert unnessecarry changes to mocked kubevirt vm Signed-off-by: soer3n <[email protected]> * changes after review Signed-off-by: soer3n <[email protected]> --------- Signed-off-by: soer3n <[email protected]>
…ubermatic#1906) * change kubevirt vm cpu assignment to not overwrite cpu alloc ratio Signed-off-by: soer3n <[email protected]> * update kubevirt testdata Signed-off-by: soer3n <[email protected]> * revert testdata change and add condition for vm cpu assignment Signed-off-by: soer3n <[email protected]> * switch to providerSpec for enabling vcpu assignment Signed-off-by: soer3n <[email protected]> * adapt kubevirt cpu struct * adapt kubevirt cpu struct for configuring vcpus for a virtual machine * modify logic in function for rendering resource requests and limits * modify validation accordingly to be a bit more specific regarding resources Signed-off-by: soer3n <[email protected]> * revert unnessecarry changes to mocked kubevirt vm Signed-off-by: soer3n <[email protected]> * changes after review Signed-off-by: soer3n <[email protected]> --------- Signed-off-by: soer3n <[email protected]>
* Change KubeVirt VM CPU assignment to not overwrite cpu alloc ratio (#1906) * change kubevirt vm cpu assignment to not overwrite cpu alloc ratio Signed-off-by: soer3n <[email protected]> * update kubevirt testdata Signed-off-by: soer3n <[email protected]> * revert testdata change and add condition for vm cpu assignment Signed-off-by: soer3n <[email protected]> * switch to providerSpec for enabling vcpu assignment Signed-off-by: soer3n <[email protected]> * adapt kubevirt cpu struct * adapt kubevirt cpu struct for configuring vcpus for a virtual machine * modify logic in function for rendering resource requests and limits * modify validation accordingly to be a bit more specific regarding resources Signed-off-by: soer3n <[email protected]> * revert unnessecarry changes to mocked kubevirt vm Signed-off-by: soer3n <[email protected]> * changes after review Signed-off-by: soer3n <[email protected]> --------- Signed-off-by: soer3n <[email protected]> * fix kubevirt cpu check + update sdk version in go.mod Signed-off-by: soer3n <[email protected]> revert change regarding import of sdk submodule Signed-off-by: soer3n <[email protected]> kubevirt resources and vcpus should only be parsed wihtout specified instance type Signed-off-by: soer3n <[email protected]> --------- Signed-off-by: soer3n <[email protected]>
What this PR does / why we need it:
This pr changes the assignment of cpu resources for kubevirt virtual machines to be able to use kubevirt
cpuAllocationRatio
feature by introducing a new field to the providerSpec called vCPUs.Which issue(s) this PR fixes:
Fixes #1905
What type of PR is this?
/kind feature
Special notes for your reviewer:
Does this PR introduce a user-facing change? Then add your Release Note here:
Documentation: