From 98c52868701bb5b77f24e3bf666acf1364c97719 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Wed, 3 Mar 2021 15:15:18 -0600 Subject: [PATCH] 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 --- .../airship.airshipit.org_sipclusters.yaml | 4 -- .../samples/airship_v1beta1_sipcluster.yaml | 2 - docs/api/sipcluster.md | 22 ---------- pkg/api/v1/sipcluster_types.go | 3 -- pkg/controllers/sipcluster_controller.go | 2 +- pkg/controllers/sipcluster_controller_test.go | 42 +++++++++---------- pkg/services/set.go | 6 +-- pkg/vbmh/machines.go | 14 +++---- testutil/testutil.go | 1 - 9 files changed, 32 insertions(+), 64 deletions(-) diff --git a/config/crd/bases/airship.airshipit.org_sipclusters.yaml b/config/crd/bases/airship.airshipit.org_sipclusters.yaml index 90d9eb0..ca0e19a 100644 --- a/config/crd/bases/airship.airshipit.org_sipclusters.yaml +++ b/config/crd/bases/airship.airshipit.org_sipclusters.yaml @@ -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 diff --git a/config/samples/airship_v1beta1_sipcluster.yaml b/config/samples/airship_v1beta1_sipcluster.yaml index 11c4a99..db6653e 100644 --- a/config/samples/airship_v1beta1_sipcluster.yaml +++ b/config/samples/airship_v1beta1_sipcluster.yaml @@ -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 diff --git a/docs/api/sipcluster.md b/docs/api/sipcluster.md index 03bdc79..495c034 100644 --- a/docs/api/sipcluster.md +++ b/docs/api/sipcluster.md @@ -210,17 +210,6 @@ SIPClusterSpec - - - - - - - -
-clusterName
- -string - -
-

ClusterName is the name of the cluster to associate machines with

-
nodes
@@ -414,17 +403,6 @@ string
-clusterName
- -string - -
-

ClusterName is the name of the cluster to associate machines with

-
nodes
diff --git a/pkg/api/v1/sipcluster_types.go b/pkg/api/v1/sipcluster_types.go index 0be4eba..3778a85 100644 --- a/pkg/api/v1/sipcluster_types.go +++ b/pkg/api/v1/sipcluster_types.go @@ -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"` diff --git a/pkg/controllers/sipcluster_controller.go b/pkg/controllers/sipcluster_controller.go index b5b5667..3af7080 100644 --- a/pkg/controllers/sipcluster_controller.go +++ b/pkg/controllers/sipcluster_controller.go @@ -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) diff --git a/pkg/controllers/sipcluster_controller_test.go b/pkg/controllers/sipcluster_controller_test.go index 6352aa1..1615d36 100644 --- a/pkg/controllers/sipcluster_controller_test.go +++ b/pkg/controllers/sipcluster_controller_test.go @@ -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()) diff --git a/pkg/services/set.go b/pkg/services/set.go index c2ee7ca..a9d2c22 100644 --- a/pkg/services/set.go +++ b/pkg/services/set.go @@ -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, diff --git a/pkg/vbmh/machines.go b/pkg/vbmh/machines.go index 51b56f4..0d2790a 100644 --- a/pkg/vbmh/machines.go +++ b/pkg/vbmh/machines.go @@ -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)) diff --git a/testutil/testutil.go b/testutil/testutil.go index 851b861..3e69428 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -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],