Skip to content

Conversation

@ricardomaraschini
Copy link
Contributor

@ricardomaraschini ricardomaraschini commented Nov 20, 2022

Description, Motivation and Context

In some cases, it is important to collect what packages are installed in the Operating System. This PR adds a collector and an analyzer for these cases. Here is an example of collecting and installing packages:

apiVersion: troubleshoot.sh/v1beta2
kind: HostPreflight
metadata:
  name: check-installed-packages
spec:
  collectors:
    - installedPackages:
        collectorName: "Installed packages"

For analyzing this PR also introduces the concept of a templated analyzer (an analyzer whose properties need to be templated out before running). Here is an analyzer to check whether a given package is present or not but only on an Ubuntu installation:

spec:
  analyzers:
    - installedPackage:
        collectorName: "Installed packages"
        packageName: "dbus-user-session"
        exclude: '{{ne .Platform "ubuntu"}}'
        outcomes:
        - pass:
            when: "> 1.12.0"
            message: "dbus-user-session version > 1.12.0 is installed"
        - fail:
            message: "dbus-user-session version > 1.12.0 is required"

As not all installed packages comply with semantic versioning the analyzer attempts to use the when clause as a regex if the package is installed but does not comply with semantic versioning.

As now this PR does not implement any test (hence the Draft), the goal is to spark some discussions about how useful this can be and, especially, about the new "templated" analyzer concept.

Extra

  • If no outcome has been specified the analyzer passes if the package is installed (regardless of the version) and fails if not installed.
  • This PR contains support for Debian and RedHat operating systems but it should be generic enough to support other flavours o the same family (tested in Ubuntu and Fedora).

Checklist

  • New and existing tests pass locally with the changes.
  • Tests for the changes have been added (for bug fixes / features)
  • The commit message(s) are informative and highlight any breaking changes

Does this PR introduce a breaking change?

  • Yes
  • No

@ricardomaraschini ricardomaraschini requested a review from a team as a code owner November 20, 2022 11:23
@CLAassistant
Copy link

CLAassistant commented Nov 20, 2022

CLA assistant check
All committers have signed the CLA.

@ricardomaraschini ricardomaraschini marked this pull request as draft November 20, 2022 11:24
@ricardomaraschini ricardomaraschini added the type::feature New feature or request label Nov 20, 2022
added a collector and an analyzer for packages installed in the
operating system.

here is an example of collecting installing packages:

```yaml
apiVersion: troubleshoot.sh/v1beta2
kind: HostPreflight
metadata:
  name: check-installed-packages
spec:
  collectors:
    - installedPackages:
        collectorName: "Installed packages"
```

for analyzing this pr also introduces the concept of a templated
analyzer. here is an analyzer to check a given package is present
but only on an ubuntu installation:

```yaml
spec:
  analyzers:
    - installedPackage:
        collectorName: "Installed packages"
        packageName: "dbus-user-session"
        exclude: '{{ne .Platform "ubuntu"}}'
        outcomes:
        - pass:
            when: "> 1.12.0"
            message: "dbus-user-session version > 1.12.0 is installed"
        - fail:
            message: "dbus-user-session version > 1.12.0 is required"
```

as not all installed packages comply with semantic version the analyzer
attempts to use the `when` clause as a regex if the package is installed
but does not comply with semantic versioning.
@diamonwiggins
Copy link
Member

diamonwiggins commented Nov 21, 2022

Curious to know if you've had a look at https://kurl.sh/docs/create-installer/host-preflights/system-packages?

https://github.com/replicatedhq/troubleshoot/blob/main/pkg/collect/host_system_package.go
https://github.com/replicatedhq/troubleshoot/blob/main/pkg/analyze/host_system_packages.go

I still haven't digged too deep into this PR yet, but at surface levels seems like there's some overlap here. If that's the case, should make a decision if we want to build on the existing collector or deprecate it with this addition.

@ricardomaraschini
Copy link
Contributor Author

Closing this. I was not aware this feature already existed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type::feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants