Split scheduling label into namespace/name
Closes: #15 Signed-off-by: Sean Eagan <seaneagan1@gmail.com> Change-Id: I03504f4f57a418ab9f2bc927e149e57597fab3b4
This commit is contained in:
parent
068afe5bb9
commit
459504111b
1
go.sum
1
go.sum
@ -822,6 +822,7 @@ k8s.io/apimachinery v0.19.0/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlm
|
||||
k8s.io/apimachinery v0.19.2 h1:5Gy9vQpAGTKHPVOh5c4plE274X8D/6cuEiTO2zve7tc=
|
||||
k8s.io/apimachinery v0.19.2/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
|
||||
k8s.io/apimachinery v0.20.4 h1:vhxQ0PPUUU2Ns1b9r4/UFp13UPs8cw2iOoTjnY9faa0=
|
||||
k8s.io/apimachinery v0.20.5 h1:wO/FxMVRn223rAKxnBbwCyuN96bS9MFTIvP0e/V7cps=
|
||||
k8s.io/apiserver v0.18.6/go.mod h1:Zt2XvTHuaZjBz6EFYzpp+X4hTmgWGy8AthNVnTdm3Wg=
|
||||
k8s.io/apiserver v0.19.2/go.mod h1:FreAq0bJ2vtZFj9Ago/X0oNGC51GfubKK/ViOKfVAOA=
|
||||
k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q=
|
||||
|
@ -62,9 +62,9 @@ const (
|
||||
const (
|
||||
BaseAirshipSelector = "sip.airshipit.org"
|
||||
|
||||
// This label is applied to all BMHs scheduled to a given SIPCluster.
|
||||
SipClusterLabelName = "cluster"
|
||||
SipClusterLabel = BaseAirshipSelector + "/" + SipClusterLabelName
|
||||
// These labels are applied to all BMHs scheduled to a given SIPCluster.
|
||||
SipClusterNamespaceLabel = BaseAirshipSelector + "/" + "cluster-namespace"
|
||||
SipClusterNameLabel = BaseAirshipSelector + "/" + "cluster-name"
|
||||
|
||||
SipNodeTypeLabelName = "node-type"
|
||||
SipNodeTypeLabel = BaseAirshipSelector + "/" + SipNodeTypeLabelName
|
||||
@ -188,7 +188,7 @@ func (ml *MachineList) getBMHs(c client.Client) (*metal3.BareMetalHostList, erro
|
||||
|
||||
// Select BMH not yet labeled as scheduled by SIP
|
||||
unscheduledSelector := labels.NewSelector()
|
||||
r, err := labels.NewRequirement(SipClusterLabel, selection.DoesNotExist, nil)
|
||||
r, err := labels.NewRequirement(SipClusterNameLabel, selection.DoesNotExist, nil)
|
||||
if err == nil {
|
||||
unscheduledSelector = unscheduledSelector.Add(*r)
|
||||
}
|
||||
@ -219,7 +219,7 @@ func (ml *MachineList) identifyNodes(sip airshipv1.SIPCluster,
|
||||
logger.Info("Getting host constraints")
|
||||
scheduleSetMap := ml.initScheduleMaps(nodeRole, nodeCfg.TopologyKey)
|
||||
logger.Info("Matching hosts against constraints")
|
||||
err := ml.scheduleIt(nodeRole, nodeCfg, bmhList, scheduleSetMap, c, GetClusterLabel(sip))
|
||||
err := ml.scheduleIt(nodeRole, nodeCfg, bmhList, scheduleSetMap, c, sip)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -240,13 +240,11 @@ func (ml *MachineList) initScheduleMaps(role airshipv1.BMHRole,
|
||||
}
|
||||
|
||||
func (ml *MachineList) countScheduledAndTobeScheduled(nodeRole airshipv1.BMHRole,
|
||||
c client.Client, clusterName string) int {
|
||||
c client.Client, sip airshipv1.SIPCluster) int {
|
||||
bmhList := &metal3.BareMetalHostList{}
|
||||
|
||||
scheduleLabels := map[string]string{
|
||||
SipClusterLabel: clusterName,
|
||||
SipNodeTypeLabel: string(nodeRole),
|
||||
}
|
||||
scheduleLabels := GetClusterLabels(sip)
|
||||
scheduleLabels[SipNodeTypeLabel] = string(nodeRole)
|
||||
|
||||
logger := ml.Log.WithValues("role", nodeRole)
|
||||
logger.Info("Getting list of BaremetalHost already scheduled for SIP cluster from kubernetes")
|
||||
@ -284,14 +282,14 @@ func (ml *MachineList) countScheduledAndTobeScheduled(nodeRole airshipv1.BMHRole
|
||||
|
||||
func (ml *MachineList) scheduleIt(nodeRole airshipv1.BMHRole, nodeCfg airshipv1.NodeSet,
|
||||
bmList *metal3.BareMetalHostList, scheduleSet *ScheduleSet,
|
||||
c client.Client, clusterName string) error {
|
||||
c client.Client, sip airshipv1.SIPCluster) error {
|
||||
logger := ml.Log.WithValues("role", nodeRole)
|
||||
validBmh := true
|
||||
// Count the expectations stated in the CR
|
||||
// Reduce from the list of BMH's already scheduled and labeled with the Cluster Name
|
||||
// Reduce from the number of Machines I have identified already to be Labeled
|
||||
totalNodes := nodeCfg.Count.Active + nodeCfg.Count.Standby
|
||||
nodeTarget := totalNodes - ml.countScheduledAndTobeScheduled(nodeRole, c, clusterName)
|
||||
nodeTarget := totalNodes - ml.countScheduledAndTobeScheduled(nodeRole, c, sip)
|
||||
|
||||
logger.Info("BMH count that need to be scheduled for SIP cluster discouting nodes ready to be scheduled",
|
||||
"BMH count to be scheduled", nodeTarget)
|
||||
@ -704,7 +702,9 @@ func (ml *MachineList) ApplyLabels(sip airshipv1.SIPCluster, c client.Client) er
|
||||
if machine.ScheduleStatus == ToBeScheduled {
|
||||
bmh := &machine.BMH
|
||||
fmt.Printf("ApplyLabels bmh.ObjectMeta.Name:%s\n", bmh.ObjectMeta.Name)
|
||||
bmh.Labels[SipClusterLabel] = GetClusterLabel(sip)
|
||||
for k, v := range GetClusterLabels(sip) {
|
||||
bmh.Labels[k] = v
|
||||
}
|
||||
bmh.Labels[SipNodeTypeLabel] = string(machine.BMHRole)
|
||||
|
||||
// This is bombing when it find 1 error
|
||||
@ -726,7 +726,8 @@ func (ml *MachineList) RemoveLabels(c client.Client) error {
|
||||
for _, machine := range ml.Machines {
|
||||
bmh := &machine.BMH
|
||||
fmt.Printf("RemoveLabels bmh.ObjectMeta.Name:%s\n", bmh.ObjectMeta.Name)
|
||||
delete(bmh.Labels, SipClusterLabel)
|
||||
delete(bmh.Labels, SipClusterNamespaceLabel)
|
||||
delete(bmh.Labels, SipClusterNameLabel)
|
||||
delete(bmh.Labels, SipNodeTypeLabel)
|
||||
|
||||
// This is bombing when it find 1 error
|
||||
@ -746,10 +747,7 @@ func (ml *MachineList) GetCluster(sip airshipv1.SIPCluster, c client.Client) err
|
||||
ml.init(sip.Spec.Nodes)
|
||||
|
||||
bmhList := &metal3.BareMetalHostList{}
|
||||
scheduleLabels := map[string]string{
|
||||
SipClusterLabel: GetClusterLabel(sip),
|
||||
}
|
||||
|
||||
scheduleLabels := GetClusterLabels(sip)
|
||||
err := c.List(context.Background(), bmhList, client.MatchingLabels(scheduleLabels))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -770,6 +768,9 @@ func (ml *MachineList) GetCluster(sip airshipv1.SIPCluster, c client.Client) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetClusterLabel(sip airshipv1.SIPCluster) string {
|
||||
return fmt.Sprintf("%s_%s", sip.GetNamespace(), sip.GetName())
|
||||
func GetClusterLabels(sip airshipv1.SIPCluster) map[string]string {
|
||||
return map[string]string{
|
||||
SipClusterNamespaceLabel: sip.GetNamespace(),
|
||||
SipClusterNameLabel: sip.GetName(),
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,10 @@ var _ = Describe("MachineList", func() {
|
||||
|
||||
It("Should produce a list of unscheduled BMH objects", func() {
|
||||
// "Schedule" two nodes
|
||||
machineList.Machines["node00"].BMH.Labels[SipClusterLabel] = "subcluster-1"
|
||||
machineList.Machines["node01"].BMH.Labels[SipClusterLabel] = "subcluster-1"
|
||||
machineList.Machines["node00"].BMH.Labels[SipClusterNamespaceLabel] = "default"
|
||||
machineList.Machines["node00"].BMH.Labels[SipClusterNameLabel] = "subcluster-1"
|
||||
machineList.Machines["node01"].BMH.Labels[SipClusterNamespaceLabel] = "default"
|
||||
machineList.Machines["node01"].BMH.Labels[SipClusterNameLabel] = "subcluster-1"
|
||||
scheduledNodes := []metal3.BareMetalHost{
|
||||
machineList.Machines["node00"].BMH,
|
||||
machineList.Machines["node01"].BMH,
|
||||
@ -86,7 +88,8 @@ var _ = Describe("MachineList", func() {
|
||||
// "Schedule" all nodes
|
||||
var objs []runtime.Object
|
||||
for _, machine := range machineList.Machines {
|
||||
machine.BMH.Labels[SipClusterLabel] = "subcluster-1"
|
||||
machine.BMH.Labels[SipClusterNamespaceLabel] = "default"
|
||||
machine.BMH.Labels[SipClusterNameLabel] = "subcluster-1"
|
||||
objs = append(objs, &machine.BMH)
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
|
||||
// Poll BMHs until SIP has scheduled them to the SIP cluster
|
||||
Eventually(func() error {
|
||||
expectedLabels := labels.SelectorFromSet(
|
||||
map[string]string{bmhpkg.SipClusterLabel: bmhpkg.GetClusterLabel(*sipCluster)})
|
||||
expectedLabels := labels.SelectorFromSet(bmhpkg.GetClusterLabels(*sipCluster))
|
||||
|
||||
var bmh metal3.BareMetalHost
|
||||
for node := range nodes {
|
||||
|
@ -21,15 +21,14 @@ var bmhRoleToLabelValue = map[airshipv1.BMHRole]string{
|
||||
|
||||
func UnscheduledSelector() labels.Selector {
|
||||
sel := labels.NewSelector()
|
||||
r, err := labels.NewRequirement(sipClusterLabel, selection.DoesNotExist, nil)
|
||||
r, err := labels.NewRequirement(sipClusterNameLabel, selection.DoesNotExist, nil)
|
||||
gomega.Expect(err).Should(gomega.Succeed())
|
||||
return sel.Add(*r)
|
||||
}
|
||||
|
||||
const (
|
||||
// NOTE(aw442m): These constants have been redefined from the bmh package in order to avoid an import cycle.
|
||||
sipClusterLabelName = "cluster"
|
||||
sipClusterLabel = "sip.airshipit.org" + "/" + sipClusterLabelName
|
||||
sipClusterNameLabel = "sip.airshipit.org/cluster-name"
|
||||
|
||||
HostLabel = "vino.airshipit.org/host"
|
||||
RackLabel = "vino.airshipit.org/rack"
|
||||
|
Loading…
x
Reference in New Issue
Block a user