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

Easy fixes #2169

Merged
merged 2 commits into from
Apr 7, 2019
Merged

Easy fixes #2169

merged 2 commits into from
Apr 7, 2019

Conversation

ahadas
Copy link
Contributor

@ahadas ahadas commented Apr 3, 2019

What this PR does / why we need it:
This PR introduces easy fixes to issues that were discovered while testing namespace-limits:

  1. We no longer clear all settings in the resources/requests section when memory request is missing.
  2. We copy the namespace from a VM to its corresponding VMI when initializing the latter.

Special notes for your reviewer:
There is an on-going discussion in parallel on whether or not default memory should be set by Kubevirt. It is debatable and therefore IMO it is better to fix for the current code, even if it would be changed/removed anytime soon.

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Apr 3, 2019
This patch changes the way the default value for memory-request is
set so it won't clear the cpu-request, if the latter is set.

This fixes the following bug:
1. Have a namespace with no memory limits set.
2. Start a VM with cpu-request=X and no memory-request set.
3. The VM would start with memory-request=<default value> and
   cpu-request will not be set.

Signed-off-by: Arik Hadas <ahadas@redhat.com>
When creating a VMI from a VM, the Namespace that the VM resides in should
be copied to the VMI in order to fetch the namespace-limits properly in
the mutating webhook.

Signed-off-by: Arik Hadas <ahadas@redhat.com>
@ahadas
Copy link
Contributor Author

ahadas commented Apr 3, 2019

/cc @cynepco3hahue @davidvossel

@@ -112,9 +112,10 @@ func SetDefaults_Firmware(obj *Firmware) {
func SetDefaults_VirtualMachineInstance(obj *VirtualMachineInstance) {
// FIXME we need proper validation and configurable defaulting instead of this
if _, exists := obj.Spec.Domain.Resources.Requests[v1.ResourceMemory]; !exists {
obj.Spec.Domain.Resources.Requests = v1.ResourceList{
v1.ResourceMemory: resource.MustParse("8192Ki"),
if obj.Spec.Domain.Resources.Requests == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can requests even be nil here? wouldn't the if statement above this one cause a crash if it was?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I was surprised by that as well but I found out that:

type mm map[string]int
func main() {
        var aa mm
	fmt.Println(aa["b"])
	if aa == nil {
	   fmt.Println("nil")
	}
}

returns:

0
nil

I discovered that because without this block (lines 115-117), tests that don't set requests explode with panic on the assignment at line 118

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidvossel Just for reference from
https://blog.golang.org/go-maps-in-action

Map types are reference types, like pointers or slices, and so the value of m above is nil; it doesn't point to an initialized map. A nil map behaves like an empty map when reading, but attempts to write to a nil map will cause a runtime panic; don't do that.

}
obj.Spec.Domain.Resources.Requests[v1.ResourceMemory] = resource.MustParse("8192Ki")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, so we were clobbering the whole requests map if memory wasn't specified previously. good catch 👍

@@ -527,6 +527,7 @@ func (c *VMController) setupVMIFromVM(vm *virtv1.VirtualMachine) *virtv1.Virtual
vmi.ObjectMeta = vm.Spec.Template.ObjectMeta
vmi.ObjectMeta.Name = basename
vmi.ObjectMeta.GenerateName = basename
vmi.ObjectMeta.Namespace = vm.ObjectMeta.Namespace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine to set this I suppose. it shouldn't make any difference though. We create the vmi in the same namespace as its parent vm, so namespace gets assigned regardless

Copy link
Contributor Author

@ahadas ahadas Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, eventually the VMI would be created within the same namespace - I didn't investigate the whole flow but this is probably set relatively late since when not setting it here, the mutating-hook receives the VMI without the namespace and so the relevant namespace-limits are not applied.

@ahadas
Copy link
Contributor Author

ahadas commented Apr 7, 2019

/assign @cynepco3hahue

Copy link

@cynepco3hahue cynepco3hahue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@cynepco3hahue cynepco3hahue merged commit 77bd6a5 into kubevirt:master Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API release-note-none Denotes a PR that doesn't merit a release note. size/XS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants