From df2a9f73d16883905af68cc49a7eda3e844fec1d Mon Sep 17 00:00:00 2001 From: Rodolfo Pacheco Date: Wed, 28 Oct 2020 11:35:35 -0400 Subject: [PATCH] WIP: Added errors on the vbmh package --- pkg/vbmh/errors.go | 23 +++++++++++++++++++++++ pkg/vbmh/machines.go | 40 +++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 pkg/vbmh/errors.go diff --git a/pkg/vbmh/errors.go b/pkg/vbmh/errors.go new file mode 100644 index 0000000..94e1bcc --- /dev/null +++ b/pkg/vbmh/errors.go @@ -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) +} diff --git a/pkg/vbmh/machines.go b/pkg/vbmh/machines.go index 36e20f5..8318893 100644 --- a/pkg/vbmh/machines.go +++ b/pkg/vbmh/machines.go @@ -146,13 +146,9 @@ func (ml *MachineList) identifyNodes(nodes map[airshipv1.VmRoles]airshipv1.NodeS if err != nil { return err } - // I haveehave empty sets initialized - for nodeIdx := 0; nodeIdx < (nodeCfg.Count.Active + nodeCfg.Count.Standby); nodeIdx++ { - - err := ml.scheduleIt(nodeRole, nodeCfg.Scheduling, bmList, scheduleSetMap) - if err != nil { - return err - } + err = ml.scheduleIt(nodeRole, nodeCfg, bmList, scheduleSetMap) + if err != nil { + return err } } @@ -185,18 +181,20 @@ func (ml *MachineList) initScheduleMaps(constraints []airshipv1.SchedulingOption 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 + nodeTarget := (nodeCfg.Count.Active + nodeCfg.Count.Standby) for _, bmh := range bmList.Items { - for _, constraint := range constraints { + for _, constraint := range nodeCfg.Scheduling { // Do I care about this constraint if scheduleSetMap[constraint].Active() { // Check if bmh has the label // There is a func (host *BareMetalHost) getLabel(name string) string { // Not sure why its not Public, so sing our won method - cLabelValue := scheduleSetMap[constraint].GetLabel(bmh.Labels) - if cLabelValue != "" { + cLabelValue, cFlavorValue := scheduleSetMap[constraint].GetLabels(bmh.Labels, nodeCfg.VmFlavor) + + if cLabelValue != "" && cFlavorValue != "" { // If its in th elist , theen this bmh is disqualified. Skip it if scheduleSetMap[constraint].Exists(cLabelValue) { 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 { // Lets add it to the list as a schedulable thing m := &Machine{ Bmh: bmh, ScheduleStatus: ToBeScheduled, } + // Probable need to use the nodeRole as a label here ml.bmhs = append(ml.bmhs, m) + nodeTarget = nodeTarget - 1 + if nodeTarget == 0 { + break + } } // ... validBmh = true } + if nodeTarget > 0 { + return ErrorUnableToFullySchedule{ + TargetNode: nodeRole, + TargetFlavor: nodeCfg.VmFlavor, + } + } return nil } @@ -241,9 +250,10 @@ func (ss *ScheduleSet) Exists(value string) bool { 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 { - return "" + return "", "" } - return labels[ss.label] + return labels[ss.label], labels[customLabel] + }