Skip to content

Commit

Permalink
Update install/uninstall commands
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
rynowak committed Jun 15, 2023
1 parent 774652e commit 5cbab36
Show file tree
Hide file tree
Showing 18 changed files with 611 additions and 414 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/uninstall.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 uninstallCmd = &cobra.Command{
Use: "uninstall",
Short: "Uninstall radius for a specific platform",
Long: `Uninstall radius for a specific platform`,
}

func init() {
RootCmd.AddCommand(uninstallCmd)
// 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 5cbab36

Please sign in to comment.