Remove ClusterName from SIPCluster CR

Previously, this field was used as the namespace for the infrastructure
services created by the SIPCluster. Prior to this change, the name of
the SIPCluster (as found in the metadata) will be used as the namespace
for created services.

Change-Id: I15fa173a857c88ccc937d1e962e269226acf04fb
This commit is contained in:
Ian Howell 2021-03-03 15:15:18 -06:00
parent c107e09f89
commit 98c5286870
9 changed files with 32 additions and 64 deletions

View File

@ -36,10 +36,6 @@ spec:
spec:
description: SIPClusterSpec defines the desired state of a SIPCluster
properties:
clusterName:
description: ClusterName is the name of the cluster to associate machines
with
type: string
nodes:
additionalProperties:
description: 'NodeSet are the the list of Nodes objects workers, or

View File

@ -6,8 +6,6 @@ metadata:
finalizers:
- sip.airship.airshipit.org/finalizer
spec:
# TODO: This field will be removed in the future.
clusterName: subcluster-test
nodes:
ControlPlane:
vmFlavor: vino.airshipit.org/flavor=control-plane

View File

@ -210,17 +210,6 @@ SIPClusterSpec
<table>
<tr>
<td>
<code>clusterName</code><br>
<em>
string
</em>
</td>
<td>
<p>ClusterName is the name of the cluster to associate machines with</p>
</td>
</tr>
<tr>
<td>
<code>nodes</code><br>
<em>
<a href="#airship.airshipit.org/v1.NodeSet">
@ -414,17 +403,6 @@ string
<tbody>
<tr>
<td>
<code>clusterName</code><br>
<em>
string
</em>
</td>
<td>
<p>ClusterName is the name of the cluster to associate machines with</p>
</td>
</tr>
<tr>
<td>
<code>nodes</code><br>
<em>
<a href="#airship.airshipit.org/v1.NodeSet">

View File

@ -49,9 +49,6 @@ type SIPClusterSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make manifests to regenerate code after modifying this file
// ClusterName is the name of the cluster to associate machines with
ClusterName string `json:"clusterName,omitempty"`
// Nodes defines the set of nodes to schedule for each vm role.
Nodes map[VMRole]NodeSet `json:"nodes,omitempty"`

View File

@ -308,7 +308,7 @@ func (r *SIPClusterReconciler) gatherVBMH(ctx context.Context, sip airshipv1.SIP
func (r *SIPClusterReconciler) deployInfra(sip airshipv1.SIPCluster, machines *airshipvms.MachineList,
logger logr.Logger) error {
if err := airshipsvc.CreateNS(sip.Spec.ClusterName, r.Client); err != nil {
if err := airshipsvc.CreateNS(sip.Name, r.Client); err != nil {
return err
}
newServiceSet := airshipsvc.NewServiceSet(logger, sip, machines, r.Client)

View File

@ -70,15 +70,15 @@ var _ = Describe("SIPCluster controller", func() {
}
// Create SIP cluster
clusterName := "subcluster-test1"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 3, 4)
name := "subcluster-test1"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 3, 4)
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
// Poll BMHs until SIP has scheduled them to the SIP cluster
Eventually(func() error {
expectedLabels := map[string]string{
vbmh.SipScheduleLabel: "true",
vbmh.SipClusterLabel: clusterName,
vbmh.SipClusterLabel: name,
}
var bmh metal3.BareMetalHost
@ -106,8 +106,8 @@ var _ = Describe("SIPCluster controller", func() {
}
// Create SIP cluster
clusterName := "subcluster-test2"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 3, 4)
name := "subcluster-test2"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 3, 4)
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
// Poll BMHs and validate they are not scheduled
@ -130,7 +130,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: clusterName,
Name: name,
Namespace: testNamespace,
}, &sipCR)).To(Succeed())
@ -152,8 +152,8 @@ var _ = Describe("SIPCluster controller", func() {
}
// Create SIP cluster
clusterName := "subcluster-test4"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 3, 4)
name := "subcluster-test4"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 3, 4)
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
// Poll BMHs and validate they are not scheduled
@ -176,7 +176,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: clusterName,
Name: name,
Namespace: testNamespace,
}, &sipCR)).To(Succeed())
@ -214,8 +214,8 @@ var _ = Describe("SIPCluster controller", func() {
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
// Create SIP cluster
clusterName := "subcluster-test5"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 1, 2)
name := "subcluster-test5"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 1, 2)
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
// Poll BMHs and validate they are not scheduled
@ -238,7 +238,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: clusterName,
Name: name,
Namespace: testNamespace,
}, &sipCR)).To(Succeed())
@ -275,8 +275,8 @@ var _ = Describe("SIPCluster controller", func() {
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
// Create SIP cluster
clusterName := "subcluster-test6"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 2, 1)
name := "subcluster-test6"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 2, 1)
Expect(k8sClient.Create(context.Background(), sipCluster)).Should(Succeed())
// Poll BMHs and validate they are not scheduled
@ -299,7 +299,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: clusterName,
Name: name,
Namespace: testNamespace,
}, &sipCR)).To(Succeed())
@ -335,8 +335,8 @@ var _ = Describe("SIPCluster controller", func() {
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
// Create SIP cluster
clusterName := "subcluster-test3"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 1, 2)
name := "subcluster-test3"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 1, 2)
controlPlaneSpec := sipCluster.Spec.Nodes[airshipv1.VMControlPlane]
controlPlaneSpec.Scheduling = airshipv1.RackAntiAffinity
@ -368,7 +368,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: clusterName,
Name: name,
Namespace: testNamespace,
}, &sipCR)).To(Succeed())
@ -401,8 +401,8 @@ var _ = Describe("SIPCluster controller", func() {
Expect(k8sClient.Create(context.Background(), networkData)).Should(Succeed())
// Create SIP cluster
clusterName := "subcluster-test3"
sipCluster := testutil.CreateSIPCluster(clusterName, testNamespace, 2, 1)
name := "subcluster-test3"
sipCluster := testutil.CreateSIPCluster(name, testNamespace, 2, 1)
controlPlaneSpec := sipCluster.Spec.Nodes[airshipv1.VMControlPlane]
controlPlaneSpec.Scheduling = airshipv1.RackAntiAffinity
@ -434,7 +434,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: clusterName,
Name: name,
Namespace: testNamespace,
}, &sipCR)).To(Succeed())

View File

@ -65,7 +65,7 @@ func (ss ServiceSet) Finalize() error {
Kind: "Namespace",
},
ObjectMeta: metav1.ObjectMeta{
Name: ss.sip.Spec.ClusterName,
Name: ss.sip.GetName(),
},
}
return ss.client.Delete(context.TODO(), serviceNamespace)
@ -98,7 +98,7 @@ func (ss ServiceSet) ServiceList() ([]InfraService, error) {
for _, svc := range services.LoadBalancer {
serviceList = append(serviceList,
newLB(ss.sip.GetName(),
ss.sip.Spec.ClusterName,
ss.sip.GetName(),
ss.logger,
svc,
ss.machines,
@ -110,7 +110,7 @@ func (ss ServiceSet) ServiceList() ([]InfraService, error) {
for _, svc := range services.JumpHost {
serviceList = append(serviceList,
newJumpHost(ss.sip.GetName(),
ss.sip.Spec.ClusterName,
ss.sip.GetName(),
ss.logger,
svc,
ss.machines,

View File

@ -240,7 +240,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.Spec.ClusterName)
err = ml.scheduleIt(nodeRole, nodeCfg, bmhList, scheduleSetMap, c, sip.GetName())
if err != nil {
return err
}
@ -271,12 +271,12 @@ func (ml *MachineList) initScheduleMaps(role airshipv1.VMRole,
}
func (ml *MachineList) countScheduledAndTobeScheduled(nodeRole airshipv1.VMRole,
c client.Client, clusterName string) int {
c client.Client, namespace string) int {
bmhList := &metal3.BareMetalHostList{}
scheduleLabels := map[string]string{
SipScheduleLabel: "true",
SipClusterLabel: clusterName,
SipClusterLabel: namespace,
SipNodeTypeLabel: string(nodeRole),
}
@ -316,14 +316,14 @@ func (ml *MachineList) countScheduledAndTobeScheduled(nodeRole airshipv1.VMRole,
func (ml *MachineList) scheduleIt(nodeRole airshipv1.VMRole, nodeCfg airshipv1.NodeSet,
bmList *metal3.BareMetalHostList, scheduleSet *ScheduleSet,
c client.Client, clusterName string) error {
c client.Client, namespace 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, clusterName)
nodeTarget := totalNodes - ml.countScheduledAndTobeScheduled(nodeRole, c, namespace)
logger.Info("BMH count that need to be scheduled for SIP cluster discouting nodes ready to be scheduled",
"BMH count to be scheduled", nodeTarget)
@ -743,7 +743,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.Spec.ClusterName
bmh.Labels[SipClusterLabel] = sip.GetName()
bmh.Labels[SipScheduleLabel] = "true"
bmh.Labels[SipNodeTypeLabel] = string(machine.VMRole)
@ -789,7 +789,7 @@ func (ml *MachineList) GetCluster(sip airshipv1.SIPCluster, c client.Client) err
bmhList := &metal3.BareMetalHostList{}
scheduleLabels := map[string]string{
SipScheduleLabel: "true",
SipClusterLabel: sip.Spec.ClusterName,
SipClusterLabel: sip.GetName(),
}
err := c.List(context.Background(), bmhList, client.MatchingLabels(scheduleLabels))

View File

@ -218,7 +218,6 @@ func CreateSIPCluster(name string, namespace string, controlPlanes int, workers
Namespace: namespace,
},
Spec: airshipv1.SIPClusterSpec{
ClusterName: name,
Nodes: map[airshipv1.VMRole]airshipv1.NodeSet{
airshipv1.VMControlPlane: {
VMFlavor: "vino.airshipit.org/flavor=" + vinoFlavorMap[airshipv1.VMControlPlane],