-
Notifications
You must be signed in to change notification settings - Fork 99
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
support deployment of an application to a scope "scope1" using environment in a different scope "scope2" #7895
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7895 +/- ##
==========================================
- Coverage 60.98% 60.97% -0.02%
==========================================
Files 527 527
Lines 27844 27860 +16
==========================================
+ Hits 16982 16988 +6
- Misses 9367 9378 +11
+ Partials 1495 1494 -1 ☔ View full report in Codecov by Sentry. |
} else if environmentNameOrID == "" { | ||
return "", fmt.Errorf("no environment name or ID provided, pass in an environment name or ID") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that the workspace doesn't also have an environment? Should we add that to the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition where workspace is editable and not set with env is checked at https://github.com/nithyatsu/radius/blob/1577a407a7079c53d56090882de2b74ceb2e99b8/pkg/cli/clivalidation.go#L120
This is because some of the cli code has the ability to make a fall back workspace to get to the server side (this just injects kubectx = default kubernetes context) and continue to work if config.yaml is not found. If this is the workspace we are dealing with, it is not editable. Then we cannot set env. L120 is the more common case.
// DidSpecifyEnvironmentName checks if an environment name is provided as a flag | ||
func DidSpecifyEnvironmentName(cmd *cobra.Command, args []string) bool { | ||
environmentName, err := cmd.Flags().GetString("environment") | ||
return err == nil && environmentName != "" | ||
return err == nil && environmentName != "" && !strings.HasPrefix(environmentName, resources.SegmentSeparator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this apply to both just the environment name and also the resource id for the environment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it checks only for environment name. Since now we might be dealing with an id, it is updated to make sure we dont have the SegmentSeperator character that suggests this is an id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need DidSpecifyEnvironmentID
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there wasn't necessity for it.
# deploy using an environment ID and a resource group. The application will be deployed in mygroup scope, using the specified environment. | ||
# use this option if the environment is in a different group. | ||
rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod --group mygroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we be able to pass in just a name? It says here like that: https://github.com/radius-project/radius/pull/7895/files#diff-bf4e917446c73565ee6967f28bdd8e619c0d4fa40b215f195b840c021dd36ce9R104.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can still pass a name. In that case, the current group is searched for the environment (like before). But if we want to use an environment in a different group, then we would have to specify the ID so that we know the group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the resource group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also just do rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in the example the resource group in the environment ID is different than the resource group that is passed via a flag.
We should be more specific in these examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod --group mygroup
This command deploys the application to group mygroup
using environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod
in the prod
group.
--group flag existed already and specifies the group to which the application should be deployed to. There wasnt any ability to use an environment from another group though. But if we think about it, environments contain information used for deploying apps, and user should be able to use environments from any group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, its OK to specify the --group value to be same group as in env ID. But in this case, name would be enough.
pkg/cli/cmd/deploy/deploy.go
Outdated
if err != nil { | ||
// If the error is not a 404, return it | ||
if !clients.Is404Error(err) { | ||
return err | ||
} | ||
|
||
// If the environment doesn't exist, but the user specified it as | ||
// If the environment doesn't exist, but the user specified it's name as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// If the environment doesn't exist, but the user specified it's name as | |
// If the environment doesn't exist, but the user specified its name or resource id as |
@@ -53,7 +54,7 @@ func Test_Validate(t *testing.T) { | |||
}, | |||
ConfigureMocks: func(mocks radcli.ValidateMocks) { | |||
mocks.ApplicationManagementClient.EXPECT(). | |||
GetEnvironment(gomock.Any(), radcli.TestEnvironmentName). | |||
GetEnvironment(gomock.Any(), "/planes/radius/local/resourceGroups/test-resource-group/providers/Applications.Core/environments/test-environment"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have another test just with the name instead of the resource id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not add it since most of the tests use a name and not ID for testing.. I will add one excplicitly for the name and rename this too to indicate the improtance of retaining the ID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I just noticed I covered it. They are "rad deploy - valid with environment" and "rad deploy - valid with env ID".
Radius functional test overview
Click here to see the list of tools in the current test run
Test Status⌛ Building Radius and pushing container images for functional tests... |
Radius functional test overview
Click here to see the list of tools in the current test run
Test Status⌛ Building Radius and pushing container images for functional tests... |
Signed-off-by: nithyatsu <[email protected]>
Signed-off-by: nithyatsu <[email protected]>
Signed-off-by: nithyatsu <[email protected]>
Radius functional test overview
Click here to see the list of tools in the current test run
Test Status⌛ Building Radius and pushing container images for functional tests... |
// DidSpecifyEnvironmentName checks if an environment name is provided as a flag | ||
func DidSpecifyEnvironmentName(cmd *cobra.Command, args []string) bool { | ||
environmentName, err := cmd.Flags().GetString("environment") | ||
return err == nil && environmentName != "" | ||
return err == nil && environmentName != "" && !strings.HasPrefix(environmentName, resources.SegmentSeparator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need DidSpecifyEnvironmentID
?
# deploy using an environment ID and a resource group. The application will be deployed in mygroup scope, using the specified environment. | ||
# use this option if the environment is in a different group. | ||
rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod --group mygroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the resource group?
# deploy using an environment ID and a resource group. The application will be deployed in mygroup scope, using the specified environment. | ||
# use this option if the environment is in a different group. | ||
rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod --group mygroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also just do rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod
?
# deploy using an environment ID and a resource group. The application will be deployed in mygroup scope, using the specified environment. | ||
# use this option if the environment is in a different group. | ||
rad deploy myapp.bicep --environment /planes/radius/local/resourcegroups/prod/providers/Applications.Core/environments/prod --group mygroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, in the example the resource group in the environment ID is different than the resource group that is passed via a flag.
We should be more specific in these examples.
// a command-line option, return an error | ||
if cli.DidSpecifyEnvironmentName(cmd, args) { | ||
return clierrors.Message("The environment %q does not exist in scope %q. Run `rad env create` first.", r.EnvironmentName, r.Workspace.Scope) | ||
return clierrors.Message("The environment %q does not exist in scope %q. Run `rad env create` first. You could also provide the environment ID if the environment exists in a different group.", r.EnvironmentNameOrID, r.Workspace.Scope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we only provide an environmentID when we are deploying to another group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. If not, it will enter the codeblock if cli.DidSpecifyEnvironmentName
and print the error message indicating the environment isnt found in group and we should specify the id if it exists in a different group.
Description
Today, rad deploy can use only the environments that are in same scope as where the application is being deployed to (either default scope or one specified by -g).
It should be able to use environments in different groups to deploy application.
Type of change
Fixes: rad deploy should be able to use environments in different groups to deploy application #7520