-
Notifications
You must be signed in to change notification settings - Fork 556
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
match.Platform but ignore variant #892
Comments
So this is where things get a little fuzzy. The spec also says:
Simiarly, for
So you want to ignore this stuff, but these are part of the minimum runtime requirements or mandatory OS features. Depending on what you're asking, you absolutely should or should not ignore this field... When a runtime encounters a set of platform-specific images, it needs to ensure that it can actually run that thing, so it definitely shouldn't ignore the variant or os.features. When a generic tool encounters a set of platform-specific images, perhaps it doesn't actually care about the variant? What are you trying to do? It might be easier to support your specific goal than to design a generic solution.
Yeah this will be fun. We're going from equality, which is symmetric, to $NEW_TERM, which is asymmetric. Conveying that via names is really important. In the past, I've implemented this two ways:
It's obvious how to apply the symmetric thing, but I don't think a single option will actually work here because we could match two ways: matches = [desc.platform.can_run(p) for desc in descriptors]
matches = [p.can_run(desc.platform) for desc in descriptors] Your If we start going in that direction, you'd probably want something similar for Re: your suggestions, I think this one is the most interesting: match.IgnoreBlank(match.Platforms(platforms ...v1.Platform)) Because func IgnoreBlank(Matcher) Matcher So we could hide a lot of super complex logic in there and apply it to any matcher... but maybe // Superset modifies the matching behavior of a given Matcher:
// For structs, a descriptor will match if the given struct has at least all the set fields.
// For arrays, a descriptor will match if the given array has at least all the entries.
// For maps, a descriptor will match if the given map has at least all the k/v entries.
func Superset(Matcher) Matcher
// Subset behaves the same way as Superset, but s/at least/at most/g
func Subset(Matcher) Matcher So we'd need to somehow pass these down through to the leaf matchers (if we end up with composition via Also I think Anyway, lots of food for thought. Not sure what we actually want to do here, but let me know what you think. |
Definitely agree. Which is why I suggest that this should be left up to the user. By default,
Pretty much that. Stumbled across this when looking at images of type Either way, it is perfectly valid for a consumer to say, "I want the image for linux/arm64, and I have no clue about variants. Once it matches linux/arm64 (or darwin/arm64, now that it exists), it is good enough for me." FWIW, for now, I just wrote a custom
Back in my days of browser stuff, there was a noticeable shift at some point from listing what browser versions one had and checking for it in a piece of JS compat list, to just seeing capabilities, "can this do X?" In theory, it is nice. In practice, I am hesitant to use that here, because I don't think we want to get into the business of deciding compatibility. Certain code might be ok on any variant of the same arch; others might be on some variants but not all. I would prefer to kick that up a level and let whoever is consuming the library decide.
Good point. Either way, the big appeal of We could extend it slightly with I do wish we could have The problem is that
Essentially we are composing our I am not sure I get your point about superset vs subset.
The other challenge is how to implement this? Taking a returned |
I somewhat recently learned about
Definitely. I like that
I get what you're saying, but I think we can rely on the spec here, usually... but that is only if someone is asking the question "can A run B?", which often isn't relevant, e.g. for your use case.
I'm not sure how to work around this :/
Equals is "all fields must match". Superset is "these values I care about here must match, anything else is gravy". Subset is "these values I care about here are the only things allowed, anything else is forbidden". Subset makes more sense thinking about a
Sometimes you know your requirements and want to match against a list of capabilities, in which case Superset makes more sense.
Agreed, maybe too messy. |
Yes. Looks like we did a good flexible job with
So
Still somewhat confusing, but ok. Either way, how do we implement that? |
It's basically just the complement of Superset so that you can flip the lhs and rhs. When thinking about platforms: func (runtime Platform) CanRun(requirement Platform) {
return runtime.Superset(requirement)
}
func (requirement Platform) CanBeRunBy(runtime Platform) {
return requirement.Subset(runtime)
}
Maybe we just don't? In #907 (comment) there's a need to expose the platform matching logic somewhere. That would make it slightly easier to write a custom matcher to do what you need. If we did expose those two methods on Platform (not in terms of {super,sub}set, just in terms of platform fields), your custom matcher could just look like: func matchPlatforms(platforms ...v1.Platform) match.Matcher {
return func(desc v1.Descriptor) bool {
for _, platform := range platforms {
if desc.Platform.CanRun(platform) {
return true
}
}
return false
}
} |
That pretty much is what I did, but instead of So will we do anything with this? |
This issue is stale because it has been open for 90 days with no |
In order to match on a platform, we have match.Platforms. Most of the time this works well.
However, the
variant
part of the platform, described in the spec is listed as "OPTIONAL".The current
match.Platforms
has no way of indicating, "match my OS/Architecture but ignore the variant". For that matter, I think it may be a broader question of a way to tell the platform-matcher to ignore some fields. E.g. I want all entries that have architecture=amd64, I don't care about the OS, etc.I am happy to open a PR on this, if we can agree on the right interface.
Options
Some options:
match.Any
Some form of
match.Any
option, such that you could provide it to any given field. So you would do:I am not sure how to make that work; some fields in
v1.Platform
arestring
, others are[]string
. Maybe it just works for thestring
fields?Wrapper
A different variant might be a wrapper, where we could do:
The above tells it to reject fields that do not match, but ignore blank. Again, not sure how to make this work. Don't we need to tell
match.Platforms
to ignore blanks?Alternate
Another option is to have an alternative matcher:
I don't like the nomenclature, but the idea isn't bad.
I looked at a parameter, but the platforms arg already is variadic.
Thoughts?
The text was updated successfully, but these errors were encountered: