Skip to content
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

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

nithyatsu
Copy link
Contributor

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

@nithyatsu nithyatsu changed the title Cli bug support deployment of an application to a scope "scope1" using environment in a different scope "scope2" Sep 7, 2024
Copy link

codecov bot commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 48.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 60.97%. Comparing base (3d2825f) to head (e7c96e7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cli/clivalidation.go 0.00% 13 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@nithyatsu nithyatsu marked this pull request as ready for review September 9, 2024 16:25
@nithyatsu nithyatsu requested review from a team as code owners September 9, 2024 16:25
Comment on lines +121 to +123
} else if environmentNameOrID == "" {
return "", fmt.Errorf("no environment name or ID provided, pass in an environment name or ID")
}
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need DidSpecifyEnvironmentID?

Copy link
Contributor Author

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.

Comment on lines +90 to +92
# 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@nithyatsu nithyatsu Sep 10, 2024

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.

Copy link
Contributor Author

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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").
Copy link
Contributor

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?

Copy link
Contributor Author

@nithyatsu nithyatsu Sep 9, 2024

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

Copy link
Contributor Author

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-tests
Copy link

radius-functional-tests bot commented Sep 9, 2024

Radius functional test overview

🔍 Go to test action run

Name Value
Repository nithyatsu/radius
Commit ref 1577a40
Unique ID func8bc958b73d
Image tag pr-func8bc958b73d
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr: 1.12.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-func8bc958b73d
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-func8bc958b73d
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func8bc958b73d
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func8bc958b73d
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting datastoresrp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ datastoresrp-cloud functional tests succeeded
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@radius-functional-tests
Copy link

radius-functional-tests bot commented Sep 9, 2024

Radius functional test overview

🔍 Go to test action run

Name Value
Repository nithyatsu/radius
Commit ref aee1cca
Unique ID funcb5ac373a4c
Image tag pr-funcb5ac373a4c
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr: 1.12.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-funcb5ac373a4c
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-funcb5ac373a4c
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funcb5ac373a4c
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funcb5ac373a4c
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting datastoresrp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
✅ datastoresrp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded
✅ ucp-cloud functional tests succeeded

@radius-functional-tests
Copy link

radius-functional-tests bot commented Sep 10, 2024

Radius functional test overview

🔍 Go to test action run

Name Value
Repository nithyatsu/radius
Commit ref e7c96e7
Unique ID func7dc83fa36e
Image tag pr-func7dc83fa36e
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr: 1.12.0
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-func7dc83fa36e
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-func7dc83fa36e
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func7dc83fa36e
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func7dc83fa36e
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
⌛ Starting datastoresrp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded
✅ datastoresrp-cloud functional tests succeeded

// 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need DidSpecifyEnvironmentID?

Comment on lines +90 to +92
# 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
Copy link
Contributor

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?

Comment on lines +90 to +92
# 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
Copy link
Contributor

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?

Comment on lines +90 to +92
# 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
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor Author

@nithyatsu nithyatsu Sep 10, 2024

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.

@nithyatsu nithyatsu merged commit 897f2aa into radius-project:main Sep 10, 2024
28 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.

rad deploy should be able to use environments in different groups to deploy application
2 participants