feat: configure env version rollout cli#34
Conversation
WalkthroughThis update introduces support for environment version rollout strategies in policy management. It adds new data structures, API client methods, and CLI flag handling to enable specifying rollout parameters when creating or updating policies. Additionally, the API client gains methods for environment-specific deployment version approvals/rejections and release target locking, with corresponding request/response types. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant API Client
participant Server
User->>CLI: upsert-policy --environment-version-rollout '{...}'
CLI->>CLI: parseEnvironmentVersionRollout(JSON)
CLI->>API Client: UpsertPolicy(EnvironmentVersionRollout)
API Client->>Server: POST /v1/policies (with rollout params)
Server-->>API Client: Policy upsert response
API Client-->>CLI: Response
CLI-->>User: Display result
sequenceDiagram
participant User
participant CLI
participant API Client
participant Server
User->>CLI: apply policy (with EnvironmentVersionRollout)
CLI->>API Client: UpsertPolicy(EnvironmentVersionRollout)
API Client->>Server: POST /v1/policies (with rollout params)
Server-->>API Client: Response
API Client-->>CLI: Result
CLI-->>User: Output
sequenceDiagram
participant User
participant API Client
participant Server
User->>API Client: ApproveDeploymentVersionForEnvironment
API Client->>Server: POST /v1/deployment-versions/{id}/environments/{id}/approve
Server-->>API Client: Approval response
User->>API Client: LockReleaseTarget
API Client->>Server: POST /v1/release-targets/{id}/lock
Server-->>API Client: Lock response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
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. 🪧 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
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
cmd/ctrlc/root/api/upsert/policy/policy.go(5 hunks)cmd/ctrlc/root/apply/policy.go(2 hunks)cmd/ctrlc/root/apply/types.go(2 hunks)internal/api/client.gen.go(36 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
cmd/ctrlc/root/apply/types.go (1)
internal/api/client.gen.go (1)
EnvironmentVersionRollout(348-357)
cmd/ctrlc/root/api/upsert/policy/policy.go (2)
internal/api/client.gen.go (3)
InsertEnvironmentVersionRollout(383-392)InsertEnvironmentVersionRolloutRolloutType(395-395)EnvironmentVersionRollout(348-357)cmd/ctrlc/root/apply/types.go (1)
EnvironmentVersionRollout(166-170)
internal/api/client.gen.go (1)
cmd/ctrlc/root/apply/types.go (6)
DeploymentVersionSelector(147-151)EnvironmentVersionRollout(166-170)PolicyTarget(135-139)VersionAnyApproval(153-155)VersionRoleApproval(161-164)VersionUserApproval(157-159)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: docker (linux/amd64)
🔇 Additional comments (8)
cmd/ctrlc/root/apply/types.go (1)
132-132: LGTM! Well-structured type definitions.The addition of the
EnvironmentVersionRolloutfield to thePolicystruct and the new struct definition follow Go conventions correctly, with optional fields using pointers and required fields using concrete types.Also applies to: 166-170
cmd/ctrlc/root/apply/policy.go (1)
122-135: LGTM! Proper type conversion logic.The conversion from internal
EnvironmentVersionRolloutto APIInsertEnvironmentVersionRolloutis handled correctly, with proper nil checking for optional fields and appropriate type casting for the enum type.Also applies to: 150-150
internal/api/client.gen.go (6)
39-52: Rollout type constants look good.The duplicate constants for
EnvironmentVersionRolloutRolloutTypeandInsertEnvironmentVersionRolloutRolloutTypefollow the established pattern for generated API clients, maintaining type safety between read and write operations.
97-97: Status additions are consistent.The addition of "rejected" status to deployment and release types, along with the
EnvironmentIdfield inApprovalRecord, properly supports the new environment-specific approval/rejection functionality.Also applies to: 105-105, 113-113, 121-121, 129-129
382-396: InsertEnvironmentVersionRollout struct is well-structured.The struct properly defines rollout configuration with clear documentation, appropriate use of pointers for optional fields, and correct JSON tags.
472-474: MaxRetries field implementation is correct.The use of non-pointer
MaxRetriesin thePolicystruct (line 488) and pointer*MaxRetriesin request bodies (lines 983, 1005) correctly distinguishes between required response fields and optional request fields.Also applies to: 488-488, 983-983, 1005-1005
615-627: ReleaseTargetLockRecord struct properly models lock state.The struct correctly tracks lock information with appropriate use of timestamps and an optional
UnlockedAtfield for active locks.
872-887: API client methods are properly implemented.All new client methods, request builders, response types, and parsers follow the established patterns in the generated code. The implementation correctly handles:
- Environment-specific deployment version approvals/rejections
- Release target locking/unlocking
- Proper HTTP methods and URL construction
- Comprehensive error response handling
Also applies to: 1175-1183, 2450-2467, 2574-2582, 2801-2883, 3353-3387, 4077-4272, 5333-5434, 6637-6654, 6761-6769, 7031-7158, 7956-8049, 8961-9020, 9361-9387, 9974-10183, 11366-11513
| cmd.Flags().StringVar(&resourceTargetSelector, "resource-selector", "", "JSON string for resource target selector") | ||
| cmd.Flags().IntVarP(&concurrency, "concurrency", "c", 0, "Concurrency of the policy") | ||
| cmd.Flags().StringVar(&deploymentVersionSelector, "version-selector", "", "JSON string for version selector") | ||
| cmd.Flags().StringVar(&environmentVersionRollout, "environment-version-rollout", "", "JSON string for environment version rollout") |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add usage example for the new CLI flag.
The new --environment-version-rollout flag lacks documentation and examples, making it difficult for users to understand the expected JSON format.
Consider adding an example to the command's usage documentation around lines 75-90:
# Upsert a policy with version approvals
$ ctrlc api upsert policy --name my-policy --version-any-approvals '{"requiredApprovalsCount": 2}' --version-user-approvals '[{"userId": "user1"}, {"userId": "user2"}]' --version-role-approvals '[{"roleId": "role1", "requiredApprovalsCount": 1}]'
+
+ # Upsert a policy with environment version rollout
+ $ ctrlc api upsert policy --name my-policy --environment-version-rollout '{"timeScaleInterval": 300.0, "rolloutType": "linear", "positionGrowthFactor": 1.5}'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| cmd.Flags().StringVar(&environmentVersionRollout, "environment-version-rollout", "", "JSON string for environment version rollout") | |
| # Upsert a policy with version approvals | |
| $ ctrlc api upsert policy --name my-policy --version-any-approvals '{"requiredApprovalsCount": 2}' --version-user-approvals '[{"userId": "user1"}, {"userId": "user2"}]' --version-role-approvals '[{"roleId": "role1", "requiredApprovalsCount": 1}]' | |
| # Upsert a policy with environment version rollout | |
| $ ctrlc api upsert policy --name my-policy --environment-version-rollout '{"timeScaleInterval": 300.0, "rolloutType": "linear", "positionGrowthFactor": 1.5}' |
🤖 Prompt for AI Agents
In cmd/ctrlc/root/api/upsert/policy/policy.go around lines 75 to 90, add a usage
example for the new --environment-version-rollout CLI flag in the command's
usage documentation. Include a clear example JSON string showing the expected
format to help users understand how to use this flag correctly.
Summary by CodeRabbit
New Features
Enhancements