Skip to content

Commit

Permalink
register: don't send new Disks and Controllers data (#741)
Browse files Browse the repository at this point in the history
The newer versions of jaypipes/ghw include a new type of Disk and
Controller in the Blocks section.

We use the library json serialization functionality: the deserialization
function of the older version of the library (0.9.0) would error out
when trying to decode serialized data of newer versions if they include
the new "virtual" drive or the new "loop" controller.
For now, just remove those devices.
Proper fix will be to better deal with this kind of errors avoiding
tearing down the registration process.

Signed-off-by: Francesco Giudici <[email protected]>
(cherry picked from commit 3379c85)
  • Loading branch information
fgiudici authored and davidcassany committed May 29, 2024
1 parent 2d4160f commit 32f3585
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,19 @@ func FillData(data []byte) (map[string]interface{}, error) {

return labels, nil
}

// Prune() filters out new Disks and Controllers introduced in ghw/pkg/block > 0.9.0
// see: https://github.com/rancher/elemental-operator/issues/733
func Prune(data *HostInfo) {
prunedDisks := []*block.Disk{}
for i := 0; i < len(data.Block.Disks); i++ {
if data.Block.Disks[i].DriveType > block.DRIVE_TYPE_SSD {
continue
}
if data.Block.Disks[i].StorageController > block.STORAGE_CONTROLLER_MMC {
continue
}
prunedDisks = append(prunedDisks, data.Block.Disks[i])
}
data.Block.Disks = prunedDisks
}
3 changes: 3 additions & 0 deletions pkg/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ func sendSystemData(conn *websocket.Conn) error {
if err != nil {
return fmt.Errorf("reading system data: %w", err)
}
// preserve compatibility with older Elemental Operators
hostinfo.Prune(data)

err = SendJSONData(conn, MsgSystemData, data)
if err != nil {
log.Debugf("system data:\n%s", litter.Sdump(data))
Expand Down

0 comments on commit 32f3585

Please sign in to comment.