-
Notifications
You must be signed in to change notification settings - Fork 580
fix: take into account number of workers from config #1365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
""" WalkthroughThe changes refactor and relocate logic for merging and overriding deployment specifications and environment variables for DynamoComponentDeployments. Merging and override functions are removed from the controller and implemented in the internal dynamo package. Associated tests are deleted from the controller and reimplemented with expanded coverage in the dynamo package. Getter/setter methods and a new constant for deployment config environment variables are added. Changes
Sequence Diagram(s)sequenceDiagram
participant ParentCR as DynamoGraphDeployment (Parent CR)
participant GraphGen as GenerateDynamoComponentsDeployments
participant CompDep as DynamoComponentDeployment
ParentCR->>GraphGen: Provide parent spec, services config, ingress spec
GraphGen->>CompDep: Create initial deployment from service config
GraphGen->>CompDep: Merge with parent deployment spec (override)
GraphGen->>CompDep: Merge environment variables (service > parent)
GraphGen->>CompDep: Update DYN_DEPLOYMENT_CONFIG env var (set port if main)
GraphGen->>CompDep: Override spec from DYN_DEPLOYMENT_CONFIG (replicas/resources)
GraphGen->>CompDep: Set GPU scheduling annotations if needed
GraphGen->>ParentCR: Return map of merged deployments
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (4)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (6)
deploy/cloud/operator/internal/consts/consts.go (1)
70-72
: Consider aligning the constant name with existing Env-prefixed naming schemeMost environment-variable constants in this file follow the pattern
Env<Something>
.
DynamoDeploymentConfigEnvVar
is functionally correct, but it slightly breaks the naming consistency and makes “what is an env-var vs. a plain constant” harder to grep for.- DynamoDeploymentConfigEnvVar = "DYN_DEPLOYMENT_CONFIG" + EnvDynamoDeploymentConfig = "DYN_DEPLOYMENT_CONFIG"Renaming now will avoid future churn, because this identifier will quickly propagate throughout the codebase.
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types.go (1)
180-191
: Setter overwrites but never removes the env-var
SetDynamoDeploymentConfig(nil)
is currently a no-op and leaves the last value in place.
If the caller wants to “clear” the config, there is no API.Either:
- Document that
nil
is not supported, or- Treat
len(config)==0
as a delete request:if len(config) == 0 { // delete existing entry for i, env := range s.Spec.Envs { if env.Name == commonconsts.DynamoDeploymentConfigEnvVar { s.Spec.Envs = append(s.Spec.Envs[:i], s.Spec.Envs[i+1:]...) return } } }deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types_test.go (2)
131-134
: Preferbytes.Equal
for byte-slice comparison
reflect.DeepEqual
works but is slower and less explicit thanbytes.Equal
for raw byte slices.- if got := s.GetDynamoDeploymentConfig(); !reflect.DeepEqual(got, tt.want) { + if got := s.GetDynamoDeploymentConfig(); !bytes.Equal(got, tt.want) {(or convert both to string and compare).
This keeps intent crystal-clear and avoids accidental misuse when the type changes.
207-209
: Test resilience: order-sensitive comparison ofEnvs
sliceThe assertion compares the entire slice literally. If unrelated env-vars are appended elsewhere in the code, this test will start failing even though
SetDynamoDeploymentConfig
still behaves correctly.A more future-proof check:
var found bool for _, e := range s.Spec.DynamoComponentDeploymentSharedSpec.Envs { if e.Name == commonconsts.DynamoDeploymentConfigEnvVar && e.Value == string(tt.args.config) { found = true break } } if !found { t.Fatalf("env %s not set to expected value", commonconsts.DynamoDeploymentConfigEnvVar) }deploy/cloud/operator/internal/dynamo/graph.go (1)
512-531
:mergeEnvs
loses deterministic orderUsing a map provides O(1) overrides but produces non-deterministic
ordering, which complicates diffing and may surprise users inspecting
the CR. A stable order (specific first, then common sorted) costs very
little:func mergeEnvs(common, specific []corev1.EnvVar) []corev1.EnvVar { seen := map[string]struct{}{} merged := make([]corev1.EnvVar, 0, len(common)+len(specific)) // keep specific order for _, e := range specific { merged = append(merged, e) seen[e.Name] = struct{}{} } // append remaining common envs alphabetically sort.Slice(common, func(i,j int) bool { return common[i].Name < common[j].Name }) for _, e := range common { if _, ok := seen[e.Name]; !ok { merged = append(merged, e) } } return merged }deploy/cloud/operator/internal/dynamo/graph_test.go (1)
1832-1838
: Sort both slices (want & got) to avoid order-dependent failures
mergeEnvs
now returns a non-deterministic order (map iteration).
The test sorts only thegot
slice; ifwant
is declared out of alpha
order the comparison fails spuriously.- sort.Slice(got, func(i, j int) bool { return got[i].Name < got[j].Name }) + sort.Slice(got, func(i, j int) bool { return got[i].Name < got[j].Name }) + sort.Slice(tt.want, func(i, j int) bool { return tt.want[i].Name < tt.want[j].Name })
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types.go
(2 hunks)deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types_test.go
(2 hunks)deploy/cloud/operator/internal/consts/consts.go
(1 hunks)deploy/cloud/operator/internal/controller/dynamographdeployment_controller.go
(1 hunks)deploy/cloud/operator/internal/controller/dynamographdeployment_controller_test.go
(0 hunks)deploy/cloud/operator/internal/dynamo/graph.go
(3 hunks)deploy/cloud/operator/internal/dynamo/graph_test.go
(2 hunks)
💤 Files with no reviewable changes (1)
- deploy/cloud/operator/internal/controller/dynamographdeployment_controller_test.go
🧰 Additional context used
🧬 Code Graph Analysis (4)
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types.go (1)
deploy/cloud/operator/internal/consts/consts.go (1)
DynamoDeploymentConfigEnvVar
(71-71)
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types_test.go (2)
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types.go (4)
DynamoComponentDeploymentSpec
(40-46)DynamoComponentDeploymentStatus
(112-118)DynamoComponentDeploymentSharedSpec
(52-83)DynamoComponentDeployment
(129-135)deploy/cloud/operator/internal/consts/consts.go (1)
DynamoDeploymentConfigEnvVar
(71-71)
deploy/cloud/operator/internal/dynamo/graph_test.go (3)
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types.go (6)
DynamoComponentDeploymentSharedSpec
(52-83)IngressSpec
(98-109)DynamoComponentDeployment
(129-135)DynamoComponentDeploymentSpec
(40-46)ExternalService
(89-92)DynamoComponentDeploymentStatus
(112-118)deploy/cloud/operator/internal/dynamo/graph.go (9)
Resources
(61-66)DynamoGraphConfig
(165-169)ServiceConfig
(88-92)Config
(77-86)Autoscaling
(72-75)DynamoConfig
(54-59)GenerateDynamoComponentsDeployments
(286-425)ServiceArgs
(102-106)SetLwsAnnotations
(260-283)deploy/cloud/operator/internal/consts/consts.go (3)
KubeLabelDynamoComponent
(47-47)KubeLabelDynamoNamespace
(48-48)DynamoDeploymentConfigEnvVar
(71-71)
deploy/cloud/operator/internal/dynamo/graph.go (3)
deploy/cloud/operator/api/v1alpha1/dynamocomponentdeployment_types.go (2)
DynamoComponentDeploymentSharedSpec
(52-83)DynamoComponentDeployment
(129-135)deploy/cloud/operator/internal/consts/consts.go (2)
DynamoServicePort
(9-9)DynamoDeploymentConfigEnvVar
(71-71)deploy/sdk/src/dynamo/sdk/core/protocol/deployment.py (1)
Resources
(25-75)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build and Test - vllm
🔇 Additional comments (2)
deploy/cloud/operator/internal/controller/dynamographdeployment_controller.go (1)
137-141
: Side-effect of removed merging logic:replicas
/resources
overrides now only happen indynamo.GenerateDynamoComponentsDeployments
Just a heads-up: the controller no longer performs any overrides/merging.
If any downstream consumers still rely on the old behaviour (e.g. unit tests, CLI tooling), they must now invokeGenerateDynamoComponentsDeployments
instead. Please verify docs and examples accordingly.deploy/cloud/operator/internal/dynamo/graph.go (1)
371-382
: Consider failure-tolerant access toSpec.Services
and move env-merge up
- If the parent CR omits the
Services
map (nil
), the look-up on
parentDynamoGraphDeployment.Spec.Services[service.Name]
is safe (a
read on a nil map returns<zero, false>
), but the second use just
below (parentDynamoGraphDeployment.Spec.Services
) will panic when
you attempt to range over or assign.
A defensive nil check before the whole override-block avoids a future
foot-gun when the code is refactored:- if configOverride, ok := parentDynamoGraphDeployment.Spec.Services[service.Name]; ok { + svcOverrides := parentDynamoGraphDeployment.Spec.Services + if svcOverrides != nil { + if configOverride, ok := svcOverrides[service.Name]; ok { // ... } }
mergeEnvs
is called after themergo.Merge
.
If the parent override itself setsEnvs
, they are overwritten again
by the later merge. Swapping the two calls guarantees deterministic
precedence:- if len(parentDynamoGraphDeployment.Spec.Envs) > 0 { - deployment.Spec.Envs = mergeEnvs(parentDynamoGraphDeployment.Spec.Envs, deployment.Spec.Envs) - } - err := updateDynDeploymentConfig(deployment, commonconsts.DynamoServicePort) + deployment.Spec.Envs = mergeEnvs(parentDynamoGraphDeployment.Spec.Envs, + deployment.Spec.Envs) + err := updateDynDeploymentConfig(deployment, commonconsts.DynamoServicePort)Would you double-check that swapping the order does not break any of the
new tests? The public contract is unchanged, so the suite should still
pass.
Overview:
take into account number of workers from config
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Refactor