-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
18 changed files
with
588 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
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: "Installs Radius onto a kubernetes cluster.", | ||
Example: `# install Radius with default settings on current kubernetes context | ||
rad install kubernetes | ||
# install Radius and override the default chart values | ||
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, | ||
Set: r.Set, | ||
}, | ||
} | ||
|
||
state, err := r.Helm.CheckRadiusInstall(r.KubeContext) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
version := version.Version() | ||
if state.Installed && r.Reinstall { | ||
r.Output.LogInfo("Reinstalling Radius version %s to namespace: %s...", version, helm.RadiusSystemNamespace) | ||
} else if state.Installed { | ||
r.Output.LogInfo("Found existing Radius installation. Use '--reinstall' to force reinstallation.") | ||
return nil | ||
} 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 | ||
} |
Oops, something went wrong.