Skip to content

feat(aws): add --instance-families flag to filter instance selector output - #872

Open
amastbau wants to merge 7 commits into
redhat-developer:mainfrom
amastbau:feat/instance-families
Open

feat(aws): add --instance-families flag to filter instance selector output#872
amastbau wants to merge 7 commits into
redhat-developer:mainfrom
amastbau:feat/instance-families

Conversation

@amastbau

@amastbau amastbau commented Jul 29, 2026

Copy link
Copy Markdown

Summary

Adds --instance-families flag (comma-separated allowlist of AWS family prefixes, e.g. m5,m6i,m7i) that post-filters the EC2 instance selector output to only matching families.

Fixes #684

Problem

When using --cpus and --memory, the instance selector returns up to 20 types including expensive specialized families (d3en, p3, x1e — dense storage, GPU, high-memory) alongside cheap general-purpose ones. Spot picks the cheapest at that moment, which may be a temporarily cheap specialized instance. Example: d3en.12xlarge and m5a.12xlarge have identical vCPU/Memory but the former is ~3x more expensive.

Changes

  • pkg/provider/api/compute-request/compute-request.go — add InstanceFamilies []string field to ComputeRequestArgs
  • pkg/provider/aws/data/compute-request.go — extract filterByFamily() helper; skip MaxResults cap in selector when family filter active; apply cap manually after filtering
  • pkg/provider/aws/data/compute-request_test.go — 8 unit tests for filterByFamily() including cap-after-filter regression
  • cmd/mapt/cmd/params/params.go — add --instance-families flag, populate field
  • tkn/template/infra-aws-ocp-snc.yaml, tkn/template/infra-aws-rhel.yaml — add instance-families param; pass flag in else branch of compute-sizes conditional
  • Regenerated tkn/infra-aws-ocp-snc.yaml, tkn/infra-aws-rhel.yaml

Behavior

  • --instance-families m5,m6i,m7i → selector returns only m5.*, m6i.*, m7i.* types
  • --instance-families is a no-op when --compute-sizes is set (compute-sizes bypasses the selector entirely — Tekton template also gates the param in the else branch)
  • Empty --instance-families (default) → no restriction, existing behavior unchanged
  • Filter uses dot-separator check (strings.HasPrefix(t, fam+".")) so m5 does not match m5a

Cap fix

When InstanceFamilies is set, MaxResults is no longer passed to FilterVerbose. Without this fix, the selector could return 20 results all outside the allowlist (e.g. GPU/storage types ranked highest), leaving nothing after filterByFamily even though matching types exist beyond position 20. The cap is now applied after filtering.

Verification — live AWS API (us-east-1)

Tested against real DescribeInstanceTypes API using the amazon-ec2-instance-selector library (same library mapt uses internally).

4 vCPU / 16 GiB

Without --instance-families — 20 types returned, including GPU and storage-optimized:

d3en.xlarge   ← dense storage (~3x cost)
g4ad.xlarge   ← GPU
g4dn.xlarge   ← GPU
g5.xlarge     ← GPU
g6.xlarge     ← GPU
g6f.xlarge    ← GPU
inf2.xlarge   ← ML inference
m4.xlarge
m5.xlarge
m5a.xlarge
m5ad.xlarge
m5d.xlarge
m5dn.xlarge
m5n.xlarge
m5zn.xlarge
m6a.xlarge
m6i.xlarge
m6id.xlarge
m6idn.xlarge
m6in.xlarge

With --instance-families m5,m6i,m7i:

m5.xlarge
m6i.xlarge

Note: m5a.xlarge correctly excluded — dot-separator enforced (m5 does not match m5a).

8 vCPU / 64 GiB

Without --instance-families:

d3.2xlarge    ← dense storage
g6e.2xlarge   ← GPU
g7e.2xlarge   ← GPU
i3en.2xlarge  ← NVMe storage
i4i.2xlarge   ← NVMe storage
i7i.2xlarge   ← NVMe storage
i7ie.2xlarge  ← NVMe storage
r5.2xlarge
r5a.2xlarge
r5ad.2xlarge
r5b.2xlarge
r5d.2xlarge
r5dn.2xlarge
r5n.2xlarge
r6a.2xlarge
r6i.2xlarge
r6id.2xlarge
r6idn.2xlarge
r6in.2xlarge
r7a.2xlarge

With --instance-families r5,r6i:

r5.2xlarge
r6i.2xlarge

Full e2e (mapt CLI → EC2 → destroy)

mapt aws rhel create --cpus 4 --memory 16 --instance-families m5,m6i,m7i

Debug log confirms: Requesting an on-demand instance of type: m5.xlarge

Instance provisioned, SSH reachable, destroyed cleanly (14 resources). No GPU or storage-optimized type selected.

🤖 Generated with Claude Code

Amos Mastbaum added 3 commits July 30, 2026 00:07
Post-filters getInstanceTypes() output to only instance types whose
family prefix matches the allowlist. Bypassed when ComputeSizes is set.

Fixes: redhat-developer#684
Comma-separated allowlist of AWS family prefixes (e.g. m5,m6i,m7i).
Post-filters instance selector output. No-op when --compute-sizes is set.
Passes --instance-families to mapt when set. Conditional: only in the
else branch (when compute-sizes is empty) since compute-sizes bypasses
the selector entirely.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added an optional AWS instance-family allowlist for compute provisioning (comma-separated family prefixes like m5, c6i).
    • Exposed instance-families in CLI and Tekton provisioning tasks; it’s applied only when compute sizes aren’t set.
    • Added an operator-channel override (comma-separated package=channel entries) for OpenShift SNC flows.
  • Bug Fixes
    • Ensured instance types are post-filtered by allowed families and then capped to the requested maximum.
  • Tests
    • Added unit coverage for empty/nil inputs, single/multiple families, exact prefix matching, and fully filtered results.

Walkthrough

Adds an optional AWS instance-family allowlist to compute request arguments, filters computed instance types by exact family prefixes, and passes the setting through CLI and Tekton provisioning commands when compute-sizes is unset. The OCP Tekton task also supports operator-channel overrides.

Changes

Instance-family filtering

Layer / File(s) Summary
Request contract and CLI wiring
pkg/provider/api/compute-request/compute-request.go, cmd/mapt/cmd/params/params.go
Adds InstanceFamilies to compute request arguments and maps the --instance-families string-slice flag into the request.
AWS instance-family filtering
pkg/provider/aws/data/compute-request.go, pkg/provider/aws/data/compute-request_test.go
Filters instance types by exact family prefixes, applies MaxResults after filtering, and tests empty, single-family, multiple-family, unmatched, and nil-input cases.
Tekton provisioning wiring
tkn/infra-aws-*.yaml, tkn/template/infra-aws-*.yaml
Adds the optional parameter and conditionally appends --instance-families during create operations when compute sizes are unset.

Operator-channel wiring

Layer / File(s) Summary
Operator-channel create wiring
tkn/infra-aws-ocp-snc.yaml
Adds an optional comma-separated operator-channel parameter and appends one --operator-channel argument for each entry during create operations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TektonTask
  participant MaptCLI
  participant ComputeRequest
  participant AWSInstanceSelector

  TektonTask->>MaptCLI: Pass --instance-families during create
  MaptCLI->>ComputeRequest: Populate InstanceFamilies
  ComputeRequest->>AWSInstanceSelector: Request instance types
  AWSInstanceSelector->>AWSInstanceSelector: Filter exact family prefixes
  AWSInstanceSelector-->>ComputeRequest: Return filtered types capped by MaxResults
Loading

Suggested reviewers: jangel97

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The operator-channel Tekton parameter and command wiring are unrelated to the instance-family filtering objective. Move the operator-channel work to a separate PR or link a requirement that explicitly calls for it.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #684 by adding an allowlist filter that avoids expensive specialized instance families.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly summarizes the main change: adding an instance-families flag to filter AWS instance selector output.
Description check ✅ Passed The description is directly related to the changeset and accurately explains the new instance-families behavior and related files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/provider/aws/data/compute-request.go`:
- Line 52: Update the compute request filtering flow around filterByFamily so
InstanceFamilies is applied before MaxResults truncates selector results. When
args.InstanceFamilies is provided, avoid the premature cap or expand it
sufficiently while filtering the allowlisted families, then apply the requested
result limit to the filtered set.

In `@tkn/template/infra-aws-ocp-snc.yaml`:
- Around line 268-270: Stop interpolating the externally supplied
instance-families value into the eval-based command construction; build the
command as an argument list and invoke it directly with safe quoting or a Bash
array. Apply the fix to tkn/template/infra-aws-ocp-snc.yaml lines 268-270, then
regenerate or apply the equivalent change to tkn/infra-aws-ocp-snc.yaml lines
268-270; make the same change in tkn/template/infra-aws-rhel.yaml lines 283-285
and tkn/infra-aws-rhel.yaml lines 283-285.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b3182e54-14b7-4474-af4a-489a865a6fdd

📥 Commits

Reviewing files that changed from the base of the PR and between 6e3cacf and 2d6ea43.

📒 Files selected for processing (8)
  • cmd/mapt/cmd/params/params.go
  • pkg/provider/api/compute-request/compute-request.go
  • pkg/provider/aws/data/compute-request.go
  • pkg/provider/aws/data/compute-request_test.go
  • tkn/infra-aws-ocp-snc.yaml
  • tkn/infra-aws-rhel.yaml
  • tkn/template/infra-aws-ocp-snc.yaml
  • tkn/template/infra-aws-rhel.yaml

Comment thread pkg/provider/aws/data/compute-request.go
Comment thread tkn/template/infra-aws-ocp-snc.yaml
Amos Mastbaum added 3 commits July 30, 2026 01:15
When InstanceFamilies is set, skip MaxResults in the selector so allowlisted
families ranked outside the top 20 are not silently dropped. Cap to MaxResults
manually after filterByFamily.
Exposes the --operator-channel CLI flag as a Tekton task param so
callers can override OLM subscription channels per operator.

Example: rhods-operator=stable-3.x to install RHOAI 3.x instead of
the default stable (2.25.x) channel.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tkn/infra-aws-ocp-snc.yaml (1)

274-276: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Do not interpolate these parameters into an eval command.

The assembled command is executed with eval at Line 325. operator-channel is inserted unquoted, allowing values such as package=stable; ... to execute arbitrary shell commands; an apostrophe or command substitution in instance-families can similarly escape its wrapper. Because the task loads AWS credentials, this can expose credentials or alter provisioning.

Build the command as a Bash argument array and invoke it without eval, or strictly validate and shell-escape both parameters before appending them; also reject malformed package=channel entries.

As per path instructions, focus on major issues impacting security and avoid nitpicks and verbosity.

Also applies to: 294-299

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tkn/infra-aws-ocp-snc.yaml` around lines 274 - 276, Replace the eval-based
command construction with a Bash argument array and invoke it directly,
preserving each parameter as a separate argument. Safely pass
params.instance-families and operator-channel without interpolation, and
validate operator-channel as a well-formed package=channel entry before
execution. Ensure malformed or unexpected values are rejected before the AWS
provisioning command runs.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tkn/infra-aws-ocp-snc.yaml`:
- Around line 274-276: Replace the eval-based command construction with a Bash
argument array and invoke it directly, preserving each parameter as a separate
argument. Safely pass params.instance-families and operator-channel without
interpolation, and validate operator-channel as a well-formed package=channel
entry before execution. Ensure malformed or unexpected values are rejected
before the AWS provisioning command runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 27bc3a1f-0472-444d-8cfe-c8c48cdba136

📥 Commits

Reviewing files that changed from the base of the PR and between e2e4670 and 1e3f2a8.

📒 Files selected for processing (1)
  • tkn/infra-aws-ocp-snc.yaml

Verifies that allowlisted families ranked outside the top MaxResults
are not silently dropped when InstanceFamilies is set.

@ppitonak ppitonak 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.

Any reason not to update other infra-aws-* Tekton tasks?

Comment thread tkn/template/infra-aws-ocp-snc.yaml
@ppitonak

Copy link
Copy Markdown
Collaborator

I tested spot instances and it seems to work fine.

@amastbau
amastbau requested a review from ppitonak July 30, 2026 12:12
@amastbau

Copy link
Copy Markdown
Author

Any reason not to update other infra-aws-* Tekton tasks?

done!

nestedVirtDesc string = "Use cloud instance that has nested virtualization support"
computeSizes string = "compute-sizes"
computeSizesDesc string = "Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args"
instanceFamilies string = "instance-families"

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.

Can we name it computeFamilies as this may / should have a matching functionality in azure?

@adrianriobo

Copy link
Copy Markdown
Collaborator

Aso rebase and fix conflicts

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.

[Bug] Expensive, specialised instances are selected when cpu/memory parameters are used

3 participants