Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding host_compat setting to package BuildSpec #922

Merged
merged 18 commits into from
Dec 12, 2023

Conversation

dcookspi
Copy link
Collaborator

@dcookspi dcookspi commented Nov 25, 2023

This add the host_compat field a package's BuildSpec, based on the discussion in the related ticket, e.g.

package: my-pkg/1.0
build:
    host_compat: distro
    options:
     -  pkg: some-pkg/2.3.4
....

The value of host_compat the determines which host os related options are automatically added to the package build's options. It also describes the kind of host os compatibility required for builds of this package. The supported values are: distro (default), arch, os, and any.

This also adds a host_compat section with validate field to spk's config file. This contols whether checks are run on a build's option to ensure no incompatible host os related options are also being by a package variant. The default is for these checks to be disabled (should it be that?).

This does not include:

Todo:

  • Decide how to resolve the <distroname> vars comparison issue, e.g. 9.2 vs 9.3 for rocky 9's being treated as equal (in the solver and builds, so any comparisons) if those versions of the distro are application compatible.
    • I'm going to leave this as it is right now: capture 9.2 or 9.3, the full number, and leave possible comparison rules/changes for the future.

@dcookspi dcookspi requested review from jrray and rydrman November 25, 2023 00:11
@dcookspi dcookspi self-assigned this Nov 25, 2023
@dcookspi dcookspi linked an issue Nov 25, 2023 that may be closed by this pull request
@dcookspi dcookspi added SPI AOI Area of interest for SPI SPI-0.39 enhancement New feature or request labels Nov 27, 2023
@dcookspi dcookspi force-pushed the 917-host-options-should-be-automatic-and-opt-out branch from efb0cee to 2087873 Compare November 30, 2023 01:43
@dcookspi
Copy link
Collaborator Author

Added a todo for what to do about the os version comparison discussison we had today.

@dcookspi dcookspi requested a review from rydrman November 30, 2023 01:55
@dcookspi
Copy link
Collaborator Author

Added codes to the new errors.

@dcookspi
Copy link
Collaborator Author

dcookspi commented Dec 6, 2023

I've removed the validation check and error, and the config option to enable/disable it. I've commented out but left in the disallowed fields constants and method because they'll get used in the planned host_compat lint warning (in a later PR).

Supports these values: distro, arch, os, and any. The value determines
which host os related options are automatically added to the package
build's options.

Adds 'host_compat' section with 'validate' setting to spk's config
file to control whether checks are run on a build's option to ensure
there no host os related options set that are incopmatible with the
package's host_compat value.

Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
@dcookspi dcookspi force-pushed the 917-host-options-should-be-automatic-and-opt-out branch from 92d2ec4 to 4287114 Compare December 6, 2023 21:10
Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
@dcookspi
Copy link
Collaborator Author

dcookspi commented Dec 7, 2023

I've fixed an issue with the --no-host option so host_compat works as expected with it. This should be ready for another review now, @rydrman.

Comment on lines 36 to 46
pub enum HostCompat {
/// Package can only be used on the same OS distribution
#[default]
Distro,
/// Package can be used anywhere that has the same OS and cpu type
Arch,
/// Package can be used on the same OS with any cpu or distro
Os,
/// Package can be used on any Os
Any,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has @lgritz been able to put eyes on this addition? I am having memories of talking about being able to handle CPU capabilities, etc, and wondering if we should consider making host_compat a list - or at least not lock ourselves into a state where cpu architecture is tied to os/distro. Eg you can't say "any arch but must be the same distro"...

sorry to throw another question into the mix here...

Copy link
Collaborator Author

@dcookspi dcookspi Dec 8, 2023

Choose a reason for hiding this comment

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

I'm not sure. I think @lgritz might been some of the internal meetings where it was mentioned, @jrray may know more. But I don't think we got into details.

The host_compat: enum values in this change are an initial set of possibilities. They expand into lists of vars, most with known names, one with a dynamic name (the value of the distro host option). We could add other host_compat values in future if we need to, e.g. a 'DistroOnly' value could expand into just the <distroname>=<version> var option (if I understand what you mean by "any arch but the same distro" correctly). We could add other enum values that turn into other, stranger sets of vars, later, as needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Eg you can't say "any arch but must be the same distro"...

David already answered this but to put it another way, individual specs can set host_compat: Any and be back to the original behavior, and then add back in whatever combination of host vars they want.

I really hope this PR doesn't get bogged down over perceived limitations of what this is doing, in my mind we're not introducing any new concepts here but just putting some more formal structure around what the existing behavior has been. It's important for us to get these vars added by default ASAP so we can make progress on our new OS testing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does seem a little counter-intuitive to read a spec with host_compat: Any that, in fact, has a very specific host compat defined elsewhere.

My goal is never to "bog down" a PR, and I hope you don't see these discussions as purely bureaucratic. My goal is to make sure we are thinking about these things from all angles. It's very hard to go backwards in spk and with every feature we add to fix a specific need we add complexity for new folks to learn and understand. I just want to make sure that the design feels intuitive for newcomers and doesn't shoehorn us into any undesirable futures...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just trying to reconcile the above in my brain - maybe we are complicating things by abstracting what's going on here? Aka Any actually means inject no vars, but doesn't preclude them existing elsewhere....

As one idea, we could instead be explicit and call the field something like auto_host_vars, changing Any to None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can rename the field and value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've changed this over to use auto_host_vars and None. The internals haven't changed.

Comment on lines 78 to 81
return Err(Error::HostOptionNotValidDistroNameError(
distro_name.to_string(),
err,
))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still have concerns with this being an error case, but curious about your thoughts...

The value that's incorrect is loaded from the host machine for an option that's injected - I think there's a potential for users to have no idea what went wrong or how to fix this and we should at least have a good explanation and possible work-around --- or maybe we need some kind of reliable conversion+fallback for distro names so that it never fails in this way?

The main question is - how do you recover if you run spk on a machine where the distro name is seen as invalid? I know you have "contact admin" now but what would the admin even do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's worth erroring. But I can see that stopping spk dead isn't good either. I'm not sure there's a good easy solution.

I looked again at what the existing host_options() function does, and updated this code to do the same. The host_options() displays a warning and skips over making the <distroname> var, which is slightly concerning, but its consistent for now. It's something we can also ticket up to look at in-depth in future, if necessary.

Here are some options:

  • Error and Stop spk, until there's a valid distroname - if that's even posssible for some sysadmin to do sensibly (the original code did this)
  • Warn and Skip making the <distroname>=<version_id> var opt at all (the current code does this)
  • Warn and Fallback, use either:
    • some predefined value (unknown_distro=<version_id>?), or
    • convert the distroname into a valid opt name, which I think at the moment involves:
      1. lowercasing it,
      2. filtering out all character that aren't letters, numbers, _'s and -'s,
      3. then making sure the leftover string is > 2 and < 64 chars, by either padding or truncating it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Internally, for name-like types we often add a new_lossy constructor that does the kind of translation that you mention in a predictable and infallible way. That seems ideal to me in this case because it would still give a consistent value on which to check compatibility, but not fail as we're discussing.

In the future, once we allow a custom host options command then we could allow it to yield an alternative name, but the above feels like the best default behavior to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can add a constructor that converts the name to a valid one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a new_lossy() and unknown_distro() methods.

dcookspi and others added 2 commits December 8, 2023 14:24
Co-authored-by: Ryan Bottriell <[email protected]>

Signed-off-by: David Gilligan-Cook <[email protected]>
Signed-off-by: David Gilligan-Cook <[email protected]>
@dcookspi dcookspi force-pushed the 917-host-options-should-be-automatic-and-opt-out branch from ec9f385 to f5541aa Compare December 8, 2023 22:58
@dcookspi dcookspi requested a review from rydrman December 9, 2023 02:08
}

impl HostCompat {
pub fn is_default(&self) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recently learned about the variantly crate which unfortunately doesn't generate an is_default method but does generate other useful methods for enums.

Comment on lines 36 to 46
pub enum HostCompat {
/// Package can only be used on the same OS distribution
#[default]
Distro,
/// Package can be used anywhere that has the same OS and cpu type
Arch,
/// Package can be used on the same OS with any cpu or distro
Os,
/// Package can be used on any Os
Any,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Eg you can't say "any arch but must be the same distro"...

David already answered this but to put it another way, individual specs can set host_compat: Any and be back to the original behavior, and then add back in whatever combination of host vars they want.

I really hope this PR doesn't get bogged down over perceived limitations of what this is doing, in my mind we're not introducing any new concepts here but just putting some more formal structure around what the existing behavior has been. It's important for us to get these vars added by default ASAP so we can make progress on our new OS testing.

@dcookspi dcookspi requested a review from jrray December 12, 2023 01:06
Co-authored-by: Ryan Bottriell <[email protected]>

Signed-off-by: David Gilligan-Cook <[email protected]>
@dcookspi dcookspi force-pushed the 917-host-options-should-be-automatic-and-opt-out branch from 8417691 to d5df810 Compare December 12, 2023 18:01
Signed-off-by: David Gilligan-Cook <[email protected]>
@dcookspi dcookspi requested a review from rydrman December 12, 2023 18:32
@dcookspi dcookspi merged commit 79ad8fe into main Dec 12, 2023
@dcookspi dcookspi deleted the 917-host-options-should-be-automatic-and-opt-out branch December 12, 2023 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SPI AOI Area of interest for SPI SPI-0.39
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Host options should be automatic and opt-out
3 participants