Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Drop lsblk in favour of ghw library #155

Merged
merged 4 commits into from
Apr 5, 2022
Merged

Drop lsblk in favour of ghw library #155

merged 4 commits into from
Apr 5, 2022

Conversation

Itxaka
Copy link
Contributor

@Itxaka Itxaka commented Mar 20, 2022

  • ghw uses udev database and files under /sys and /proc to gather all
    info
  • This uses that exclusively so no more lsblk
  • Probably means that the partition/disk identification utils can now
    without root privs
  • Adds a new mock to mock a full disk(s) with partition(s) for tests
    only
  • Makes tests use the new mock to mock the lsblk calls
  • Fixes a couple of leftovers on dir permissions

Unofrtunately this needs my own fork of ghw as upstream is missing a
patch to get the labels from the udev database, but it should be merged
upstream soon.

It also means that when running elemental from docker we need to link
the /run/udev/data volume, but this can be done on RO as we only read,
which would be a bit nicer. Commadn will look uglier thougth, but as
long as we explain why it needs that volume, it should all be good.

Signed-off-by: Itxaka [email protected]

@codecov
Copy link

codecov bot commented Mar 21, 2022

Codecov Report

Merging #155 (70bbf9e) into main (1b81b18) will decrease coverage by 0.88%.
The diff coverage is 78.26%.

@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   75.66%   74.77%   -0.89%     
==========================================
  Files          40       40              
  Lines        3291     3271      -20     
==========================================
- Hits         2490     2446      -44     
- Misses        649      667      +18     
- Partials      152      158       +6     
Impacted Files Coverage Δ
pkg/partitioner/disk.go 56.80% <40.00%> (-0.74%) ⬇️
pkg/utils/getpartitions.go 82.05% <82.05%> (ø)
pkg/utils/common.go 88.82% <100.00%> (-2.04%) ⬇️
pkg/utils/runstage.go 83.52% <100.00%> (ø)
pkg/action/reset.go 72.13% <0.00%> (-3.28%) ⬇️
pkg/elemental/elemental.go 80.09% <0.00%> (-1.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b81b18...70bbf9e. Read the comment docs.

@Itxaka Itxaka requested review from davidcassany and mudler March 21, 2022 09:02
Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just a couple of nits

If we are changing from GetAllPartitions(runner v1.Runner) to GetAllPartitionsV2(), probably without keeping the former method, probably we can simply avoid the V2 into the method name. Looks like there could be an alternate version of the method. Also, the pkg/utils/lsbk.go file I think it should be renamed to something else if it is not wrapping lsblk.

Beyond this two naming details it all looks good to me. 👍 I think this is a good move. And as discussed already, using the installer within a container will always be tricky or require specific uncommon volumes and privilages, it should not be the preferred way to use elemental.

@Itxaka
Copy link
Contributor Author

Itxaka commented Mar 21, 2022

yup, the naming and old functions are there 'cause...I was testing them side by side :D

In practice this was gonna be a work on top of the existing stuff to be substituted, but I saw it was only called in a few places, tried changing those and fixing the tests and suddenly those functions are not called anymore :o did not expect it to be this straightforward.

@Itxaka
Copy link
Contributor Author

Itxaka commented Mar 21, 2022

oh yeah what about the ghw Partition type VS our Partition type? We could drop our partition as they are identical but relaying on a external type....not good if they change it, but I would like to avoid doing the absurd transformation from one struct to the other which IMHO is wasted cycles.

@Itxaka
Copy link
Contributor Author

Itxaka commented Mar 21, 2022

I changed it to return our type, we can work out if we want to drop the transformation afterwards

@davidcassany
Copy link
Contributor

oh yeah what about the ghw Partition type VS our Partition type? We could drop our partition as they are identical but relaying on a external type....not good if they change it, but I would like to avoid doing the absurd transformation from one struct to the other which IMHO is wasted cycles.

I'd leave it for another PR and probably after a while. The good thing of this the current approach is that ghw is only imported within the utils wrapper and in tests. v1.Partitions is used in several places, so if we encounter some issue with ghw and consider going back to something else the changes are mostly affecting tests, the elemental logic is pretty isolated from it.

@kkaempf
Copy link
Contributor

kkaempf commented Mar 23, 2022

Not sure about the long-term implications of this:

  • lsblk is part of the core operating system
  • there's someone to blame if lsblk has problems 😉
  • ghw increases our external dependencies
  • problems in ghw are on us to fix

@mudler
Copy link
Contributor

mudler commented Mar 23, 2022

Not sure about the long-term implications of this:

* `lsblk` is part of the core operating system

* there's someone to blame if lsblk has problems wink

* `ghw` increases our external dependencies

* problems in `ghw` are _on us_ to fix

Let's not confuse blkid lsblk and ghw. ghw is a library for hardware detection, and for partitions and such it uses also blkid behind the scene, among other tools (@Itxaka also improved it to use udev!).

This is about avoiding us to re-invent the wheel and write from scratch a detecting library, with all the issues that it might bring.. it makes sense instead to contribute to an open source one that we just adopt.

@Itxaka
Copy link
Contributor Author

Itxaka commented Mar 23, 2022

lsblk is part of the core operating system

Not on cos, only 'cause we need it for elemental :P

there's someone to blame if lsblk has problems wink

well...same? we blame ghw :P

ghw increases our external dependencies

Not really, its compiled into a final binary babyyyyy. ghw is really ligth and we only use a small part of it, not sure why the problem with this and not the other 300 dep that we have 🤣

problems in ghw are on us to fix

Good. I like that, cause I already fixed issues on it and expanded. Good luck getting me to fix something on lsblk 🤣

@Itxaka
Copy link
Contributor Author

Itxaka commented Mar 30, 2022

upstream PR missing jaypipes/ghw#310

Itxaka added 3 commits March 30, 2022 10:31
 - ghw uses udev database and files under /sys and /proc to gather all
info
 - This uses that exclusively so no more lsblk
 - Probably means that the partition/disk identification utils can now
without root privs
 - Adds a new mock to mock a full disk(s) with partition(s) for tests
only
 - Makes tests use the new mock to mock the lsblk calls
 - Fixes a couple of leftovers on dir permissions

Unofrtunately this needs my own fork of ghw as upstream is missing a
patch to get the labels from the udev database, but it should be merged
upstream soon.

It also means that when running elemental from docker we need to link
the /run/udev/data volume, but this can be done on RO as we only read,
which would be a bit nicer. Commadn will look uglier thougth, but as
long as we explain why it needs that volume, it should all be good.

Signed-off-by: Itxaka <[email protected]>
Also drop a method not used anywhere, return a v1.Partition by default

Signed-off-by: Itxaka <[email protected]>
Signed-off-by: Itxaka <[email protected]>
@Itxaka Itxaka self-assigned this Mar 30, 2022
@Itxaka
Copy link
Contributor Author

Itxaka commented Apr 4, 2022

upstream patch merged, this should be ready tomorrow!

@Itxaka Itxaka marked this pull request as ready for review April 4, 2022 19:16
Copy link
Contributor

@davidcassany davidcassany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

},
},
}
ghwTest = v1mock.GhwMock{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Contributor

@mudler mudler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Itxaka Itxaka merged commit 89d323a into rancher:main Apr 5, 2022
@Itxaka Itxaka deleted the use_ghw branch April 5, 2022 10:13
mjura pushed a commit to mjura/elemental-cli that referenced this pull request Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants