diff --git a/pkg/vbmh/vbmh_test.go b/pkg/vbmh/vbmh_test.go index b69a540..9f0c4ec 100644 --- a/pkg/vbmh/vbmh_test.go +++ b/pkg/vbmh/vbmh_test.go @@ -76,7 +76,96 @@ var _ = Describe("MachineList", func() { Expect(bmh.Labels[SipScheduleLabel]).To(Equal("false")) } } - }) + It("Should not produce a list of BMH objects when there are none available for scheduling", func() { + // "Schedule" all nodes + var objs []runtime.Object + for _, machine := range machineList.Machines { + machine.BMH.Labels[SipScheduleLabel] = "true" + objs = append(objs, &machine.BMH) + } + + k8sClient := mockClient.NewFakeClient(objs...) + _, err := machineList.getBMHs(k8sClient) + Expect(err).ToNot(BeNil()) + }) + + It("Should retrieve the BMH IP from the BMH's NetworkData secret when infra services are defined", func() { + // Create a BMH with a NetworkData secret + bmh, secret := testutil.CreateBMH(1, "default", "master", 6) + + var objs []runtime.Object + objs = append(objs, bmh) + objs = append(objs, secret) + + ml := &MachineList{ + NamespacedName: types.NamespacedName{ + Name: "vbmh", + Namespace: "default", + }, + Machines: map[string]*Machine{ + bmh.Name: NewMachine(*bmh, airshipv1.VmMaster, NotScheduled), + }, + Log: ctrl.Log.WithName("controllers").WithName("SIPCluster"), + } + + sipCluster := testutil.CreateSIPCluster("subcluster-1", "default", 1, 3) + sipCluster.Spec.InfraServices = map[airshipv1.InfraService]airshipv1.InfraConfig{ + airshipv1.LoadBalancerService: airshipv1.InfraConfig{ + Image: "haproxy:latest", + NodeLabels: map[string]string{ + "test": "true", + }, + NodePorts: []int{7000, 7001, 7002}, + NodeInterface: "oam-ipv4", + }, + } + k8sClient := mockClient.NewFakeClient(objs...) + Expect(ml.Extrapolate(*sipCluster, k8sClient)).To(BeTrue()) + + // NOTE(drewwalters96): Interface data is b64 encoded in the testutil convenience function. + Expect(ml.Machines[bmh.Name].Data.IpOnInterface).To(Equal(map[string]string{"oam-ipv4": "32.68.51.139"})) + }) + + It("Should not retrieve the BMH IP from the BMH's NetworkData secret if no infraServices are defined", func() { + // Create a BMH with a NetworkData secret + bmh, secret := testutil.CreateBMH(1, "default", "master", 6) + + var objs []runtime.Object + objs = append(objs, bmh) + objs = append(objs, secret) + + ml := &MachineList{ + NamespacedName: types.NamespacedName{ + Name: "vbmh", + Namespace: "default", + }, + Machines: map[string]*Machine{ + bmh.Name: NewMachine(*bmh, airshipv1.VmMaster, NotScheduled), + }, + Log: ctrl.Log.WithName("controllers").WithName("SIPCluster"), + } + + k8sClient := mockClient.NewFakeClient(objs...) + sipCluster := testutil.CreateSIPCluster("subcluster-1", "default", 1, 3) + Expect(ml.Extrapolate(*sipCluster, k8sClient)).To(BeTrue()) + Expect(len(ml.Machines[bmh.Name].Data.IpOnInterface)).To(Equal(0)) + }) + + + It("Should not retrieve the BMH IP if it has been previously extrapolated", func() { + // Store an IP address for each machine + var objs []runtime.Object + for _, machine := range machineList.Machines { + machine.Data.IpOnInterface = map[string]string{ + "oam-ipv4": "32.68.51.139", + } + objs = append(objs, &machine.BMH) + } + + k8sClient := mockClient.NewFakeClient(objs...) + sipCluster := testutil.CreateSIPCluster("subcluster-1", "default", 1, 3) + Expect(machineList.Extrapolate(*sipCluster, k8sClient)).To(BeTrue()) + }) })