Repository navigation
feat(tree): add WorkloadTree data model and builder - #87
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughIntroduces the ChangesWorkloadTree feature implementation
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Build
participant StructureSummary
participant ComponentFactory
participant PodMatcher
participant populateTotals
Caller->>Build: Build(ctx, karta, factory, pods, matcher)
Build->>StructureSummary: NewStructureSummary(karta)
Build->>ComponentFactory: GetRootComponent().GetStatus()
ComponentFactory-->>Build: matched status phases
loop for each child component
Build->>ComponentFactory: claimPods via PodMatcher.MatchComponent
PodMatcher-->>Build: claimed pods
Build->>PodMatcher: MatchInstance + ExtractReplicaKey per pod
PodMatcher-->>Build: instance+replica keys
Build->>ComponentFactory: GetExtractedInstances, GetScale
ComponentFactory-->>Build: extracted instances + scale
Build->>Build: build InstanceNode(s), recurse children
end
Build->>populateTotals: populateTotals(tree)
populateTotals-->>Build: PodCount + Resources rolled up
Build-->>Caller: *WorkloadTree
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
docs/design/workload-tree/design.md (1)
16-108: ⚡ Quick winAdd language identifiers to fenced code blocks.
Nine fenced code blocks lack language identifiers (directory tree at line 16 and schema definitions at lines 33, 40, 46, 54, 77, 86, 96, 104). Adding
textas the language specifier satisfies the linter and clarifies that these are language-agnostic schema representations.📝 Example fix for the directory tree block
-``` +```text pkg/tree/ tree.go WorkloadTree, WorkloadStatus, ComponentNode, InstanceNodeApply the same pattern to the eight schema blocks.
🤖 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 `@docs/design/workload-tree/design.md` around lines 16 - 108, Add the missing fenced-block language identifiers by changing the nine unlabeled code fences in the document to use "text" so the linter recognizes them; specifically update the directory tree block and the schema blocks that describe WorkloadTree, WorkloadStatus, ComponentNode, InstanceNode, WorkloadView, ComponentView, InstanceView, and ResourceSummary so each opening triple-backtick is followed by "text". Ensure every unlabeled block in the file is updated consistently.Source: Linters/SAST tools
🤖 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/tree/pod_matcher.go`:
- Around line 21-24: Change the constructor NewKartaPodMatcher to return the
PodMatcher interface instead of the concrete *KartaPodMatcher: update its
signature to return PodMatcher, have it still instantiate &KartaPodMatcher{}
internally, and adjust any callers or tests to accept the PodMatcher interface
where they currently expect *KartaPodMatcher; keep the concrete type
KartaPodMatcher unchanged.
In `@pkg/tree/view_builder_test.go`:
- Around line 53-73: The test is missing assertions for aggregated memory;
update the test (the It block using NewWorkloadView and variable view) to assert
view.Resources.MemoryBytes equals the combined memory of both pods and also
assert the child component's memory (view.Children[0].Resources.MemoryBytes)
matches that same total; for these pods (each with resource.MustParse("8Gi"))
add expectations for MemoryBytes == 17179869184 (int64) or compute 16Gi in bytes
to validate correct aggregation.
---
Nitpick comments:
In `@docs/design/workload-tree/design.md`:
- Around line 16-108: Add the missing fenced-block language identifiers by
changing the nine unlabeled code fences in the document to use "text" so the
linter recognizes them; specifically update the directory tree block and the
schema blocks that describe WorkloadTree, WorkloadStatus, ComponentNode,
InstanceNode, WorkloadView, ComponentView, InstanceView, and ResourceSummary so
each opening triple-backtick is followed by "text". Ensure every unlabeled block
in the file is updated consistently.
🪄 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: Enterprise
Run ID: 6560adf6-e900-45c5-a296-4cfb2aa809df
📒 Files selected for processing (37)
docs/design/workload-tree/design.mddocs/examples/quickstart/README.mddocs/examples/quickstart/main.gopkg/instructions/summary.gopkg/tree/builder.gopkg/tree/builder_test.gopkg/tree/pod_matcher.gopkg/tree/pod_matcher_mock.gopkg/tree/pod_matcher_test.gopkg/tree/suite_test.gopkg/tree/testdata/jobset/events.yamlpkg/tree/testdata/jobset/expected.yamlpkg/tree/testdata/jobset/pods.yamlpkg/tree/testdata/lws/events.yamlpkg/tree/testdata/lws/expected.yamlpkg/tree/testdata/lws/pods.yamlpkg/tree/testdata/pytorch/events_extended.yamlpkg/tree/testdata/pytorch/events_minimal.yamlpkg/tree/testdata/pytorch/expected_extended.yamlpkg/tree/testdata/pytorch/expected_minimal.yamlpkg/tree/testdata/pytorch/pods_extended.yamlpkg/tree/testdata/pytorch/pods_minimal.yamlpkg/tree/testdata/pytorch/workload_extended.yamlpkg/tree/testdata/pytorch/workload_minimal.yamlpkg/tree/testdata/raycluster/events_extended.yamlpkg/tree/testdata/raycluster/events_minimal.yamlpkg/tree/testdata/raycluster/expected_extended.yamlpkg/tree/testdata/raycluster/expected_minimal.yamlpkg/tree/testdata/raycluster/pods_extended.yamlpkg/tree/testdata/raycluster/pods_minimal.yamlpkg/tree/testdata/raycluster/workload_extended.yamlpkg/tree/testdata/raycluster/workload_minimal.yamlpkg/tree/tree.gopkg/tree/view.gopkg/tree/view_builder.gopkg/tree/view_builder_test.gopkg/tree/yaml_examples_test.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/design/cli/high-level-design.md (1)
283-283:⚠️ Potential issue | 🔴 CriticalFix Build function signature in documentation to match actual implementation.
Line 283 documents the signature as
func Build(ctx context.Context, ri *ResourceInterface, workload client.Object, pods []corev1.Pod, matcher PodMatcher), but the actual implementation inpkg/tree/builder.gousesfunc Build(ctx context.Context, karta *v1alpha1.Karta, factory *resource.ComponentFactory, pods []corev1.Pod, matcher PodMatcher). The documented parameters are incorrect and will mislead users. Update parameter names and types to match the actual function.Additionally, remove bold formatting from lines 61-67 (Semantic role names, Pods grouped by their role, Normalized phase, Desired vs current replicas, Collapsed plumbing) and use inline code or plain text instead, as shown in the refactored display layer section.
🤖 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 `@docs/design/cli/high-level-design.md` at line 283, Update the Build function signature in the documentation at line 283 to match the actual implementation in pkg/tree/builder.go. Replace the incorrect parameters ri *ResourceInterface and workload client.Object with the correct ones: karta *v1alpha1.Karta and factory *resource.ComponentFactory. Additionally, remove the bold formatting from lines 61-67 (the list items covering Semantic role names, Pods grouped by their role, Normalized phase, Desired vs current replicas, and Collapsed plumbing) and replace it with inline code formatting or plain text to maintain consistent styling with the refactored display layer section.
🧹 Nitpick comments (1)
docs/design/cli/high-level-design.md (1)
61-67: ⚡ Quick winRemove bold emphasis from key concept names.
Lines 61–67 use bold (
**Semantic role names**,**Pods grouped by their role**,**Normalized phase**, etc.) to highlight concepts for emphasis. This violates the Markdown style guideline. The refactored display layer section (lines 309–317) correctly avoids bold emphasis, using inline code and plain text instead.Remove bold formatting from all concept labels in this subsection.
Proposed style fix for lines 61–67
- **Semantic role names** - Frontend / PrefillWorker / DecodeWorker come from the label mapping declared in the Karta YAML. - **Pods grouped by their role, not by their owner** - pods playing different roles are shown as separate groups even when they share the same owning resource. - **Normalized phase** - `Running` has the same meaning across PyTorchJob, RayCluster, Dynamo, etc. - **Desired vs current replicas** - `3/4 replicas` shows the scale target vs. the actual pod count, per role. - **Collapsed plumbing** - intermediate objects (DynamoComponentDeployment, LeaderWorkerSet) are optionally hidden to reduce noise while keeping the semantic hierarchy visible. + Semantic role names - Frontend / PrefillWorker / DecodeWorker come from the label mapping declared in the Karta YAML. + Pods grouped by their role, not by their owner - pods playing different roles are shown as separate groups even when they share the same owning resource. + Normalized phase - `Running` has the same meaning across PyTorchJob, RayCluster, Dynamo, etc. + Desired vs current replicas - `3/4 replicas` shows the scale target vs. the actual pod count, per role. + Collapsed plumbing - intermediate objects (DynamoComponentDeployment, LeaderWorkerSet) are optionally hidden to reduce noise while keeping the semantic hierarchy visible.🤖 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 `@docs/design/cli/high-level-design.md` around lines 61 - 67, In the high-level design section of the documentation, remove the bold emphasis (the `**` markers) from all concept labels: "Semantic role names", "Pods grouped by their role", "Normalized phase", "Desired vs current replicas", and "Collapsed plumbing". Replace them with plain text format, following the style pattern used in the refactored display layer section which uses inline code and plain text instead of bold for consistency with the Markdown style guidelines.Source: Coding guidelines
🤖 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 `@docs/design/cli/high-level-design.md`:
- Line 283: Update the Build function signature in the documentation at line 283
to match the actual implementation in pkg/tree/builder.go. Replace the incorrect
parameters ri *ResourceInterface and workload client.Object with the correct
ones: karta *v1alpha1.Karta and factory *resource.ComponentFactory.
Additionally, remove the bold formatting from lines 61-67 (the list items
covering Semantic role names, Pods grouped by their role, Normalized phase,
Desired vs current replicas, and Collapsed plumbing) and replace it with inline
code formatting or plain text to maintain consistent styling with the refactored
display layer section.
---
Nitpick comments:
In `@docs/design/cli/high-level-design.md`:
- Around line 61-67: In the high-level design section of the documentation,
remove the bold emphasis (the `**` markers) from all concept labels: "Semantic
role names", "Pods grouped by their role", "Normalized phase", "Desired vs
current replicas", and "Collapsed plumbing". Replace them with plain text
format, following the style pattern used in the refactored display layer section
which uses inline code and plain text instead of bold for consistency with the
Markdown style guidelines.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 144a31b4-e00c-46f3-bb0a-9e52dec27a51
📒 Files selected for processing (14)
docs/design/cli/high-level-design.mddocs/design/workload-tree/design.mddocs/examples/quickstart/README.mddocs/examples/quickstart/main.gopkg/tree/builder.gopkg/tree/builder_test.gopkg/tree/testdata/jobset/expected.yamlpkg/tree/testdata/lws/expected.yamlpkg/tree/testdata/pytorch/expected_extended.yamlpkg/tree/testdata/pytorch/expected_minimal.yamlpkg/tree/testdata/raycluster/expected_extended.yamlpkg/tree/testdata/raycluster/expected_minimal.yamlpkg/tree/tree.gopkg/tree/yaml_examples_test.go
💤 Files with no reviewable changes (7)
- pkg/tree/testdata/jobset/expected.yaml
- pkg/tree/testdata/raycluster/expected_minimal.yaml
- pkg/tree/testdata/pytorch/expected_minimal.yaml
- pkg/tree/testdata/pytorch/expected_extended.yaml
- pkg/tree/testdata/raycluster/expected_extended.yaml
- pkg/tree/testdata/lws/expected.yaml
- pkg/tree/tree.go
✅ Files skipped from review due to trivial changes (2)
- docs/design/workload-tree/design.md
- docs/examples/quickstart/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
- docs/examples/quickstart/main.go
- pkg/tree/builder_test.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/tree/tree.go (1)
8-8:⚠️ Potential issue | 🔴 CriticalImport
k8s.io/apimachinery/pkg/runtime/schemaand useschema.GroupVersionKindinstead ofmetav1.GroupVersionKind.
GroupVersionKindis defined ink8s.io/apimachinery/pkg/runtime/schema, notpkg/apis/meta/v1. The current code at line 51 will fail to compile.Fix
import ( corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "github.com/run-ai/karta/pkg/resource" )type ComponentNode struct { Name string // Kind is nil for logical grouping components (those without a Kind in the definition). - Kind *metav1.GroupVersionKind + Kind *schema.GroupVersionKind HasPodDefinition bool PodCount int Resources Resources Instances []InstanceNode }🤖 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 `@pkg/tree/tree.go` at line 8, The code is using metav1.GroupVersionKind which does not exist in that package. Add a new import statement for k8s.io/apimachinery/pkg/runtime/schema (aliased as schema), then locate where GroupVersionKind is used in the code (referenced at line 51) and change the reference from metav1.GroupVersionKind to schema.GroupVersionKind to use the correct package where this type is actually defined.
🤖 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 `@pkg/tree/tree.go`:
- Line 8: The code is using metav1.GroupVersionKind which does not exist in that
package. Add a new import statement for k8s.io/apimachinery/pkg/runtime/schema
(aliased as schema), then locate where GroupVersionKind is used in the code
(referenced at line 51) and change the reference from metav1.GroupVersionKind to
schema.GroupVersionKind to use the correct package where this type is actually
defined.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 9b2eb13f-7ff3-4d1b-acd6-378fbc610032
📒 Files selected for processing (12)
docs/design/workload-tree/design.mdpkg/tree/builder.gopkg/tree/testdata/jobset/expected.yamlpkg/tree/testdata/lws/expected.yamlpkg/tree/testdata/pytorch/expected_extended.yamlpkg/tree/testdata/pytorch/expected_minimal.yamlpkg/tree/testdata/raycluster/expected_extended.yamlpkg/tree/testdata/raycluster/expected_minimal.yamlpkg/tree/totals.gopkg/tree/totals_test.gopkg/tree/tree.gopkg/tree/yaml_examples_test.go
✅ Files skipped from review due to trivial changes (4)
- pkg/tree/testdata/jobset/expected.yaml
- pkg/tree/testdata/lws/expected.yaml
- docs/design/workload-tree/design.md
- pkg/tree/testdata/pytorch/expected_minimal.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
- pkg/tree/testdata/raycluster/expected_minimal.yaml
- pkg/tree/testdata/pytorch/expected_extended.yaml
- pkg/tree/testdata/raycluster/expected_extended.yaml
- pkg/tree/builder.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/design/cli/high-level-design.md (1)
301-302:⚠️ Potential issue | 🟡 MinorUpdate the Build() function signature to match the actual implementation. The second and third parameters are incorrect: the documented
ri *ResourceInterface, workload client.Objectshould bekarta *v1alpha1.Karta, factory *resource.ComponentFactory.🤖 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 `@docs/design/cli/high-level-design.md` around lines 301 - 302, Update the Build() function signature in the design documentation to match the actual implementation. Replace the second and third parameters from `ri *ResourceInterface, workload client.Object` with `karta *v1alpha1.Karta, factory *resource.ComponentFactory` to accurately reflect what the function accepts in the real codebase.
🤖 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 `@docs/design/cli/high-level-design.md`:
- Around line 301-302: Update the Build() function signature in the design
documentation to match the actual implementation. Replace the second and third
parameters from `ri *ResourceInterface, workload client.Object` with `karta
*v1alpha1.Karta, factory *resource.ComponentFactory` to accurately reflect what
the function accepts in the real codebase.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 9cdfe695-6ecc-4bb0-bd2e-172dc5320b01
📒 Files selected for processing (1)
docs/design/cli/high-level-design.md
Apply Ron Lev's review on PR #87: - Build now takes only the ComponentFactory and derives the Karta from it via a new ComponentFactory.GetKarta(); rewrite the Build doc comment. - Resources holds k8s resource.Quantity (CPU/Memory/GPU) instead of raw int64/float64, so units round-trip exactly and fractional GPU is preserved. - WorkloadStatus is now optional (*WorkloadStatus); nil means no status was evaluated, e.g. an offline pre-submission tree. - Totals derive pod-bearing from leaf instances rather than HasPodDefinition, and set ResourcesIncomplete when a node has desired pods whose per-pod resources cannot be resolved, instead of silently reporting zero. - Rename effectiveReplicas to replicaBounds. - Document why every component (including single-instance) carries an InstanceNode and why child components are built per instance. - Assert exact pod counts and replica bounds in the builder tests; regenerate the golden fixtures for the Quantity serialization. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Roee Gil <roee.gil@run.ai>
ronlv10
left a comment
There was a problem hiding this comment.
Overall looks good to me - I think that the solution of the yamls is an overkill and would made us to update the yamls for any change and on the other hand is hard to verify the output (need to look on 3 files in order to verify
I suggest
- convert them to test if there are not cover - e.g, pytorch and dyanmo and check the tree
- maybe create a diagram/image and add to the doc (you can open an issue ) so we would be able to visuals in our docs how the tree looks like - I think it could bring value
There was a problem hiding this comment.
I think you changed the deisgn doc too much here
it's fine to correction but for example you deleted the pod matcher - which still relevant to the CLI but we decided to split it differently
in the past we didn't really update design docs(before ai and pr that is a design doc)- I think it's fine to make correction after different decision but not to change entirely - for example it's fine to update what is workload tree post-discussion , that we added resource , etc
Isan-Rivkin
left a comment
There was a problem hiding this comment.
Minor comments, overall like but Im still in partial review will continue tomorrow.
Wanted to publish something not to delay the minor stuff.
Regarding the testing of expected yamls, didnt review as discussed
| instanceKeys = []string{""} | ||
| } | ||
| keys := append([]string(nil), instanceKeys...) | ||
| sort.Strings(keys) |
There was a problem hiding this comment.
taken from Map, using sort keep the sorted list aligned, instead of getting each call a different list arrangement
152402b to
d0d091f
Compare
|
|
||
| // GetChildComponentsOf retrieves the direct child components of the named parent, | ||
| // resolved from the structure's OwnerRef relationships. | ||
| func (f *ComponentFactory) GetChildComponentsOf(parentName string) ([]*Component, error) { |
There was a problem hiding this comment.
why you put it here? I think it should be in the tree..
There was a problem hiding this comment.
The factory has the karta and the object. The tree comes afterwards
| baseChildren, err := buildComponentNodes(ctx, children, factory) | ||
| if err != nil { |
There was a problem hiding this comment.
baseChildren -> instanceChildren
There was a problem hiding this comment.
But it returns a component child list
| // ranged over the scale envelope. A pod-bearing leaf counts its own replicas | ||
| // (defaulting to one when it declares no scale); a non-pod leaf counts nothing; | ||
| // a non-leaf rolls up its children. | ||
| func instancePodCount(children []ComponentNode, scale *resource.Scale, hasPodDefinition bool) PodCount { |
There was a problem hiding this comment.
I think you're missing here a case where instance has pods and also children
not sure if it's a valid case but not sure it doesn't and we miss it here
There was a problem hiding this comment.
var total PodCount
if hasPodDefinition {
minReplicas, maxReplicas := replicaBounds(scale)
total = PodCount{Min: minReplicas, Max: maxReplicas}
}
for _, child := range children {
total.Min += child.PodCount.Min
total.Max += child.PodCount.Max
}
return total
probably something like this
There was a problem hiding this comment.
This logic breaks in the case where the instance has a replica and also has children. We ignore the instance and replica count. This sums it up.
There was a problem hiding this comment.
TBH I think that we should have a builder that in the test you override what's need for the test and then when reading the test is clear and you don't need to jump to this file - but that's not the first case so I get it if it too much now
| *~ | ||
| .vscode/ | ||
| .idea | ||
| /docs/examples/quickstart/quickstart |
There was a problem hiding this comment.
Add to ignore: this is the binary created when running go build
| // replicaBounds returns the min and max desired replica counts for a scale. | ||
| // A nil scale defaults to one replica: assumes that a pod-bearing component that declares no | ||
| // scale still runs a single pod. | ||
| func replicaBounds(scale *resource.Scale) (minReplicas, maxReplicas int) { |
There was a problem hiding this comment.
Min-only scale yields Max < Min, for example PodCount{Min:3, Max:0}.
- suggest to add a test with min only
- define the correct behavior, indicate it's optional with a pointer or something
There was a problem hiding this comment.
pointer is used to locate an unbounded pod number. If CR allows this, we cannot predict the behavior, so we cannot assume anything here. It is what it is.
There was a problem hiding this comment.
That's exactly what I am saying, we cannot assume anything.
No assumption means indicating we don't know e.g return a pointer.
Returning PodCount{Min:3, Max:0} is the assumption because user of this doesn't have a way to know if it was set or not in the first place.
A common behavior might be: if max: set + < min -> error else if not set -> no limit.
We can't tell that here using this api.
There was a problem hiding this comment.
So no error will be triggered, but the min and max will be derived from the min and max values or missing values.
| // replicaBounds returns the min and max desired replica counts for a scale. | ||
| // A nil scale defaults to one replica: assumes that a pod-bearing component that declares no | ||
| // scale still runs a single pod. | ||
| func replicaBounds(scale *resource.Scale) (minReplicas, maxReplicas int) { |
There was a problem hiding this comment.
That's exactly what I am saying, we cannot assume anything.
No assumption means indicating we don't know e.g return a pointer.
Returning PodCount{Min:3, Max:0} is the assumption because user of this doesn't have a way to know if it was set or not in the first place.
A common behavior might be: if max: set + < min -> error else if not set -> no limit.
We can't tell that here using this api.
Isan-Rivkin
left a comment
There was a problem hiding this comment.
Thanks, asking for changes due to single left over max/mix/calculation of podcount
LMK what u think
| } | ||
|
|
||
| // replicaBounds returns the min and max desired replica counts for a scale. | ||
| // A nil scale defaults to one replica: assumes that a pod-bearing component that declares no |
There was a problem hiding this comment.
irrelevant comments to maintain the details in the code very clear
| // A nil scale defaults to one replica: assumes that a pod-bearing component that declares no | ||
| // scale still runs a single pod. maxReplicas is nil when a minimum was declared but no maximum | ||
| // was, i.e. the scale has no upper bound. | ||
| func replicaBounds(scale *resource.Scale) (minReplicas int, maxReplicas *int) { |
There was a problem hiding this comment.
Before you read this: if it's not too much to maintain PodCount as part of the tree.
Not sure if this is our of scope or not for this PR ( ☝️ ). In current form with pod count 👇
The behavior is still inconsistent now.
type PodCount struct {
Min int
Max *int
}The reverse of min<max&0 issues applies here too:
-
min:0 max: 800// min explicit 0 -
max:800// min omitted, framework default -
scale == nil-> returns(1, *1)was this set or default?? -
min: 2-> returns(1,nil) -
max: 2-> returns(1,2)// asymmetric behavior
So 2 issues here:
- Whoever uses this function has no way of predicting what it does without deep diving into the source code of this func.
- The reverse of the max-not or 0 issues: there's no way to distinguish if 0 was set or omitted.
What I suggest:
Option 1
func replicaBounds(scale *resource.Scale) (minReplicas *int, maxReplicas *int) {- Also:
if scale == nilreturn(0,0)
Option 2:
func replicaBounds(scale *resource.Scale, default [2]int) (minReplicas int, maxReplicas int) {Add the WorkloadTree data model and builder that ranges pod counts and resources over the scale envelope, resolves child components, and validates the Karta object before building. Includes YAML-driven example tests. Signed-off-by: Roee Gil <roee.gil@run.ai>
0fb1e59 to
bd1f672
Compare
What does this PR do?
Implements the
WorkloadTreedata model and builder for the Karta library.Adds
pkg/tree/with:WorkloadTree— raw extraction result (component hierarchy, matched pods, scale, status)WorkloadView— display layer with aggregated resource sums, ready counts, node listsBuild()— assembles aWorkloadTreefrom a Karta definition,ComponentFactory, and pod listPodMatcherinterface — decouples tree structure from pod matching strategyKartaPodMatcher— default implementation usingPodSelectordefinitionsNewWorkloadView()— computes display-layer values from aWorkloadTreeAlso adds two exported accessor methods to
StructureSummary(ChildrenOf,ParentOf) used by the tree builder.Includes design document:
docs/design/workload-tree/design.mdRelated issue(s)
Fixes #85
Checklist
git commit -s)make check)Summary by CodeRabbit
Release Notes
New Features
Documentation