Skip to content

fix(server): AND the GPU product pin into the form's node terms - #58

Open
aceforeverd wants to merge 1 commit into
masterfrom
fix-gpu-pin-and-terms
Open

aceforeverd wants to merge 1 commit into
masterfrom
fix-gpu-pin-and-terms

Conversation

@aceforeverd

Copy link
Copy Markdown
Contributor

In nodeSelectorTerms, the terms are ORed and a term's matchExpressions are ANDed. POST /api/plans pinned GPU products by writing over the form's required node terms, so any term the form set was lost:

Case Before Now
products picked (gpuProducts) the form's terms replaced by the product term the product expression added to each of the form's terms
no products picked, variant requires a GPU product the derived pin replaced by the form's terms (the form layer comes after the derived layer) the pin added to each of the form's terms, in the form layer
the form sets no required terms the product term alone unchanged

An In expression on the product label key is replaced rather than added. That keeps an upgrade from stacking the old products' expression beside the new one.

Example: a preset's term plus a picked product gives one term with both expressions, so the pod needs both:

nodeSelectorTerms:
  - matchExpressions:
      - {key: storage, operator: In, values: ["true"]}                 # the form's
      - {key: nvidia.com/gpu.product, operator: In, values: [NVIDIA-H800]}  # the picked product

Two separate terms would mean either one, and then the preset's rule would never constrain anything.

This is a fix to the current API only. The plan is for the web to build the whole form layer and for a /api/v2/compose to replace this, at which point swissd stops writing into the form layer (#56).

No API change. A console that sets no required terms gets the same plan as before.

Testing

  • TestAndTerms: each term gets the pin; an In on the same key is replaced and a NotIn kept; the input is not changed.
  • TestComposeGPUNodeSelectorTerms: the derived pin is added to the form's terms, and the catalog's own terms still stand.
  • TestGPUProductsAreANDedIntoTheFormsTerms: a POST /api/plans with a form term and a picked product gives one term with both expressions.
  • go test ./... and go vet ./... pass, and gofmt -l is empty.

Refs #56.

nodeSelectorTerms are ORed, and a term's matchExpressions ANDed. Picking GPU
products used to replace the form's required terms with the product term,
and a variant's derived pin was replaced by any terms the form set, so a
preset's or an edited term was lost either way.

Both now add the product expression to each of the form's terms, replacing
an In on the same key, and set the product term alone only when the form
has none.

@huskcass huskcass left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No blockers. Tests pass against the pinned catalog (go test ./...), and the go and gate checks are green; e2e and publish were still pending.

Medium

  • Silent dropped pins. In AndTerms, a pin entry that isn't a map is skipped and a form term that isn't a map is kept without the pin, so a malformed term yields an unpinned deploy with no error. Both inputs come from our own code and a decoded form, so these are unrealistic cases. Cut the ok branches and the map[string]any arm of asTree (keep one decoded type), or return an error instead of passing through.
  • Behavior change when no products are picked. If the form already has an In on the product label key, for example a different product than the variant requires, the derived pin now overwrites it through putExpr. Before, the form's terms won outright. Leave the form's own In for that key alone in this path, and replace only in the picked-products path where the replace is the intent.
  • The pin now lives in the form layer in the derived case, so LayerOf reports it as the user's and an upgrade carries it forward even if the variant stops requiring it. This is acceptable for a stopgap that #56 replaces; worth a note in the PR.

Low

  • compose.go writes into in.Overrides in place. Copy it, or note the mutation.
  • The server and compose paths each repeat the get-list-AndTerms-set sequence; one small helper would cover both.

Solid
Fixes the real OR/AND bug, AndTerms doesn't mutate its inputs, the tests cover each case, and there is no API change.

Verdict: OK to merge; the Medium items are simplifications and one behavior question.

— Review Golden

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants