Skip to content

Fix rad deploy resolving Radius.Core environment ID in the wrong group - #12599

Open
pujitha24 wants to merge 3 commits into
radius-project:mainfrom
pujitha24:auto/issue-12573
Open

Fix rad deploy resolving Radius.Core environment ID in the wrong group#12599
pujitha24 wants to merge 3 commits into
radius-project:mainfrom
pujitha24:auto/issue-12573

Conversation

@pujitha24

Copy link
Copy Markdown

Motivation:
When a workspace's default environment is stored as a full Radius.Core
resource ID (e.g. created via rad init in preview mode), running
rad deploy <template> -g <group> against a resource group other than
the environment's own group failed with "The environment ... does not
exist in scope ...", even though rad deploy --help and the rad group
command's own documentation state that an application's resources do
not have to live in the same resource group as the environment they
reference, and that passing a full environment ID is the documented way
to use an environment from a different group.

Approach:
FetchEnvironment in pkg/cli/cmd/deploy/deploy.go already handled this
correctly for Applications.Core environments (it passes the full ID
through to GetEnvironment, which extracts scope from the ID). The
Radius.Core branch instead discarded the full ID's own resource group
and re-queried using only the environment name against
r.Workspace.Scope (the --group-overridden scope), so a Radius.Core
environment could never be reused across resource groups. This change
brings the Radius.Core branch in line with the Applications.Core branch:
when the environment reference is a full resource ID, the lookup now
uses the scope encoded in that ID (envID.RootScope()) instead of the
deploy-time --group scope. The "environment does not exist" error
message in Validate() is also updated to report the scope that was
actually checked, instead of always reporting the --group scope,
which was misleading in this case.

Note: user-visible behavior for the common case (deploying into the
same group as the environment) is unchanged; this only affects
deployments that use -g/--group with an environment stored/passed
as a full Radius.Core resource ID belonging to a different group.

Validation:

  • go build ./...
  • go test ./pkg/cli/cmd/deploy/... ./pkg/cli/cmd/run/... -count=1 (both ok)
  • CGO_ENABLED=1 go test ./pkg/cli/cmd/... ./cmd/rad/... -timeout 600s
    (the command run by the documented make test-validate-cli target
    per docs/contributing/contributing-code/contributing-code-tests/README.md)
    — all packages pass
  • Added Test_FetchEnvironment_RadiusCoreEnvironmentUsesOwnGroup, which
    reproduces the reported failure with a fake Radius.Core environment
    server that 404s unless queried with the environment ID's own scope;
    confirmed this test fails against the pre-fix code and passes with
    the fix by temporarily reverting the scope-selection change and
    rerunning it.

Report: #12573
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com

Fixes #12573

@pujitha24
pujitha24 requested review from a team as code owners August 2, 2026 00:27
Copilot AI review requested due to automatic review settings August 2, 2026 00:27
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 2, 2026 00:27 — with GitHub Actions Waiting

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes rad deploy -g <group> incorrectly resolving a workspace default Radius.Core environment ID against the deploy-time --group scope instead of the scope encoded in the full environment resource ID, preventing reuse of environments across resource groups.

Changes:

  • Use envID.RootScope() when fetching Radius.Core environments referenced by full resource ID, aligning behavior with the existing Applications.Core lookup path.
  • Improve the “environment does not exist” validation error to report the scope that was actually checked (ID-encoded scope when a full ID is provided).
  • Add a regression test covering Radius.Core environment resolution across differing environment/deploy scopes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/cli/cmd/deploy/deploy.go Fixes Radius.Core environment lookup to use ID-encoded scope and improves the related validation error message.
pkg/cli/cmd/deploy/deploy_test.go Updates existing Radius.Core env tests for the new signature and adds a regression test for cross-group environment resolution.

Comment thread pkg/cli/cmd/deploy/deploy_test.go Outdated
Comment on lines +1892 to +1896
@@ -1893,7 +1893,7 @@ func Test_getRadiusCoreEnvironment(t *testing.T) {
},
}

env, err := runner.getRadiusCoreEnvironment(context.Background(), tc.environmentName)
env, err := runner.getRadiusCoreEnvironment(context.Background(), scope, tc.environmentName)
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.19%. Comparing base (88aa822) to head (b546353).

Files with missing lines Patch % Lines
pkg/cli/cmd/deploy/deploy.go 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12599      +/-   ##
==========================================
+ Coverage   54.17%   54.19%   +0.01%     
==========================================
  Files         770      770              
  Lines       51050    51055       +5     
==========================================
+ Hits        27656    27668      +12     
+ Misses      20789    20785       -4     
+ Partials     2605     2602       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lakshmimsft

Copy link
Copy Markdown
Contributor

Thank you for the submission. This issue is pending a discussion with the PMs. @willtsai , @zachcasper

@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 8, 2026 02:32 — with GitHub Actions Waiting
@pujitha24

Copy link
Copy Markdown
Author

Thanks for the update, @lakshmimsft — understood that this is pending discussion with the PMs, so I'll hold off on further changes here until that's resolved. In the meantime I addressed Copilot's review comment on Test_getRadiusCoreEnvironment (it was passing a full resource ID directly as the environmentName argument, which doesn't match how the real API or FetchEnvironment use it); the test now extracts scope/name from the ID first, matching production behavior. Happy to make further changes once there's guidance from the PM discussion.

@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 9, 2026 20:54 — with GitHub Actions Waiting
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 10, 2026 23:26 — with GitHub Actions Waiting
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 12, 2026 00:39 — with GitHub Actions Waiting
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 12, 2026 13:45 — with GitHub Actions Waiting
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 13, 2026 00:27 — with GitHub Actions Waiting
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 13, 2026 17:32 — with GitHub Actions Waiting
Motivation:
When a workspace's default environment is stored as a full Radius.Core
resource ID (e.g. created via `rad init` in preview mode), running
`rad deploy <template> -g <group>` against a resource group other than
the environment's own group failed with "The environment ... does not
exist in scope ...", even though `rad deploy --help` and the `rad group`
command's own documentation state that an application's resources do
not have to live in the same resource group as the environment they
reference, and that passing a full environment ID is the documented way
to use an environment from a different group.

Approach:
`FetchEnvironment` in pkg/cli/cmd/deploy/deploy.go already handled this
correctly for Applications.Core environments (it passes the full ID
through to GetEnvironment, which extracts scope from the ID). The
Radius.Core branch instead discarded the full ID's own resource group
and re-queried using only the environment name against
`r.Workspace.Scope` (the `--group`-overridden scope), so a Radius.Core
environment could never be reused across resource groups. This change
brings the Radius.Core branch in line with the Applications.Core branch:
when the environment reference is a full resource ID, the lookup now
uses the scope encoded in that ID (`envID.RootScope()`) instead of the
deploy-time `--group` scope. The "environment does not exist" error
message in Validate() is also updated to report the scope that was
actually checked, instead of always reporting the `--group` scope,
which was misleading in this case.

Note: user-visible behavior for the common case (deploying into the
same group as the environment) is unchanged; this only affects
deployments that use `-g`/`--group` with an environment stored/passed
as a full Radius.Core resource ID belonging to a different group.

Validation:
- go build ./...
- go test ./pkg/cli/cmd/deploy/... ./pkg/cli/cmd/run/... -count=1 (both ok)
- CGO_ENABLED=1 go test ./pkg/cli/cmd/... ./cmd/rad/... -timeout 600s
  (the command run by the documented `make test-validate-cli` target
  per docs/contributing/contributing-code/contributing-code-tests/README.md)
  — all packages pass
- Added Test_FetchEnvironment_RadiusCoreEnvironmentUsesOwnGroup, which
  reproduces the reported failure with a fake Radius.Core environment
  server that 404s unless queried with the environment ID's own scope;
  confirmed this test fails against the pre-fix code and passes with
  the fix by temporarily reverting the scope-selection change and
  rerunning it.

Report: radius-project#12573
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
…etRadiusCoreEnvironment

Test_getRadiusCoreEnvironment was passing a full Radius.Core resource ID
directly as the environmentName argument to getRadiusCoreEnvironment,
which doesn't reflect how the real EnvironmentsClient.Get API or the
production caller (FetchEnvironment) use it. Extract scope/name from the
ID before calling, matching FetchEnvironment's own envID.RootScope() /
envID.Name() usage, and update the expected environment name to the bare
name.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 14, 2026 01:31 — with GitHub Actions Waiting
@pujitha24
pujitha24 requested a deployment to external-contributor-approval August 14, 2026 21:27 — with GitHub Actions Waiting
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.

Recipe pack deploy with -g <group> resolves environment from default/workspace group and fails in target group

3 participants