Skip to content

Refactor pkg/cli/helm and add unit tests #9166

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

Merged
merged 12 commits into from
May 19, 2025
Merged

Conversation

ytimocin
Copy link
Contributor

@ytimocin ytimocin commented Apr 11, 2025

Description

Overview

the pkg/cli/helm package has been part of the Radius project since the beginning of the project (~4yrs ago). This package has been left mostly un-unit tested and has been the source of a few bugs in the past. As part of the Radius upgrades features, we will be adding code here, so I decided to refactor this package to add unit tests and improve code clarity.

Copilot-generated summary

This pull request introduces significant refactoring and enhancements to the Helm integration for managing Radius and its dependencies (e.g., Contour) in Kubernetes. The changes include the introduction of a new Helm interface, improved error handling, and updates to test cases to align with the new implementation. Below is a summary of the most important changes grouped by theme.

Helm Interface Enhancements:

  • Introduced a new Helm.Interface abstraction to encapsulate Helm operations such as InstallRadius, UninstallRadius, UpgradeRadius, and CheckRadiusInstall. This improves modularity and testability.
  • Implemented a concrete Helm.Impl struct that uses a Helm client to perform the actual operations, replacing direct function calls to Helm utilities.

Refactoring of Installation and Uninstallation Logic:

  • Replaced the old installRadius function with a new InstallRadius method in the Helm.Interface. The new method applies both Radius and Contour Helm charts with enhanced error handling. [1] [2]
  • Simplified the UninstallRadius logic by delegating it to the new Helm.Interface, making the code cleaner and more maintainable. [1] [2]

Updates to Default Cluster Options:

  • Updated the ClusterOptions struct to separate RadiusChartOptions and ContourChartOptions, making the configuration more explicit. Added default values for new fields such as Wait and HostNetwork.
  • Enhanced the PopulateDefaultClusterOptions function to support overriding the ChartVersion for Radius.

Test Case Adjustments:

  • Updated test cases in kubernetes_test.go and init_test.go to reflect the new InstallRadius and UninstallRadius method signatures. Removed the return value from InstallRadius and adjusted expectations accordingly. [1] [2] [3]

Code Cleanup:

  • Removed unused constants and functions, such as ContourChartDefaultVersion and queryRelease, as they were replaced by the new Helm interface methods. [1] [2]

Type of change

  • This pull request adds or changes features of Radius and has an approved issue (issue link required).

Contributor checklist

Please verify that the PR meets the following requirements, where applicable:

  • An overview of proposed schema changes is included in a linked GitHub issue.
    • Yes
    • Not applicable
  • A design document PR is created in the design-notes repository, if new APIs are being introduced.
    • Yes
    • Not applicable
  • The design document has been reviewed and approved by Radius maintainers/approvers.
    • Yes
    • Not applicable
  • A PR for the samples repository is created, if existing samples are affected by the changes in this PR.
    • Yes
    • Not applicable
  • A PR for the documentation repository is created, if the changes in this PR affect the documentation or any user facing updates are made.
    • Yes
    • Not applicable
  • A PR for the recipes repository is created, if existing recipes are affected by the changes in this PR.
    • Yes
    • Not applicable

@ytimocin ytimocin requested review from a team as code owners April 11, 2025 21:54
@ytimocin ytimocin changed the base branch from features/upgrade/v1 to features/upgrade-v1 April 11, 2025 22:01
@ytimocin ytimocin force-pushed the ytimocin/upgrade/clients branch from 6676432 to 8fd7152 Compare April 11, 2025 22:02
@ytimocin ytimocin temporarily deployed to functional-tests April 11, 2025 22:02 — with GitHub Actions Inactive
@radius-functional-tests
Copy link

radius-functional-tests bot commented Apr 11, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 8fd7152
Unique ID func7b8ed36336
Image tag pr-func7b8ed36336
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-func7b8ed36336
  • 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-func7b8ed36336
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func7b8ed36336
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func7b8ed36336
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func7b8ed36336
  • 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 ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@ytimocin ytimocin force-pushed the ytimocin/upgrade/clients branch from 8fd7152 to 20d15a7 Compare April 11, 2025 22:09
@ytimocin ytimocin temporarily deployed to functional-tests April 11, 2025 22:10 — with GitHub Actions Inactive
Copy link

github-actions bot commented Apr 11, 2025

Unit Tests

3 734 tests  +8   3 731 ✅ +7   6m 32s ⏱️ -7s
  297 suites ±0       3 💤 +1 
    1 files   ±0       0 ❌ ±0 

Results for commit 5bff917. ± Comparison against base commit 140fe93.

This pull request removes 3 and adds 11 tests. Note that renamed tests count towards both.
github.com/radius-project/radius/pkg/cli/helm ‑ Test_AddValues
github.com/radius-project/radius/pkg/cli/helm ‑ Test_CanSetCLIOptions
github.com/radius-project/radius/pkg/cli/helm ‑ Test_isHelm403Error
github.com/radius-project/radius/pkg/cli/helm ‑ TestAddContourValues_HostNetworkDisabled_NoChange
github.com/radius-project/radius/pkg/cli/helm ‑ TestAddContourValues_HostNetworkEnabled
github.com/radius-project/radius/pkg/cli/helm ‑ Test_Helm_CheckRadiusInstall
github.com/radius-project/radius/pkg/cli/helm ‑ Test_Helm_CheckRadiusInstall_ErrorOnQuery
github.com/radius-project/radius/pkg/cli/helm ‑ Test_Helm_InstallRadius
github.com/radius-project/radius/pkg/cli/helm ‑ Test_Helm_UninstallRadius
github.com/radius-project/radius/pkg/cli/helm ‑ Test_Helm_UninstallRadius_ReleaseNotFound
github.com/radius-project/radius/pkg/cli/helm ‑ Test_Helm_UpgradeRadius
github.com/radius-project/radius/pkg/cli/helm ‑ Test_PopulateDefaultClusterOptions
github.com/radius-project/radius/pkg/cli/helm ‑ Test_addArgsFromCLI
…

♻️ This comment has been updated with latest results.

@radius-functional-tests
Copy link

radius-functional-tests bot commented Apr 12, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 20d15a7
Unique ID func3b4fcb1146
Image tag pr-func3b4fcb1146
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-func3b4fcb1146
  • 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-func3b4fcb1146
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func3b4fcb1146
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func3b4fcb1146
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func3b4fcb1146
  • 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...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

Copy link

codecov bot commented Apr 12, 2025

Codecov Report

Attention: Patch coverage is 51.95822% with 184 lines in your changes missing coverage. Please review.

Project coverage is 56.35%. Comparing base (140fe93) to head (5bff917).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cli/helm/helmaction.go 59.18% 46 Missing and 14 partials ⚠️
pkg/cli/helm/cluster.go 53.19% 39 Missing and 5 partials ⚠️
pkg/cli/helm/helmclient.go 0.00% 35 Missing ⚠️
pkg/cli/helm/contour.go 55.55% 16 Missing and 8 partials ⚠️
pkg/cli/helm/radius.go 55.31% 14 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9166      +/-   ##
==========================================
+ Coverage   55.92%   56.35%   +0.42%     
==========================================
  Files         604      605       +1     
  Lines       41467    41495      +28     
==========================================
+ Hits        23192    23386     +194     
+ Misses      16500    16308     -192     
- Partials     1775     1801      +26     

☔ View full report in Codecov by Sentry.
📢 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.

Signed-off-by: willdavsmith <[email protected]>
Signed-off-by: willdavsmith <[email protected]>
Signed-off-by: willdavsmith <[email protected]>
Signed-off-by: willdavsmith <[email protected]>
@radius-functional-tests

This comment has been minimized.

@radius-functional-tests
Copy link

radius-functional-tests bot commented Apr 22, 2025

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
❌ Failed to install Radius for ucp-cloud functional test. Please check the logs for more details
❌ ucp-cloud functional test failed. Please check the logs for more details
❌ Failed to install Radius for corerp-cloud functional test. Please check the logs for more details
❌ corerp-cloud functional test failed. Please check the logs for more details

@radius-functional-tests
Copy link

radius-functional-tests bot commented May 8, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 999f0d4
Unique ID func072e0cb299
Image tag pr-func072e0cb299
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-func072e0cb299
  • 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-func072e0cb299
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func072e0cb299
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func072e0cb299
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func072e0cb299
  • 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...
❌ Failed to install Radius for corerp-cloud functional test. Please check the logs for more details
❌ corerp-cloud functional test failed. Please check the logs for more details
❌ ucp-cloud functional test cancelled. Please check the logs for more details
⌛ Starting corerp-cloud functional tests...
⌛ Starting ucp-cloud functional tests...
❌ Failed to install Radius for corerp-cloud functional test. Please check the logs for more details
❌ corerp-cloud functional test failed. Please check the logs for more details
❌ ucp-cloud functional test cancelled. Please check the logs for more details

Signed-off-by: willdavsmith <[email protected]>
@radius-functional-tests
Copy link

radius-functional-tests bot commented May 12, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 6152f36
Unique ID func25ed1b80e4
Image tag pr-func25ed1b80e4
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-func25ed1b80e4
  • 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-func25ed1b80e4
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func25ed1b80e4
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func25ed1b80e4
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func25ed1b80e4
  • 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 ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@willdavsmith willdavsmith changed the base branch from features/upgrade-v1 to main May 12, 2025 23:11
Signed-off-by: willdavsmith <[email protected]>
@radius-functional-tests
Copy link

radius-functional-tests bot commented May 12, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref c7e5bec
Unique ID func155d7841d1
Image tag pr-func155d7841d1
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-func155d7841d1
  • 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-func155d7841d1
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func155d7841d1
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func155d7841d1
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func155d7841d1
  • 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...
✅ corerp-cloud functional tests succeeded
✅ ucp-cloud functional tests succeeded

@willdavsmith willdavsmith temporarily deployed to functional-tests May 13, 2025 22:19 — with GitHub Actions Inactive
@willdavsmith willdavsmith changed the title Update clients and cluster manager Refactor pkg/cli/helm and add unit tests May 13, 2025
@radius-functional-tests
Copy link

radius-functional-tests bot commented May 13, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref ddab411
Unique ID funcee06288465
Image tag pr-funcee06288465
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-funcee06288465
  • 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-funcee06288465
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-funcee06288465
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funcee06288465
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funcee06288465
  • 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 ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

Copy link
Member

@brooke-hamilton brooke-hamilton left a comment

Choose a reason for hiding this comment

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

The PR description should explain why these changes are being made, especially if there is no issue linked. The PR checklist should also be filled out.


// QueryRelease checks to see if a release is deployed to a namespace for a given kubecontext.
// Returns a bool indicating if the release is deployed, the version of the release, and an error if one occurs.
QueryRelease(kubeContext, namespace, releaseName string) (bool, string, error)
Copy link
Member

Choose a reason for hiding this comment

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

The parameters are in a different order than the implementation and the code that calls the function.

Copy link
Contributor

Choose a reason for hiding this comment

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

good catch. looks like 2 wrongs do make a right

}

err := AddValues(&helmChart, options)
err := addArgsFromCLI(&helmChart, options)
require.Equal(t, err, nil)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: use require.NoError(t, err)

See the License for the specific language governing permissions and
limitations under the License.
*/

Copy link
Member

Choose a reason for hiding this comment

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

Is removing the copyright header intentional?

Signed-off-by: willdavsmith <[email protected]>
@radius-functional-tests
Copy link

radius-functional-tests bot commented May 19, 2025

Radius functional test overview

🔍 Go to test action run

Name Value
Repository radius-project/radius
Commit ref 5bff917
Unique ID func7b869db5a7
Image tag pr-func7b869db5a7
Click here to see the list of tools in the current test run
  • gotestsum 1.12.0
  • KinD: v0.20.0
  • Dapr:
  • 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-func7b869db5a7
  • 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-func7b869db5a7
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-func7b869db5a7
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-func7b869db5a7
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-func7b869db5a7
  • 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 ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

Copy link
Member

@brooke-hamilton brooke-hamilton left a comment

Choose a reason for hiding this comment

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

🚢

@willdavsmith willdavsmith merged commit 9fe3bc0 into main May 19, 2025
35 checks passed
@willdavsmith willdavsmith deleted the ytimocin/upgrade/clients branch May 19, 2025 18:11
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.

3 participants