-
Notifications
You must be signed in to change notification settings - Fork 132
add workspace create --preview #11905
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
Open
nithyatsu
wants to merge
4
commits into
radius-project:main
Choose a base branch
from
nithyatsu:radcorews
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| Copyright 2023 The Radius Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| // Package preview implements the `rad workspace create --preview` command. It reuses | ||
| // the runner from the parent create package and only overrides the environment | ||
| // validation step so that the workspace is bound to a Radius.Core/environments | ||
| // resource (v20250801preview) instead of an Applications.Core/environments resource. | ||
| package preview | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/radius-project/radius/pkg/cli/clients" | ||
| "github.com/radius-project/radius/pkg/cli/clierrors" | ||
| "github.com/radius-project/radius/pkg/cli/cmd" | ||
| "github.com/radius-project/radius/pkg/cli/cmd/commonflags" | ||
| workspace_create "github.com/radius-project/radius/pkg/cli/cmd/workspace/create" | ||
| "github.com/radius-project/radius/pkg/cli/framework" | ||
| "github.com/radius-project/radius/pkg/cli/workspaces" | ||
| corerpv20250801 "github.com/radius-project/radius/pkg/corerp/api/v20250801preview" | ||
| "github.com/radius-project/radius/pkg/corerp/datamodel" | ||
| ) | ||
|
|
||
| // NewCommand creates an instance of the command and runner for the `rad workspace create --preview` command. | ||
| // | ||
| // The preview command behaves identically to `rad workspace create`, but binds the workspace | ||
| // to a Radius.Core/environments resource (v20250801preview) instead of an | ||
| // Applications.Core/environments resource. | ||
| func NewCommand(factory framework.Factory) (*cobra.Command, framework.Runner) { | ||
| runner := NewRunner(factory) | ||
|
|
||
| c := &cobra.Command{ | ||
| Use: "create [workspaceType] [workspaceName]", | ||
| Short: "Create a workspace (preview)", | ||
| Long: `Create a workspace bound to a Radius.Core (preview) environment. | ||
|
|
||
| Available workspaceTypes: kubernetes | ||
|
|
||
| Workspaces allow you to manage multiple Radius platforms and environments using a local configuration file. | ||
|
|
||
| Use this command together with environments created via 'rad env create --preview'.`, | ||
| Args: workspace_create.ValidateArgs(), | ||
| Example: ` | ||
| # Create a workspace bound to a Radius.Core (preview) environment | ||
| rad workspace create kubernetes my-workspace --group my-grp --environment my-env --preview | ||
|
|
||
| # Create a workspace using the current kubernetes context as the workspace name | ||
| rad workspace create kubernetes --preview`, | ||
| RunE: framework.RunCommand(runner), | ||
| } | ||
|
|
||
| commonflags.AddWorkspaceFlag(c) | ||
| commonflags.AddResourceGroupFlag(c) | ||
| commonflags.AddEnvironmentNameFlag(c) | ||
| c.Flags().BoolP("force", "f", false, "Overwrite existing workspace if present") | ||
| c.Flags().StringP("context", "c", "", "the Kubernetes context to use, will use the default if unset") | ||
|
|
||
| return c, runner | ||
| } | ||
|
|
||
| // Runner is the runner implementation for the `rad workspace create --preview` command. | ||
| // | ||
| // It embeds the legacy create.Runner and overrides only the environment validation | ||
| // step. All other workspace-creation behaviour (kube context, install check, group | ||
| // lookup, persistence) is inherited unchanged. | ||
| type Runner struct { | ||
| *workspace_create.Runner | ||
|
|
||
| // RadiusCoreClientFactory validates the Radius.Core/environments resource. When nil, | ||
| // it is initialized lazily from the workspace connection. Tests may pre-populate it. | ||
| RadiusCoreClientFactory *corerpv20250801.ClientFactory | ||
| } | ||
|
|
||
| // NewRunner creates a new instance of the `rad workspace create --preview` runner. | ||
| func NewRunner(factory framework.Factory) *Runner { | ||
| base := workspace_create.NewRunner(factory) | ||
| r := &Runner{Runner: base} | ||
| base.EnvironmentValidator = r.validateRadiusCoreEnvironment | ||
| return r | ||
| } | ||
|
|
||
| // validateRadiusCoreEnvironment validates that the Radius.Core/environments resource | ||
| // exists in the workspace scope and returns its fully-qualified resource ID. | ||
| func (r *Runner) validateRadiusCoreEnvironment(ctx context.Context, ws *workspaces.Workspace, _ clients.ApplicationsManagementClient, envName string) (string, error) { | ||
| envID := ws.Scope + "/providers/" + datamodel.EnvironmentResourceType_v20250801preview + "/" + envName | ||
|
|
||
| if r.RadiusCoreClientFactory == nil { | ||
| clientFactory, err := cmd.InitializeRadiusCoreClientFactory(ctx, ws, ws.Scope) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| r.RadiusCoreClientFactory = clientFactory | ||
| } | ||
|
|
||
| if _, err := r.RadiusCoreClientFactory.NewEnvironmentsClient().Get(ctx, envName, nil); err != nil { | ||
| if clients.Is404Error(err) { | ||
| return "", clierrors.Message("The environment %q does not exist. Run `rad env create --preview` and try again.", envID) | ||
| } | ||
| return "", clierrors.MessageWithCause(err, "Failed to get environment %q.", envID) | ||
| } | ||
|
Comment on lines
+110
to
+115
|
||
| return envID, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.