moby / moby/swarmkit

Treat constraint expressions as an AST

Open
#1,151 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/orchestration status/0-triage
Dominant language
Go
Stars
3.7k
Forks
676
Avg merge
4d 9h
Merged PRs (30d)
6

Description

First of all, this is mostly meant as a topic for discussion, rather than a concrete proposal.

As of now, constraints are a set of key-value expressions using == or != operators that are chained together with implicit logical AND (&&) operators.

In BNF, this can be expressed as follows, even though there is currently no actual && operator:

<expr> ::=  <key> <op> <value> 
                | <expr> `&&` <expr>
<op> ::=  `==`  |  `!=`

I would argue that there are use cases where the model is overly restrictive or it requires excessive node labelling.

Without going into details about variations of <op> or adding different keys, I believe that this model could benefit from an explicit OR (||) operator and by setting the AND operator to be explicit.

This would be reflected in the following grammar:

<expr> ::=  <key> <op> <value>  
               | <expr> `&&` <expr> 
               | <expr> `||` <expr>  
               | `(` expr `)`
<op> ::=  `==` | `!=`

One example expression would be:

(node.role == manager && node.labels.disk == ssd) || (node.role != manager && node.labels.disk != ssd) meaning "schedule on a manager node only if its storage drive is an ssd`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named. Start by locating the existing constraint representation and parser, then compare them with the proposed BNF for explicit &&, ||, and parentheses. Done would require an agreed design and corresponding parsing and scheduling behavior, but this issue is presented as discussion rather than a concrete proposal.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers, distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.