Skip to content

fix: call regular resource upsert endpoint when no provider is specified#66

Merged
adityachoudhari26 merged 3 commits intomainfrom
claude/issue-64-20260327-2010
Mar 27, 2026
Merged

fix: call regular resource upsert endpoint when no provider is specified#66
adityachoudhari26 merged 3 commits intomainfrom
claude/issue-64-20260327-2010

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Mar 27, 2026

When ctrlc apply is run without a --provider flag and a resource YAML does not have a provider field, the CLI now calls PATCH /v1/workspaces/{workspaceId}/resources/identifier/{identifier} directly instead of creating/reusing a default "ctrlc-apply" provider.

Fixes #64

Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Deployment planning capabilities with status tracking and targeting support.
    • Resource endpoints for direct management without provider assignment.
    • Workflow execution functionality with run creation support.
    • Resource provider endpoints for resource listing and removal.
  • Refactor

    • Simplified selector and CEL modeling across API request/response structures.

When `ctrlc apply` is run without a `--provider` flag and a resource YAML
does not have a `provider` field set, the CLI now calls
`PATCH /v1/workspaces/{workspaceId}/resources/identifier/{identifier}`
directly instead of creating/reusing a default "ctrlc-apply" provider.

Changes:
- `--provider` flag default changed from "ctrlc-apply" to "" so that
  the absence of a provider is detectable
- Resources without a provider skip the SetResourceProviderResources path
  and are upserted individually via the new UpsertResourceByIdentifier helper
- Provider is only assigned from the CLI flag when the flag is explicitly set

Fixes #64

Co-authored-by: Aditya Choudhari <adityachoudhari26@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

This PR removes the default "ctrlc-apply" provider fallback when no --provider flag is specified. Resources without a provider are now upserted directly via a dedicated endpoint, while provider-flagged resources continue batch processing per provider. The PR also introduces new API deployment-plan types, replaces union-based selector/CEL modeling with plain string fields, and adds supporting client endpoints.

Changes

Cohort / File(s) Summary
Apply Command Provider Logic
cmd/ctrlc/root/apply/cmd.go
Updated --provider flag default from "ctrlc-apply" to empty string; modified resource spec preparation to conditionally assign provider only when flag is non-empty; adjusted debug logging to reflect conditional provider assignment.
API Client Generation
internal/api/client.gen.go
Added deployment-plan domain types (DeploymentPlan, DeploymentPlanStatus, DeploymentPlanSummary, etc.); replaced union-based selector/CEL models with plain string fields across multiple request/response models; added new client methods for deployment plans, resource providers, resource upsert, and workflow execution; removed legacy selector union helper structs and methods.
Resource Provider Batching
internal/api/providers/resource.go
Split resource batching logic to handle provider-less resources separately via new upsertWithoutProvider method; provider-assigned resources continue existing batch-per-provider processing; removed default provider assignment for empty-provider specs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • zacharyblasczyk

Poem

🐰 A rabbit hops through provider fields,
No defaults block what upsert yields,
Direct endpoints dance so free,
CEL strings replace complexity!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The generated API client changes (internal/api/client.gen.go) are out of scope; they appear to be auto-generated code unrelated to issue #64's specific requirements. Exclude auto-generated API client changes from this PR and create a separate PR for API schema updates that necessitate those generated changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: switching to the regular resource upsert endpoint when no provider is specified, which is the core fix implemented.
Linked Issues check ✅ Passed All coding objectives from issue #64 are met: the default provider flag is removed, resources without a provider use the regular upsert endpoint, and provider-flag behavior is preserved.
Docstring Coverage ✅ Passed Docstring coverage is 97.22% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-64-20260327-2010

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 and usage tips.

@adityachoudhari26 adityachoudhari26 marked this pull request as ready for review March 27, 2026 20:43
Copy link
Copy Markdown
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.

Caution

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

⚠️ Outside diff range comments (1)
internal/api/client.gen.go (1)

7244-7284: ⚠️ Potential issue | 🔴 Critical

Use PATCH for UpsertResourceByIdentifier.

Line 7276 still builds a PUT request, but issue #64 requires PATCH /v1/workspaces/{workspaceId}/resources/identifier/{identifier} for the no-provider path. That means every UpsertResourceByIdentifier* wrapper will hit the wrong route/semantics, which can 405 or turn the intended additive patch into replacement behavior. Since this file is generated, please fix the OpenAPI operation and regenerate the client.

Expected generated output after fixing the spec
- req, err := http.NewRequest("PUT", queryURL.String(), body)
+ req, err := http.NewRequest("PATCH", queryURL.String(), body)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/api/client.gen.go` around lines 7244 - 7284, The generated client is
creating a PUT request in NewUpsertResourceByIdentifierRequestWithBody
(http.NewRequest("PUT", ...)) but the OpenAPI spec requires PATCH for the
upsert-by-identifier no-provider path; update the OpenAPI operation for the
/v1/workspaces/{workspaceId}/resources/identifier/{identifier} endpoint to use
the PATCH HTTP method (or directly change the operationId/method mapping) and
then regenerate the client so NewUpsertResourceByIdentifierRequestWithBody (and
all UpsertResourceByIdentifier* wrappers) use "PATCH" instead of "PUT".
🧹 Nitpick comments (1)
internal/api/providers/resource.go (1)

130-134: Remove the "ctrlc-apply" fallback in getProviderID() for consistency.

The method still falls back to "ctrlc-apply" when Provider is empty. However, BatchUpsertResources() (lines 163–178) explicitly separates empty-provider resources and routes them to upsertWithoutProvider(), which bypasses providers entirely. This creates two inconsistent code paths for the same input:

  • Single-resource path (Create/Update via framework.go): Empty provider → fallback to "ctrlc-apply"
  • Batch path (BatchUpsertResources): Empty provider → upsertWithoutProvider (no provider)

Either remove the fallback and require a provider, or add a comment explaining that this legacy behavior is not used by the batch flow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/api/providers/resource.go` around lines 130 - 134, Remove the
hardcoded "ctrlc-apply" fallback in getProviderID so empty r.Provider is treated
as missing; update getProviderID (in ResourceItemSpec) to return an error when
Provider is empty instead of returning "ctrlc-apply", and ensure the callers
(including any code paths used by Create/Update) surface that error; this makes
behavior consistent with BatchUpsertResources which routes empty-provider
resources to upsertWithoutProvider (see BatchUpsertResources and
upsertWithoutProvider for the intended path).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@internal/api/client.gen.go`:
- Around line 7244-7284: The generated client is creating a PUT request in
NewUpsertResourceByIdentifierRequestWithBody (http.NewRequest("PUT", ...)) but
the OpenAPI spec requires PATCH for the upsert-by-identifier no-provider path;
update the OpenAPI operation for the
/v1/workspaces/{workspaceId}/resources/identifier/{identifier} endpoint to use
the PATCH HTTP method (or directly change the operationId/method mapping) and
then regenerate the client so NewUpsertResourceByIdentifierRequestWithBody (and
all UpsertResourceByIdentifier* wrappers) use "PATCH" instead of "PUT".

---

Nitpick comments:
In `@internal/api/providers/resource.go`:
- Around line 130-134: Remove the hardcoded "ctrlc-apply" fallback in
getProviderID so empty r.Provider is treated as missing; update getProviderID
(in ResourceItemSpec) to return an error when Provider is empty instead of
returning "ctrlc-apply", and ensure the callers (including any code paths used
by Create/Update) surface that error; this makes behavior consistent with
BatchUpsertResources which routes empty-provider resources to
upsertWithoutProvider (see BatchUpsertResources and upsertWithoutProvider for
the intended path).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 98e3d525-0318-4524-ba88-d3da7d6e5a92

📥 Commits

Reviewing files that changed from the base of the PR and between d6d2881 and 76d5962.

📒 Files selected for processing (3)
  • cmd/ctrlc/root/apply/cmd.go
  • internal/api/client.gen.go
  • internal/api/providers/resource.go

@adityachoudhari26 adityachoudhari26 merged commit 20021c3 into main Mar 27, 2026
7 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.

ctrlc apply w/ no provider should call regular resource upsert endpoint

1 participant