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

Drop requirement for DBRs #85

Merged
merged 11 commits into from
Oct 5, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (d *DynamicBindController) reconcileDynamicBindRequest(dynamicBindRequest *

if err != nil {
glog.Errorf("error retrieving corresponding virtual machine claim %s for dynamic bind request %s", dynamicBindRequest.Spec.VirtualMachineClaim, dynamicBindRequest.Spec.Id)
return err
}

var dbcSelector metav1.ListOptions
Expand All @@ -161,6 +162,7 @@ func (d *DynamicBindController) reconcileDynamicBindRequest(dynamicBindRequest *

if err != nil {
glog.Errorf("Error while retrieving dynamic bind configurations, %v", err)
return err
}

var chosenDynamicBindConfiguration *hfv1.DynamicBindConfiguration
Expand All @@ -179,7 +181,7 @@ func (d *DynamicBindController) reconcileDynamicBindRequest(dynamicBindRequest *
}
if err != nil {
glog.Errorf("Error while retrieving environment %v", err)
return nil
return err
}

if !environment.Spec.BurstCapable {
Expand Down
96 changes: 63 additions & 33 deletions pkg/controllers/scheduledevent/scheduledeventcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ func (s ScheduledEventController) provisionScheduledEvent(templates *hfv1.Virtua
for envName, vmtMap := range se.Spec.RequiredVirtualMachines {
// get the environment we're provisioning into (envName)
env, err := s.hfClientSet.HobbyfarmV1().Environments().Get(s.ctx, envName, metav1.GetOptions{})

if err != nil {
glog.Errorf("error retreiving environment %s", err.Error())
return err
}
// get all vmsets that are being provisioned into this environment (label selector)
vmsList, err := s.hfClientSet.HobbyfarmV1().VirtualMachineSets().List(s.ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("environment=%s", envName),
Expand Down Expand Up @@ -281,43 +284,70 @@ func (s ScheduledEventController) provisionScheduledEvent(templates *hfv1.Virtua

for templateName, count := range vmtMap {
if count > 0 && !se.Spec.OnDemand { // only setup vmsets if >0 VMs are requested, and they aren't ondemand
vmsRand := fmt.Sprintf("%s-%08x", baseNameScheduledPrefix, rand.Uint32())
vmsName := strings.Join([]string{"se", se.Name, "vms", vmsRand}, "-")
vmSets = append(vmSets, vmsName)
vms := &hfv1.VirtualMachineSet{
ObjectMeta: metav1.ObjectMeta{
Name: vmsName,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "hobbyfarm.io/v1",
Kind: "ScheduledEvent",
Name: se.Name,
UID: se.UID,
if len(se.Status.VirtualMachineSets) == 0 {
vmsRand := fmt.Sprintf("%s-%08x", baseNameScheduledPrefix, rand.Uint32())
vmsName := strings.Join([]string{"se", se.Name, "vms", vmsRand}, "-")
vmSets = append(vmSets, vmsName)
vms := &hfv1.VirtualMachineSet{
ObjectMeta: metav1.ObjectMeta{
Name: vmsName,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "hobbyfarm.io/v1",
Kind: "ScheduledEvent",
Name: se.Name,
UID: se.UID,
},
},
Labels: map[string]string{
"environment": env.Name,
"scheduledevent": se.Name,
fmt.Sprintf("virtualmachinetemplate.hobbyfarm.io/%s", templateName): "true",
},
},
Labels: map[string]string{
"environment": env.Name,
"scheduledevent": se.Name,
fmt.Sprintf("virtualmachinetemplate.hobbyfarm.io/%s", templateName): "true",
Spec: hfv1.VirtualMachineSetSpec{
Count: count,
Environment: envName,
VMTemplate: templateName,
BaseName: vmsRand,
},
},
Spec: hfv1.VirtualMachineSetSpec{
Count: count,
Environment: envName,
VMTemplate: templateName,
BaseName: vmsRand,
},
}
if se.Spec.RestrictedBind {
vms.Spec.RestrictedBind = true
vms.Spec.RestrictedBindValue = se.Spec.RestrictedBindValue
}
if se.Spec.RestrictedBind {
vms.Spec.RestrictedBind = true
vms.Spec.RestrictedBindValue = se.Spec.RestrictedBindValue
} else {
vms.Spec.RestrictedBind = false
}
_, err = s.hfClientSet.HobbyfarmV1().VirtualMachineSets().Create(s.ctx, vms, metav1.CreateOptions{})
if err != nil {
glog.Error(err)
return err
}
} else {
vms.Spec.RestrictedBind = false
}
vms, err := s.hfClientSet.HobbyfarmV1().VirtualMachineSets().Create(s.ctx, vms, metav1.CreateOptions{})
if err != nil {
glog.Error(err)
vmSetName := se.Status.VirtualMachineSets[0]
vmSetOrg, err := s.hfClientSet.HobbyfarmV1().VirtualMachineSets().Get(s.ctx, vmSetName, metav1.GetOptions{})
if err != nil {
glog.Error(err)
return err
}

vmSetOrg.Labels["environment"] = env.Name
vmSetOrg.Spec.Count = count
vmSetOrg.Spec.Environment = envName
vmSetOrg.Spec.VMTemplate = templateName
if se.Spec.RestrictedBind {
vmSetOrg.Spec.RestrictedBind = true

} else {
vmSetOrg.Spec.RestrictedBind = false
}
_, err = s.hfClientSet.HobbyfarmV1().VirtualMachineSets().Update(s.ctx, vmSetOrg, metav1.UpdateOptions{})
if err != nil {
glog.Errorf("error updating vmset config %s", err.Error())
return err
}
}

}
}

Expand Down
24 changes: 3 additions & 21 deletions pkg/controllers/session/sessioncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,9 @@ func (s *SessionController) reconcileSession(ssName string) error {

timeUntilExpires := expires.Sub(now)

// clean up old (3 hours later) sessions, and only if they are finished
if expires.Add(SessionExpireTime).Before(now) && ss.Status.Finished {
// first we need to delete the DynamicBindRequests
err := s.hfClientSet.HobbyfarmV1().DynamicBindRequests().DeleteCollection(s.ctx, metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: fmt.Sprintf("hobbyfarm.io/session=%s", ss.Name),
})

if err != nil {
return fmt.Errorf("error deleting dynamicbindrequests with session label %s: %s", ss.Name, err)
}

// then we need to delete the vmclaims
err = s.hfClientSet.HobbyfarmV1().VirtualMachineClaims().DeleteCollection(s.ctx, metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: fmt.Sprintf("hobbyfarm.io/session=%s", ss.Name),
})

if err != nil {
return fmt.Errorf("error deleting vmclaims with session label %s: %s", ss.Name, err)
}

glog.V(6).Infof("deleted vmclaims for old session %s", ss.Name)
// clean up sessions if they are finished
if ss.Status.Finished {
glog.V(6).Infof("deleted finished session %s", ss.Name)

// now that the vmclaims are deleted, go ahead and delete the session
err = s.hfClientSet.HobbyfarmV1().Sessions().Delete(s.ctx, ss.Name, metav1.DeleteOptions{})
Expand Down
Loading