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

🐛 Fix NPE when VM does not have a Reserved field #309

Merged
merged 1 commit into from
Dec 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *Reconciler) deleteResourcePolicy(ctx *context.VirtualMachineSetResource
}

for _, vm := range vmsInNamespace.Items {
if vm.Spec.Reserved.ResourcePolicyName == resourcePolicy.Name {
if reserved := vm.Spec.Reserved; reserved != nil && reserved.ResourcePolicyName == resourcePolicy.Name {
return fmt.Errorf("failing VirtualMachineSetResourcePolicy deletion since VM: '%s' is referencing it, resourcePolicyName: '%s'",
vm.NamespacedName(), resourcePolicy.NamespacedName())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func unitTestsReconcile() {

resourcePolicyCtx *context.VirtualMachineSetResourcePolicyContextA2
resourcePolicy *vmopv1.VirtualMachineSetResourcePolicy
vm *vmopv1.VirtualMachine
vm, vmNoReserved *vmopv1.VirtualMachine
)

BeforeEach(func() {
Expand All @@ -47,6 +47,12 @@ func unitTestsReconcile() {
},
Spec: vmopv1.VirtualMachineSetResourcePolicySpec{},
}
vmNoReserved = &vmopv1.VirtualMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "dummy-vm-no-reserved",
Namespace: "dummy-ns",
},
}
vm = &vmopv1.VirtualMachine{
ObjectMeta: metav1.ObjectMeta{
Name: "dummy-vm",
Expand Down Expand Up @@ -103,7 +109,7 @@ func unitTestsReconcile() {

When("One or more VMs are referencing this policy", func() {
BeforeEach(func() {
initObjects = append(initObjects, vm)
initObjects = append(initObjects, vm, vmNoReserved)
})

AfterEach(func() {
Expand Down