Skip to content

Commit

Permalink
VirtualMachineSets can now be scaled down (#144)
Browse files Browse the repository at this point in the history
* VirtualMachineSets can now be scaled down

* VirtualMachineSets can now be scaled down refactor with one cycle

* remove old comment

---------

Co-authored-by: Maksym Veres <Maksym.Veres@sva.de>
  • Loading branch information
maxsva and Maksym Veres authored Jun 12, 2023
1 parent e6a8f73 commit 4498adc
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions pkg/controllers/vmsetcontroller/vmsetcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ func (v *VirtualMachineSetController) reconcileVirtualMachineSet(vmset *hfv1.Vir
},
},
Labels: map[string]string{
"dynamic": "false",
"vmset": vmset.Name,
util.VirtualMachineTemplate: vmt.Name,
util.EnvironmentLabel: env.Name,
"bound": "false",
"ready": "false",
util.ScheduledEventLabel: vmset.ObjectMeta.Labels[util.ScheduledEventLabel],
"dynamic": "false",
"vmset": vmset.Name,
util.VirtualMachineTemplate: vmt.Name,
util.EnvironmentLabel: env.Name,
"bound": "false",
"ready": "false",
util.ScheduledEventLabel: vmset.ObjectMeta.Labels[util.ScheduledEventLabel],
},
},
Spec: hfv1.VirtualMachineSpec{
Expand All @@ -307,8 +307,7 @@ func (v *VirtualMachineSetController) reconcileVirtualMachineSet(vmset *hfv1.Vir
},
}


config := util.GetVMConfig(env,vmt)
config := util.GetVMConfig(env, vmt)

sshUser, exists := config["ssh_username"]
if exists {
Expand Down Expand Up @@ -345,22 +344,28 @@ func (v *VirtualMachineSetController) reconcileVirtualMachineSet(vmset *hfv1.Vir

_, err = v.hfClientSet.HobbyfarmV1().VirtualMachines(util.GetReleaseNamespace()).UpdateStatus(v.ctx, vm, metav1.UpdateOptions{})



if err != nil {
glog.Error(err)
}


err = util.VerifyVM(v.vmLister, vm)
if err != nil {
glog.Error(err)
}
}

//TODO handle case of scaling down VMSets
}

//-----------------------handle case of scaling down VMSets
if len(currentVMs) > vmset.Spec.Count {
needed_delete := len(currentVMs) - vmset.Spec.Count
for _, cur_vm := range currentVMs {
if !cur_vm.Status.Allocated {
v.hfClientSet.HobbyfarmV1().VirtualMachines(util.GetReleaseNamespace()).Delete(v.ctx, cur_vm.Name, metav1.DeleteOptions{} )
needed_delete--
if needed_delete == 0 {break}
}
}
}
//-----------------------------------------------------
vms, err := v.vmLister.List(labels.Set{
"vmset": string(vmset.Name),
}.AsSelector())
Expand All @@ -378,7 +383,7 @@ func (v *VirtualMachineSetController) reconcileVirtualMachineSet(vmset *hfv1.Vir
provisionedCount++
}

if(activeCount < vmset.Spec.Count){
if activeCount < vmset.Spec.Count {
glog.V(4).Infof("requeing VMset as there are not enough VMs ready")
v.enqueueVMSet(vmset)
}
Expand Down

0 comments on commit 4498adc

Please sign in to comment.