Label vBMHs with SIP name along with namespace
Relates-To: #5 Change-Id: Ia3e553f5032ba199abc18345cd3fedbfe381578c
This commit is contained in:
parent
44ee037f5b
commit
58faa0d491
@ -242,7 +242,7 @@ func (ml *MachineList) identifyNodes(sip airshipv1.SIPCluster,
|
||||
return err
|
||||
}
|
||||
logger.Info("Matching hosts against constraints")
|
||||
err = ml.scheduleIt(nodeRole, nodeCfg, bmhList, scheduleSetMap, c, sip.GetNamespace())
|
||||
err = ml.scheduleIt(nodeRole, nodeCfg, bmhList, scheduleSetMap, c, GetClusterLabel(sip))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -273,12 +273,12 @@ func (ml *MachineList) initScheduleMaps(role airshipv1.BMHRole,
|
||||
}
|
||||
|
||||
func (ml *MachineList) countScheduledAndTobeScheduled(nodeRole airshipv1.BMHRole,
|
||||
c client.Client, namespace string) int {
|
||||
c client.Client, clusterName string) int {
|
||||
bmhList := &metal3.BareMetalHostList{}
|
||||
|
||||
scheduleLabels := map[string]string{
|
||||
SipScheduleLabel: "true",
|
||||
SipClusterLabel: namespace,
|
||||
SipClusterLabel: clusterName,
|
||||
SipNodeTypeLabel: string(nodeRole),
|
||||
}
|
||||
|
||||
@ -318,14 +318,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, namespace string) error {
|
||||
c client.Client, clusterName string) 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, namespace)
|
||||
nodeTarget := totalNodes - ml.countScheduledAndTobeScheduled(nodeRole, c, clusterName)
|
||||
|
||||
logger.Info("BMH count that need to be scheduled for SIP cluster discouting nodes ready to be scheduled",
|
||||
"BMH count to be scheduled", nodeTarget)
|
||||
@ -748,7 +748,7 @@ 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] = sip.GetNamespace()
|
||||
bmh.Labels[SipClusterLabel] = GetClusterLabel(sip)
|
||||
bmh.Labels[SipScheduleLabel] = "true"
|
||||
bmh.Labels[SipNodeTypeLabel] = string(machine.BMHRole)
|
||||
|
||||
@ -794,7 +794,7 @@ func (ml *MachineList) GetCluster(sip airshipv1.SIPCluster, c client.Client) err
|
||||
bmhList := &metal3.BareMetalHostList{}
|
||||
scheduleLabels := map[string]string{
|
||||
SipScheduleLabel: "true",
|
||||
SipClusterLabel: sip.GetNamespace(),
|
||||
SipClusterLabel: GetClusterLabel(sip),
|
||||
}
|
||||
|
||||
err := c.List(context.Background(), bmhList, client.MatchingLabels(scheduleLabels))
|
||||
@ -816,3 +816,7 @@ func (ml *MachineList) GetCluster(sip airshipv1.SIPCluster, c client.Client) err
|
||||
fmt.Printf("GetCluster %s \n", ml.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetClusterLabel(sip airshipv1.SIPCluster) string {
|
||||
return fmt.Sprintf("%s_%s", sip.GetNamespace(), sip.GetName())
|
||||
}
|
||||
|
@ -70,8 +70,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
}
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test1"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 3, 4)
|
||||
clusterName := "subcluster-test1"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 3, 4)
|
||||
Expect(k8sClient.Create(context.Background(), nodeSSHPrivateKeys)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
|
||||
|
||||
@ -79,7 +79,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
Eventually(func() error {
|
||||
expectedLabels := map[string]string{
|
||||
bmhpkg.SipScheduleLabel: "true",
|
||||
bmhpkg.SipClusterLabel: testNamespace,
|
||||
bmhpkg.SipClusterLabel: bmhpkg.GetClusterLabel(*sipCluster),
|
||||
}
|
||||
|
||||
var bmh metal3.BareMetalHost
|
||||
@ -107,8 +107,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
}
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test2"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 3, 4)
|
||||
clusterName := "subcluster-test2"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 3, 4)
|
||||
Expect(k8sClient.Create(context.Background(), nodeSSHPrivateKeys)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
|
||||
|
||||
@ -132,7 +132,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
// Validate SIP CR ready condition has been updated
|
||||
var sipCR airshipv1.SIPCluster
|
||||
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
Name: name,
|
||||
Name: clusterName,
|
||||
Namespace: testNamespace,
|
||||
}, &sipCR)).To(Succeed())
|
||||
|
||||
@ -154,8 +154,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
}
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test4"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 3, 4)
|
||||
clusterName := "subcluster-test4"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 3, 4)
|
||||
Expect(k8sClient.Create(context.Background(), nodeSSHPrivateKeys)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
|
||||
|
||||
@ -179,7 +179,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
// Validate SIP CR ready condition has been updated
|
||||
var sipCR airshipv1.SIPCluster
|
||||
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
Name: name,
|
||||
Name: clusterName,
|
||||
Namespace: testNamespace,
|
||||
}, &sipCR)).To(Succeed())
|
||||
|
||||
@ -217,8 +217,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test5"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 1, 2)
|
||||
clusterName := "subcluster-test5"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 1, 2)
|
||||
Expect(k8sClient.Create(context.Background(), nodeSSHPrivateKeys)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
|
||||
|
||||
@ -242,7 +242,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
// Validate SIP CR ready condition has been updated
|
||||
var sipCR airshipv1.SIPCluster
|
||||
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
Name: name,
|
||||
Name: clusterName,
|
||||
Namespace: testNamespace,
|
||||
}, &sipCR)).To(Succeed())
|
||||
|
||||
@ -279,8 +279,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test6"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 2, 1)
|
||||
clusterName := "subcluster-test6"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 2, 1)
|
||||
Expect(k8sClient.Create(context.Background(), nodeSSHPrivateKeys)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
|
||||
|
||||
@ -304,7 +304,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
// Validate SIP CR ready condition has been updated
|
||||
var sipCR airshipv1.SIPCluster
|
||||
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
Name: name,
|
||||
Name: clusterName,
|
||||
Namespace: testNamespace,
|
||||
}, &sipCR)).To(Succeed())
|
||||
|
||||
@ -340,8 +340,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test3"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 1, 2)
|
||||
clusterName := "subcluster-test3"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 1, 2)
|
||||
|
||||
controlPlaneSpec := sipCluster.Spec.Nodes[airshipv1.RoleControlPlane]
|
||||
controlPlaneSpec.Scheduling = airshipv1.RackAntiAffinity
|
||||
@ -374,7 +374,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
// Validate SIP CR ready condition has been updated
|
||||
var sipCR airshipv1.SIPCluster
|
||||
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
Name: name,
|
||||
Name: clusterName,
|
||||
Namespace: testNamespace,
|
||||
}, &sipCR)).To(Succeed())
|
||||
|
||||
@ -407,8 +407,8 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
|
||||
|
||||
// Create SIP cluster
|
||||
name := "subcluster-test3"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(name, testNamespace, 2, 1)
|
||||
clusterName := "subcluster-test3"
|
||||
sipCluster, nodeSSHPrivateKeys := testutil.CreateSIPCluster(clusterName, testNamespace, 2, 1)
|
||||
|
||||
controlPlaneSpec := sipCluster.Spec.Nodes[airshipv1.RoleControlPlane]
|
||||
controlPlaneSpec.Scheduling = airshipv1.RackAntiAffinity
|
||||
@ -441,7 +441,7 @@ var _ = Describe("SIPCluster controller", func() {
|
||||
// Validate SIP CR ready condition has been updated
|
||||
var sipCR airshipv1.SIPCluster
|
||||
Expect(k8sClient.Get(context.Background(), types.NamespacedName{
|
||||
Name: name,
|
||||
Name: clusterName,
|
||||
Namespace: testNamespace,
|
||||
}, &sipCR)).To(Succeed())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user