Skip to content

Commit

Permalink
Update install/uninstall commands (#5725)
Browse files Browse the repository at this point in the history
# Description

This change updates the install and uninstall commands to use the CLI
framework and adds tests. These commands previously were missing tests.

Additionally I removed the console output from the *shared* code path
used for installation by both `rad init` and `rad install kubernetes`
and moved it to the `rad install kubernetes` command directly. This was
causing an issue with the interactive output shown by `rad init`. Any
time we're using Bubbletea to display something, we need to prevent any
other console output from going to stdout. This cleanup fixes a display
bug in `rad init`.


## Auto-generated summary

<!--
GitHub Copilot for docs will auto-generate a summary of the PR
-->

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 42630cd</samp>

### Summary
🚀🧹🧪

<!--
1. 🚀 - This emoji represents the new feature of installing Radius on
Kubernetes using the `install` command and its subcommand `install
kubernetes`. This is a major enhancement for the user experience and the
functionality of the CLI.
2. 🧹 - This emoji represents the refactoring and simplification of the
code, as well as the removal of unused or redundant code and fields.
This is a minor improvement for the code quality and maintainability.
3. 🧪 - This emoji represents the addition of unit tests for the `install
kubernetes` and `uninstall kubernetes` commands and their runners. This
is a minor improvement for the code coverage and reliability.
-->
This pull request adds the `install` and `uninstall` commands and their
subcommands for Kubernetes to the Radius CLI. It also refactors and
simplifies the helm chart logic, removes unused code and files, and adds
unit tests for the new commands.

> _`install` command grows_
> _`uninstall` follows its steps_
> _helm charts in spring_

### Walkthrough
* Add `install` and `uninstall` commands and subcommands for different
platforms
([link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-d36b7b4d04f01a6cf60c50dd9c01da8fb8c190231ea4c59cbbfbe070178b510bR48-R49),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-d36b7b4d04f01a6cf60c50dd9c01da8fb8c190231ea4c59cbbfbe070178b510bR277-R281),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-cee167b5fae6ceb091e56307a4a1a5ed10a903a67e94e9f21fbecf5424ca44e9L17-R28),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-5d15d76cfd8957139c374b9ef658dfa8e46eced4ed1da0dd058f6a2af4219267R1-R28))
* Implement and test `install kubernetes` command and runner using
`helm` and `output` interfaces
([link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-969a1495c18d847fc09b31b1e6854e7be42d541513807361aaa5e9497a62e86fR1-R110),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-fe10b481ed48e3007befe842b7f4bd554a17bf5b76b39e6c863ffb068a093c78R1-R177),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-a94c29c96fb0778e35d7983669dedfa10de7111040707a3839dace9836b20d0bR185-R187),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-a94c29c96fb0778e35d7983669dedfa10de7111040707a3839dace9836b20d0bR202-R205),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-2d01644b81f03e1f0c2eecf2479214ce1fd7e1b1c1c2a9f4ed5606e345f61d3fR66-R79),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eR25),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL31-L33),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL46-R44),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL90),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL97-L98),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL104-L105),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL112),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7f93f7a0f0c6c2329155f30e6a4cc6928277acabefab4c28826cb143a23ce90eL119-R121),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-d86037fd6c18ac1d33c42f14b22694ed549f413bc6f01e486edcc069e3e50e08L31-R31),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-d86037fd6c18ac1d33c42f14b22694ed549f413bc6f01e486edcc069e3e50e08L39-L45),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-d86037fd6c18ac1d33c42f14b22694ed549f413bc6f01e486edcc069e3e50e08L69-R61),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-d86037fd6c18ac1d33c42f14b22694ed549f413bc6f01e486edcc069e3e50e08L77-L83))
* Implement and test `uninstall kubernetes` command and runner using
`helm` and `output` interfaces
([link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-0c66069f452935504ded2987817c39f57ab768793748e2f8a9e6b93a3529406eR1-R90),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-33a999669eb2dcff3938070935440577bfabd65104db26e7b8e1c42b0a139a5dR1-R118),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-a94c29c96fb0778e35d7983669dedfa10de7111040707a3839dace9836b20d0bL53-L57),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-a94c29c96fb0778e35d7983669dedfa10de7111040707a3839dace9836b20d0bL64),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-a94c29c96fb0778e35d7983669dedfa10de7111040707a3839dace9836b20d0bL81-R76))
* Add flag for specifying Kubernetes context to `commonflags` package
([link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-40d092c037a2ba62ae8e3716ee0ebc4e4244023c7b030a0c855da629076a5053R110-R113))
* Delete unused files and code related to previous installation logic
([link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-6d139e6efecb729155a2ad191d25039e107f7d6677a17be5650199ae8e48c0c0),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-4fb102623b364b352cbac46bcbdeb3c9e678fe71c2ccfda9fcc4b7303eb03d68),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-ca2257e7dd0dc51444106f8b77568bfa89fc7239ffca43bb6d4154677f06442c),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-76a1681b574683b48c986dfbfd669aaf0e33e5f6094c277be1a9fd2e28f12818),
[link](https://github.com/project-radius/radius/pull/5725/files?diff=unified&w=0#diff-7213cc490ab86f00c0e5f12592f33bb9aad04578bc0b9cfa37b41aebe45d8c50))
  • Loading branch information
rynowak authored and nithyatsu committed Jun 21, 2023
1 parent 92c8d70 commit f407ab1
Show file tree
Hide file tree
Showing 18 changed files with 583 additions and 426 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/functional-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ jobs:
echo "*** Installing Radius to Kubernetes ***"
rad install kubernetes \
--chart ${{ env.RADIUS_CHART_LOCATION }} --tag ${{ env.REL_VERSION }} \
--set rp.image=${{ env.CACHE_REGISTRY }}/appcore-rp,rp.tag=${{ env.REL_VERSION }},ucp.image=${{ env.CACHE_REGISTRY }}/ucpd,ucp.tag=${{ env.REL_VERSION }},ucp.provider.aws.region=${{ env.AWS_REGION }}
--chart ${{ env.RADIUS_CHART_LOCATION }} \
--set rp.image=${{ env.CACHE_REGISTRY }}/appcore-rp,rp.tag=${{ env.REL_VERSION }},ucp.image=${{ env.CACHE_REGISTRY }}/ucpd,ucp.tag=${{ env.REL_VERSION }}
echo "*** Create workspace, group and environment for test ***"
rad workspace create kubernetes
Expand Down
67 changes: 0 additions & 67 deletions cmd/rad/cmd/installKubernetes.go

This file was deleted.

16 changes: 16 additions & 0 deletions cmd/rad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import (
env_show "github.com/project-radius/radius/pkg/cli/cmd/env/show"
env_update "github.com/project-radius/radius/pkg/cli/cmd/env/update"
group "github.com/project-radius/radius/pkg/cli/cmd/group"
"github.com/project-radius/radius/pkg/cli/cmd/install"
install_kubernetes "github.com/project-radius/radius/pkg/cli/cmd/install/kubernetes"
"github.com/project-radius/radius/pkg/cli/cmd/radinit"
recipe_list "github.com/project-radius/radius/pkg/cli/cmd/recipe/list"
recipe_register "github.com/project-radius/radius/pkg/cli/cmd/recipe/register"
Expand All @@ -54,6 +56,8 @@ import (
resource_list "github.com/project-radius/radius/pkg/cli/cmd/resource/list"
resource_show "github.com/project-radius/radius/pkg/cli/cmd/resource/show"
"github.com/project-radius/radius/pkg/cli/cmd/run"
"github.com/project-radius/radius/pkg/cli/cmd/uninstall"
uninstall_kubernetes "github.com/project-radius/radius/pkg/cli/cmd/uninstall/kubernetes"
workspace_create "github.com/project-radius/radius/pkg/cli/cmd/workspace/create"
workspace_delete "github.com/project-radius/radius/pkg/cli/cmd/workspace/delete"
workspace_list "github.com/project-radius/radius/pkg/cli/cmd/workspace/list"
Expand Down Expand Up @@ -272,6 +276,18 @@ func initSubCommands() {

bicepPublishCmd, _ := bicep_publish.NewCommand(framework)
bicepCmd.AddCommand(bicepPublishCmd)

installCmd := install.NewCommand()
RootCmd.AddCommand(installCmd)

installKubernetesCmd, _ := install_kubernetes.NewCommand(framework)
installCmd.AddCommand(installKubernetesCmd)

uninstallCmd := uninstall.NewCommand()
RootCmd.AddCommand(uninstallCmd)

uninstallKubernetesCmd, _ := uninstall_kubernetes.NewCommand(framework)
uninstallCmd.AddCommand(uninstallKubernetesCmd)
}

// The dance we do with config is kinda complex. We want commands to be able to retrieve a config (*viper.Viper)
Expand Down
50 changes: 0 additions & 50 deletions cmd/rad/cmd/uninstallKubernetes.go

This file was deleted.

4 changes: 4 additions & 0 deletions pkg/cli/cmd/commonflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ func AddAWSRegionFlag(cmd *cobra.Command) {
func AddAWSAccountFlag(cmd *cobra.Command) {
cmd.Flags().String(AWSAccountIdFlag, "", "The account ID where AWS resources will be deployed")
}

func AddKubeContextFlagVar(cmd *cobra.Command, ref *string) {
cmd.Flags().StringVar(ref, "kubecontext", "", "The Kubernetes context to use, will use the default if unset")
}
21 changes: 9 additions & 12 deletions cmd/rad/cmd/install.go → pkg/cli/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd
package install

import (
"github.com/spf13/cobra"
)
import "github.com/spf13/cobra"

var installCmd = &cobra.Command{
Use: "install",
Short: "Installs radius for a given platform",
Long: `Installs radius for a given platform`,
}

func init() {
RootCmd.AddCommand(installCmd)
// NewCommand returns a new cobra command for `rad install`.
func NewCommand() *cobra.Command {
return &cobra.Command{
Use: "install",
Short: "Installs Radius for a given platform",
Long: `Installs Radius for a given platform`,
}
}
123 changes: 123 additions & 0 deletions pkg/cli/cmd/install/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
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 kubernetes

import (
"context"

"github.com/project-radius/radius/pkg/cli/cmd/commonflags"
"github.com/project-radius/radius/pkg/cli/framework"
"github.com/project-radius/radius/pkg/cli/helm"
"github.com/project-radius/radius/pkg/cli/output"
"github.com/project-radius/radius/pkg/version"
"github.com/spf13/cobra"
)

// NewCommand creates an instance of the `rad install kubernetes` command and runner.
func NewCommand(factory framework.Factory) (*cobra.Command, framework.Runner) {
runner := NewRunner(factory)

cmd := &cobra.Command{
Use: "kubernetes",
Short: "Installs Radius onto a kubernetes cluster",
Long: `Install Radius in a Kubernetes cluster using the Radius Helm chart.
By default 'rad install kubernetes' will install Radius with the version matching the rad CLI version.
Radius will be installed in the 'radius-system' namespace. For more information visit https://docs.radapp.dev/concepts/architecture/
Overrides can be set by specifying Helm chart values with the '--set' flag. For more information visit https://docs.radapp.dev/operations/platforms/kubernetes/install/.
`,
Example: `# Install Radius with default settings in current Kubernetes context
rad install kubernetes
# Install Radius with default settings in specified Kubernetes context
rad install kubernetes --kubecontext mycluster
# Install Radius with overrides in the current Kubernetes context
rad install kubernetes --set key=value
`,
Args: cobra.ExactArgs(0),
RunE: framework.RunCommand(runner),
}

commonflags.AddKubeContextFlagVar(cmd, &runner.KubeContext)
cmd.Flags().BoolVar(&runner.Reinstall, "reinstall", false, "Specify to force reinstallation of Radius")
cmd.Flags().StringVar(&runner.Chart, "chart", "", "Specify a file path to a helm chart to install Radius from")
cmd.Flags().StringArrayVar(&runner.Set, "set", []string{}, "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")

return cmd, runner
}

// Runner is the Runner implementation for the `rad install kubernetes` command.
type Runner struct {
Helm helm.Interface
Output output.Interface

KubeContext string
Chart string
Reinstall bool
Set []string
}

// NewRunner creates an instance of the runner for the `rad install kubernetes` command.
func NewRunner(factory framework.Factory) *Runner {
return &Runner{
Helm: factory.GetHelmInterface(),
Output: factory.GetOutput(),
}
}

// Validate runs validation for the `rad install kubernetes` command.
func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
return nil
}

// Run runs the `rad install kubernetes` command.
func (r *Runner) Run(ctx context.Context) error {
cliOptions := helm.CLIClusterOptions{
Radius: helm.RadiusOptions{
Reinstall: r.Reinstall,
ChartPath: r.Chart,
SetArgs: r.Set,
},
}

state, err := r.Helm.CheckRadiusInstall(r.KubeContext)
if err != nil {
return err
}

if state.Installed && !r.Reinstall {
r.Output.LogInfo("Found existing Radius installation. Use '--reinstall' to force reinstallation.")
return nil
}

version := version.Version()
if state.Installed {
r.Output.LogInfo("Reinstalling Radius version %s to namespace: %s...", version, helm.RadiusSystemNamespace)
} else {
r.Output.LogInfo("Installing Radius version %s to namespace: %s...", version, helm.RadiusSystemNamespace)
}

clusterOptions := helm.PopulateDefaultClusterOptions(cliOptions)
_, err = r.Helm.InstallRadius(ctx, clusterOptions, r.KubeContext)
if err != nil {
return err
}

return nil
}
Loading

0 comments on commit f407ab1

Please sign in to comment.