Skip to content

Commit 32f3585

Browse files
fgiudicidavidcassany
authored andcommitted
register: don't send new Disks and Controllers data (#741)
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)
1 parent 2d4160f commit 32f3585

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/hostinfo/hostinfo.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,19 @@ func FillData(data []byte) (map[string]interface{}, error) {
220220

221221
return labels, nil
222222
}
223+
224+
// Prune() filters out new Disks and Controllers introduced in ghw/pkg/block > 0.9.0
225+
// see: https://github.com/rancher/elemental-operator/issues/733
226+
func Prune(data *HostInfo) {
227+
prunedDisks := []*block.Disk{}
228+
for i := 0; i < len(data.Block.Disks); i++ {
229+
if data.Block.Disks[i].DriveType > block.DRIVE_TYPE_SSD {
230+
continue
231+
}
232+
if data.Block.Disks[i].StorageController > block.STORAGE_CONTROLLER_MMC {
233+
continue
234+
}
235+
prunedDisks = append(prunedDisks, data.Block.Disks[i])
236+
}
237+
data.Block.Disks = prunedDisks
238+
}

pkg/register/register.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ func sendSystemData(conn *websocket.Conn) error {
267267
if err != nil {
268268
return fmt.Errorf("reading system data: %w", err)
269269
}
270+
// preserve compatibility with older Elemental Operators
271+
hostinfo.Prune(data)
272+
270273
err = SendJSONData(conn, MsgSystemData, data)
271274
if err != nil {
272275
log.Debugf("system data:\n%s", litter.Sdump(data))

0 commit comments

Comments
 (0)