WIP: Added errors on the vbmh package

This commit is contained in:
Rodolfo Pacheco 2020-10-28 11:35:35 -04:00
parent 0afa0db4c3
commit df2a9f73d1
2 changed files with 48 additions and 15 deletions

23
pkg/vbmh/errors.go Normal file
View File

@ -0,0 +1,23 @@
package vbmh
import (
"fmt"
airshipv1 "sipcluster/pkg/api/v1"
)
// ErrAuthTypeNotSupported is returned when wrong AuthType is provided
type ErrorConstraintNotFound struct {
}
func (e ErrorConstraintNotFound) Error() string {
return "Invalid or Not found Schedulign Constraint"
}
type ErrorUnableToFullySchedule struct {
TargetNode airshipv1.VmRoles
TargetFlavor string
}
func (e ErrorUnableToFullySchedule) Error() string {
return fmt.Sprintf("Unable to complete a schedule targetting %v nodes, which a floavor of %v ", e.TargetNode, e.TargetFlavor)
}

View File

@ -146,15 +146,11 @@ func (ml *MachineList) identifyNodes(nodes map[airshipv1.VmRoles]airshipv1.NodeS
if err != nil { if err != nil {
return err return err
} }
// I haveehave empty sets initialized err = ml.scheduleIt(nodeRole, nodeCfg, bmList, scheduleSetMap)
for nodeIdx := 0; nodeIdx < (nodeCfg.Count.Active + nodeCfg.Count.Standby); nodeIdx++ {
err := ml.scheduleIt(nodeRole, nodeCfg.Scheduling, bmList, scheduleSetMap)
if err != nil { if err != nil {
return err return err
} }
} }
}
return nil return nil
} }
@ -185,18 +181,20 @@ func (ml *MachineList) initScheduleMaps(constraints []airshipv1.SchedulingOption
return setMap, nil return setMap, nil
} }
func (ml *MachineList) scheduleIt(nodeRole airshipv1.VmRoles, constraints []airshipv1.SchedulingOptions, bmList *metal3.BareMetalHostList, scheduleSetMap map[airshipv1.SchedulingOptions]*ScheduleSet) error { func (ml *MachineList) scheduleIt(nodeRole airshipv1.VmRoles, nodeCfg airshipv1.NodeSet, bmList *metal3.BareMetalHostList, scheduleSetMap map[airshipv1.SchedulingOptions]*ScheduleSet) error {
validBmh := true validBmh := true
nodeTarget := (nodeCfg.Count.Active + nodeCfg.Count.Standby)
for _, bmh := range bmList.Items { for _, bmh := range bmList.Items {
for _, constraint := range constraints { for _, constraint := range nodeCfg.Scheduling {
// Do I care about this constraint // Do I care about this constraint
if scheduleSetMap[constraint].Active() { if scheduleSetMap[constraint].Active() {
// Check if bmh has the label // Check if bmh has the label
// There is a func (host *BareMetalHost) getLabel(name string) string { // There is a func (host *BareMetalHost) getLabel(name string) string {
// Not sure why its not Public, so sing our won method // Not sure why its not Public, so sing our won method
cLabelValue := scheduleSetMap[constraint].GetLabel(bmh.Labels) cLabelValue, cFlavorValue := scheduleSetMap[constraint].GetLabels(bmh.Labels, nodeCfg.VmFlavor)
if cLabelValue != "" {
if cLabelValue != "" && cFlavorValue != "" {
// If its in th elist , theen this bmh is disqualified. Skip it // If its in th elist , theen this bmh is disqualified. Skip it
if scheduleSetMap[constraint].Exists(cLabelValue) { if scheduleSetMap[constraint].Exists(cLabelValue) {
validBmh = false validBmh = false
@ -205,20 +203,31 @@ func (ml *MachineList) scheduleIt(nodeRole airshipv1.VmRoles, constraints []airs
} }
} }
} }
// All the constraints have been checcked // All the constraints have been checked
if validBmh { if validBmh {
// Lets add it to the list as a schedulable thing // Lets add it to the list as a schedulable thing
m := &Machine{ m := &Machine{
Bmh: bmh, Bmh: bmh,
ScheduleStatus: ToBeScheduled, ScheduleStatus: ToBeScheduled,
} }
// Probable need to use the nodeRole as a label here
ml.bmhs = append(ml.bmhs, m) ml.bmhs = append(ml.bmhs, m)
nodeTarget = nodeTarget - 1
if nodeTarget == 0 {
break
}
} }
// ... // ...
validBmh = true validBmh = true
} }
if nodeTarget > 0 {
return ErrorUnableToFullySchedule{
TargetNode: nodeRole,
TargetFlavor: nodeCfg.VmFlavor,
}
}
return nil return nil
} }
@ -241,9 +250,10 @@ func (ss *ScheduleSet) Exists(value string) bool {
return false return false
} }
func (ss *ScheduleSet) GetLabel(labels map[string]string) string { func (ss *ScheduleSet) GetLabels(labels map[string]string, customLabel string) (string, string) {
if labels == nil { if labels == nil {
return "" return "", ""
} }
return labels[ss.label] return labels[ss.label], labels[customLabel]
} }