Skip to content

refactor: deployment variables cli#32

Merged
adityachoudhari26 merged 4 commits intomainfrom
refactor-deployment-variable-cli
Jun 2, 2025
Merged

refactor: deployment variables cli#32
adityachoudhari26 merged 4 commits intomainfrom
refactor-deployment-variable-cli

Conversation

@adityachoudhari26
Copy link
Member

@adityachoudhari26 adityachoudhari26 commented Jun 2, 2025

Summary by CodeRabbit

  • New Features

    • Deployment variables now support separate handling for direct values and reference values, providing clearer distinction and improved flexibility.
  • Refactor

    • The structure of deployment variables has been updated to use distinct fields for direct and reference values, replacing the previous unified approach.
    • Internal representations and API interactions for deployment variables have been streamlined for greater clarity and maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 2, 2025

Warning

Rate limit exceeded

@adityachoudhari26 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fee868a and 920d338.

📒 Files selected for processing (1)
  • cmd/ctrlc/root/apply/deployment.go (1 hunks)

Walkthrough

The changes refactor deployment variable handling by separating direct and reference variable values into distinct types and fields. Helper functions are introduced for converting these values to API types. The API client code is updated to support these new structures, including union type marshaling and unmarshaling logic for both direct and reference value representations.

Changes

File(s) Change Summary
cmd/ctrlc/root/apply/deployment.go Added helper functions for converting direct/reference variable values; refactored upsert logic to use them.
cmd/ctrlc/root/apply/types.go Split variable value struct into DirectDeploymentVariableValue and ReferenceDeploymentVariableValue; updated DeploymentVariable struct to use two separate slices.
internal/api/client.gen.go Refactored API structs to have explicit direct/reference value slices; added/renamed union types and methods for marshaling/unmarshaling; updated concurrency type.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant API

    User->>CLI: Initiate deployment variable upsert
    CLI->>CLI: Separate direct and reference variable values
    CLI->>CLI: Convert values using helper functions
    CLI->>API: Send request with DirectValues and ReferenceValues
    API-->>CLI: Respond with result
    CLI-->>User: Report outcome
Loading

Poem

A bunny hopped through fields of code,
Splitting values on its road.
Direct and reference, side by side,
With helper paws, it did divide.
Now the API, neat and clear—
Deployment carrots everywhere! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
cmd/ctrlc/root/apply/deployment.go (1)

72-106: Consider more efficient type conversion approach.

The current approach uses JSON marshal/unmarshal for type conversion, which adds unnecessary serialization overhead. Since you're converting between similar struct types, consider direct field assignment or a more efficient conversion method.

For better performance, you could implement direct conversion methods that map fields without JSON serialization, especially since the Value fields in both source and target types are of type any/interface{}.

internal/api/client.gen.go (1)

1186-1947: Comprehensive union type handling looks correct

The extensive union type marshaling/unmarshaling methods follow standard patterns for handling OpenAPI discriminated unions in Go. The implementation correctly handles all value types (string, float32, bool, map, array).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37956e6 and fee868a.

📒 Files selected for processing (3)
  • cmd/ctrlc/root/apply/deployment.go (1 hunks)
  • cmd/ctrlc/root/apply/types.go (1 hunks)
  • internal/api/client.gen.go (20 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
cmd/ctrlc/root/apply/deployment.go (2)
cmd/ctrlc/root/apply/types.go (4)
  • DirectDeploymentVariableValue (28-34)
  • ReferenceDeploymentVariableValue (36-43)
  • DeploymentVariable (45-51)
  • Config (6-11)
internal/api/client.gen.go (3)
  • DirectDeploymentVariableValue (225-230)
  • ReferenceDeploymentVariableValue (496-502)
  • DeploymentVariable (186-194)
cmd/ctrlc/root/apply/types.go (1)
internal/api/client.gen.go (2)
  • DirectDeploymentVariableValue (225-230)
  • ReferenceDeploymentVariableValue (496-502)
🔇 Additional comments (9)
cmd/ctrlc/root/apply/types.go (3)

28-34: LGTM! Well-structured direct value type definition.

The DirectDeploymentVariableValue struct is well-designed with appropriate field types and YAML tags. The non-pointer Value field of type any provides flexibility for different value types while maintaining simplicity.


36-43: LGTM! Clear reference value type definition.

The ReferenceDeploymentVariableValue struct appropriately captures reference-based variable semantics with mandatory Reference field, optional Path for nested references, and optional DefaultValue for fallback scenarios.


45-51: LGTM! Clean separation of value types in deployment variables.

The updated DeploymentVariable struct clearly separates direct and reference values into distinct slices, making the data model more explicit and easier to understand. This aligns well with the refactoring objectives.

cmd/ctrlc/root/apply/deployment.go (2)

114-132: LGTM! Clean separation of processing logic.

The updated upsertDeploymentVariable function correctly processes direct and reference values separately using the helper functions. The error handling with logging and continue is appropriate for this concurrent processing context.


134-140: LGTM! Properly structured API request body.

The request body construction correctly uses the separate DirectValues and ReferenceValues slices, aligning with the new API structure. The pointer assignment ensures optional fields are handled correctly.

internal/api/client.gen.go (4)

886-892: Update aligns with DeploymentVariable structure changes

The changes to CreateDeploymentVariableJSONBody correctly mirror the structural changes in DeploymentVariable, maintaining API consistency.


186-194:

Details

✅ Verification successful

Major API structure change requires careful migration

The restructuring of DeploymentVariable to separate DirectValues and ReferenceValues is a significant breaking change that improves clarity but requires updates to all API consumers.

Run the following script to identify affected code that needs updating:


🏁 Script executed:

#!/bin/bash
# Description: Find code that accesses the old 'Values' field of DeploymentVariable

# Search for usage of DeploymentVariable.Values
ast-grep --pattern 'DeploymentVariable {
  $$$
  Values: $_
  $$$
}'

# Also search for field access
rg -A 2 -B 2 'DeploymentVariable.*\.Values\b' --type go

Length of output: 128


No remaining Values field references—API change is safe

I ran searches across the Go client for any usage of the old DeploymentVariable.Values field and found no matches. It looks like all generated code and internal consumers have already been updated to use DirectValues and ReferenceValues. No further changes are required.


117-1947:

Details

✅ Verification successful

Verify this is truly generated code

Since this file is named client.gen.go, it appears to be generated code. Manual modifications to generated files will be lost on regeneration.

Run the following script to confirm this is generated code and locate the generator configuration:


🏁 Script executed:

#!/bin/bash
# Description: Verify if this is generated code and find the generation source

# Check for generation comments at the top of the file
head -20 internal/api/client.gen.go | grep -E "generated|Generated|DO NOT EDIT|Code generated"

# Look for OpenAPI spec files or generator configs
fd -e yaml -e yml -e json | xargs grep -l "openapi\|swagger" | head -10

# Check for code generation tools in go.mod
grep -E "oapi-codegen|openapi|swagger" go.mod

Length of output: 810


Generated Code Confirmed
This file (internal/api/client.gen.go) is auto-generated by the oapi-codegen tool.

  • The header includes:
    // Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
  • go.mod declares the generator and its runtime dependencies:
    tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
    github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
    github.com/oapi-codegen/runtime v1.1.1
    

Please avoid manual edits to this file; update the OpenAPI spec or generator configuration instead.


485-486:

Details

❓ Verification inconclusive

Verify the type change for PolicyConcurrency

Changing PolicyConcurrency from float32 to int32 could cause data loss if existing values have decimal parts.

Run the following script to check for potential decimal values:


🏁 Script executed:

#!/bin/bash
# Description: Check if PolicyConcurrency is used with decimal values

# Search for PolicyConcurrency usage with potential decimal values
rg -A 3 -B 3 'PolicyConcurrency.*[0-9]+\.[0-9]+|[0-9]+\.[0-9]+.*PolicyConcurrency' --type go

# Check JSON files for decimal concurrency values
fd -e json -x grep -l '"concurrency".*:.*[0-9]\+\.[0-9]\+' {} \;

Length of output: 164


Confirm safe conversion of PolicyConcurrency
A search for decimal literals in Go code and JSON fixtures returned no matches. Since converting from float32 to int32 will truncate any fractional parts, please manually verify that:

  • No configuration files, JSON/YAML fixtures, or database records define “concurrency” with decimal values
  • All API inputs or environment-provided values mapped to PolicyConcurrency are guaranteed to be integers
  • Any hard-coded or default values in internal/api/client.gen.go remain whole numbers

Once you’ve confirmed there are no non-integer concurrency values in use, document this decision.

Comment on lines +117 to 121
// BaseDeploymentVariableValue defines model for BaseDeploymentVariableValue.
type BaseDeploymentVariableValue struct {
IsDefault *bool `json:"isDefault,omitempty"`
ResourceSelector *map[string]interface{} `json:"resourceSelector"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Field rename is a breaking change

The rename from Default to IsDefault in BaseDeploymentVariableValue is clearer but will break existing API consumers.

Run the following script to check if there are any references to the old field name:


🏁 Script executed:

#!/bin/bash
# Description: Check for references to the old 'Default' field in deployment variable contexts

# Search for potential usage of the old field name
rg -A 3 -B 3 '\.Default\b.*deployment.*variable|deployment.*variable.*\.Default\b' --type go

Length of output: 94


Major Breaking Change: Rename DefaultIsDefault

We’ve renamed the Default field to IsDefault in BaseDeploymentVariableValue, which is a clear breaking change for any existing API consumers.

• No occurrences of the old .Default field remain in the codebase (verified via ripgrep).
Action required:

  • Bump the API major version to signal this breaking change.
  • Update any client code, documentation, and tests that referenced Default.
  • Regenerate client libraries and notify downstream teams of the field rename.
🤖 Prompt for AI Agents
In internal/api/client.gen.go around lines 117 to 121, the field `Default` was
renamed to `IsDefault` in the BaseDeploymentVariableValue struct, which is a
breaking change. To fix this, bump the API major version to indicate the
breaking change, update all client code, documentation, and tests to use
`IsDefault` instead of `Default`, regenerate client libraries, and notify
downstream teams about the rename to ensure compatibility.

@adityachoudhari26 adityachoudhari26 merged commit 5d075ea into main Jun 2, 2025
2 checks passed
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.

1 participant