Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion internal/controller/controllers/bmh_agent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ func (r *BMACReconciler) findInstallationDiskID(devices []aiv1beta1.HostDisk, hi

acceptable := hostutil.GetAcceptableDisksWithHints(disks, hints)
if len(acceptable) > 0 {
return acceptable[0].ID
return getDiskID(acceptable)
}

// If hints are provided but we did not find an eligible disk, we need to raise an error.
Expand All @@ -1130,6 +1130,18 @@ func (r *BMACReconciler) findInstallationDiskID(devices []aiv1beta1.HostDisk, hi
return "/dev/not-found-by-hints"
}

// Given a list of acceptable disks,
// find the multipath disk ID, if it exists,
// otherwise return the ID of the first disk in the list.
func getDiskID(disks []*models.Disk) string {
for _, disk := range disks {
if strings.EqualFold(string(disk.DriveType), string(models.DriveTypeMultipath)) {
return disk.ID
}
}
return disks[0].ID
}

// Finds the agents related to this ClusterDeployment
//
// The ClusterDeployment <-> agent relation is one-to-many.
Expand Down
61 changes: 61 additions & 0 deletions internal/controller/controllers/bmh_agent_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,67 @@ var _ = Describe("bmac reconcile", func() {
Expect(err).To(BeNil())
Expect(updatedAgent.Spec.InstallationDiskID).To(Equal("1"))
})

It("should set the InstallationDiskID to multipath if the wwn RootDeviceHints were provided and match", func() {
priorAgent := &v1beta1.Agent{}
Expect(c.Get(ctx, types.NamespacedName{Name: agent.Name, Namespace: agent.Namespace}, priorAgent)).To(BeNil())
priorAgent.Status.Inventory.Disks = append(priorAgent.Status.Inventory.Disks, v1beta1.HostDisk{
ID: "3",
InstallationEligibility: v1beta1.HostInstallationEligibility{Eligible: true},
ByID: "/dev/disk/by-id/wwn-0x1111111111111111111111",
DriveType: string(models.DriveTypeMultipath),
Name: "sda",
SizeBytes: int64(120) * (int64(1) << 30),
Bootable: true,
})

for i := range priorAgent.Status.Inventory.Disks {
priorAgent.Status.Inventory.Disks[i].Wwn = "0x1111111111111111111111"
}
Expect(c.Update(ctx, priorAgent)).To(BeNil())

updatedHost := &bmh_v1alpha1.BareMetalHost{}
Expect(c.Get(ctx, types.NamespacedName{Name: host.Name, Namespace: testNamespace}, updatedHost)).To(BeNil())

updatedHost.Spec.RootDeviceHints = &bmh_v1alpha1.RootDeviceHints{
WWN: "0x1111111111111111111111",
}
Expect(c.Update(ctx, updatedHost)).To(BeNil())

result, err := bmhr.Reconcile(ctx, newBMHRequest(host))
Expect(err).To(BeNil())
Expect(result).To(Equal(ctrl.Result{}))

updatedAgent := &v1beta1.Agent{}
Expect(c.Get(ctx, types.NamespacedName{Name: agent.Name, Namespace: agent.Namespace}, updatedAgent)).To(BeNil())
Expect(updatedAgent.Spec.InstallationDiskID).To(Equal("3"))
})

It("should set the InstallationDiskID to the first disk if the wwn RootDeviceHints were provided and match and there's no multipath disks", func() {
priorAgent := &v1beta1.Agent{}
Expect(c.Get(ctx, types.NamespacedName{Name: agent.Name, Namespace: agent.Namespace}, priorAgent)).To(BeNil())
for i := range priorAgent.Status.Inventory.Disks {
priorAgent.Status.Inventory.Disks[i].Wwn = "0x1111111111111111111111"
}
Expect(c.Update(ctx, priorAgent)).To(BeNil())

updatedHost := &bmh_v1alpha1.BareMetalHost{}
Expect(c.Get(ctx, types.NamespacedName{Name: host.Name, Namespace: testNamespace}, updatedHost)).To(BeNil())

updatedHost.Spec.RootDeviceHints = &bmh_v1alpha1.RootDeviceHints{
WWN: "0x1111111111111111111111",
}
Expect(c.Update(ctx, updatedHost)).To(BeNil())

result, err := bmhr.Reconcile(ctx, newBMHRequest(host))
Expect(err).To(BeNil())
Expect(result).To(Equal(ctrl.Result{}))

updatedAgent := &v1beta1.Agent{}
Expect(c.Get(ctx, types.NamespacedName{Name: agent.Name, Namespace: agent.Namespace}, updatedAgent)).To(BeNil())
Expect(updatedAgent.Spec.InstallationDiskID).To(Equal("1"))
})

It("should not touch InstallationDiskID if the RootDeviceHints were not provided", func() {
updatedHost := &bmh_v1alpha1.BareMetalHost{}
err := c.Get(ctx, types.NamespacedName{Name: host.Name, Namespace: testNamespace}, updatedHost)
Expand Down