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

Add basic logical operator support to MachineMetadata #1424

Open
alecmev opened this issue Feb 4, 2016 · 1 comment
Open

Add basic logical operator support to MachineMetadata #1424

alecmev opened this issue Feb 4, 2016 · 1 comment

Comments

@alecmev
Copy link

alecmev commented Feb 4, 2016

Right now MachineMetadata logic is quite counter-intuitive, at least to me. Here's an example:

[X-Fleet]
MachineMetadata="region=us-east-1" "diskType=SSD"
MachineMetadata=region=us-west-1

Since the docs define each MachineMetadata entry as an OR, I'd expect it to mean this:

(diskType=SSD AND region=us-east-1) OR region=us-west-1

While it's actually parsed as this:

diskType=SSD AND (region=us-east-1 OR region=us-west-1)

Something similar to this has caused me to post an issue a week earlier.

There's a pull request now, containing a few simple examples, including the one above, which is good. However, that doesn't fix the fact that some pretty trivial things, like an OR of two different meta keys (e.g. foo=bar OR abc=xyz), just can't be expressed using the current syntax.

I propose a simple backwards-compatible solution: SQL-like operators + brackets. To escape spaces / special words and stay consistent with the old syntax, each key=value is wrapped in double quotes. Then, key-values can be combined by either AND or OR (AND getting precedence over OR), and then grouped in brackets, if desired, just like in SQL. Additionally, for negation, use either NOT before a key-value or != / =! instead of = (the negation has been mentioned in this issue before). If the new syntax is used, then only one MachineMetadata per unit is allowed, as to avoid ambiguity.

So, the example above would look like this:

[X-Fleet]
MachineMetadata=("region=us-east-1" AND "diskType=SSD") OR "region=us-west-1"

Brackets being redundant. IMO, even those unfamiliar with X-Fleet will understand what's going on.

@Alino
Copy link

Alino commented Mar 10, 2016

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants