Skip to content

Commit 08ca93c

Browse files
committed
set up profile installation commands
1 parent bd3b944 commit 08ca93c

File tree

3 files changed

+45
-33
lines changed

3 files changed

+45
-33
lines changed

go/cli/cmd/kagent/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@ func main() {
3232
rootCmd.PersistentFlags().StringVarP(&cfg.Namespace, "namespace", "n", "kagent", "Namespace")
3333
rootCmd.PersistentFlags().StringVarP(&cfg.OutputFormat, "output-format", "o", "table", "Output format")
3434
rootCmd.PersistentFlags().BoolVarP(&cfg.Verbose, "verbose", "v", false, "Verbose output")
35+
var profile string
3536
installCmd := &cobra.Command{
3637
Use: "install",
3738
Short: "Install kagent",
3839
Long: `Install kagent`,
3940
Run: func(cmd *cobra.Command, args []string) {
40-
cli.InstallCmd(cmd.Context(), cfg)
41+
cli.InstallCmd(cmd.Context(), cfg, profile)
4142
},
4243
}
44+
installCmd.Flags().StringVar(&profile, "profile", "minimal", "Installation profile (minimal|demo)")
45+
_ = installCmd.RegisterFlagCompletionFunc("profile", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
46+
return cli.Profiles, cobra.ShellCompDirectiveNoFileComp
47+
})
4348

4449
uninstallCmd := &cobra.Command{
4550
Use: "uninstall",
@@ -434,8 +439,7 @@ Example:
434439
Aliases: []string{"i"},
435440
Help: "Install kagent.",
436441
Func: func(c *ishell.Context) {
437-
cfg := config.GetCfg(c)
438-
if pf := cli.InstallCmd(ctx, cfg); pf != nil {
442+
if pf := cli.InteractiveInstallCmd(ctx, c); pf != nil {
439443
// Set the port-forward to the shell.
440444
shell.Set(portForwardKey, pf)
441445
}

go/cli/internal/cli/const.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const (
1111
// Version is the current version of the kagent CLI
1212
DefaultModelProvider = v1alpha1.ModelProviderOpenAI
1313
DefaultHelmOciRegistry = "oci://ghcr.io/kagent-dev/kagent/helm/"
14-
// This is the default path to the profile values files, NOT the "default" profile - as in the profile that is the default - values file
1514
// TODO: If possible, we should try and use a release tag for whatever release the CLI is running on
1615
DefaultProfileUrl = "https://raw.githubusercontent.com/kagent-dev/kagent/main/helm/kagent/files/profiles/"
1716

@@ -74,7 +73,12 @@ func GetProviderAPIKey(provider v1alpha1.ModelProvider) string {
7473

7574
// GetProfileUrl returns the profile url from KAGENT_HELM_PROFILE_URL environment variable
7675
func GetHelmProfileUrl(profile string) string {
77-
return GetEnvVarWithDefault(KAGENT_HELM_PROFILE_URL, DefaultProfileUrl) + profile + ".yaml"
76+
profileUrl := GetEnvVarWithDefault(KAGENT_HELM_PROFILE_URL, DefaultProfileUrl)
77+
// add trailing slash if not present
78+
if !strings.HasSuffix(profileUrl, "/") {
79+
profileUrl += "/"
80+
}
81+
return profileUrl + profile + ".yaml"
7882
}
7983

8084
// GetEnvVarWithDefault returns the value of the environment variable if it exists, otherwise returns the default value

go/cli/internal/cli/install.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ const (
2626
ProfileDemo = "demo"
2727
)
2828

29+
var (
30+
Profiles = []string{ProfileMinimal, ProfileDemo}
31+
)
32+
2933
// installChart installs or upgrades a Helm chart with the given parameters
30-
func installChart(ctx context.Context, chartName string, namespace string, registry string, version string, setValues []string, s *spinner.Spinner) (string, error) {
34+
func installChart(ctx context.Context, chartName string, namespace string, registry string, version string, setValues []string, valuesFile string, s *spinner.Spinner) (string, error) {
3135
args := []string{
3236
"upgrade",
3337
"--install",
@@ -50,14 +54,18 @@ func installChart(ctx context.Context, chartName string, namespace string, regis
5054
args = append(args, "--set", setValue)
5155
}
5256

57+
if valuesFile != "" {
58+
args = append(args, "-f", valuesFile)
59+
}
60+
5361
cmd := exec.CommandContext(ctx, "helm", args...)
5462
if byt, err := cmd.CombinedOutput(); err != nil {
5563
return string(byt), err
5664
}
5765
return "", nil
5866
}
5967

60-
func InstallCmd(ctx context.Context, cfg *config.Config) *PortForward {
68+
func InstallCmd(ctx context.Context, cfg *config.Config, profile string) *PortForward {
6169
if version.Version == "dev" {
6270
fmt.Fprintln(os.Stderr, "Installation requires released version of kagent")
6371
return nil
@@ -94,14 +102,27 @@ func InstallCmd(ctx context.Context, cfg *config.Config) *PortForward {
94102
values = append(values, hev)
95103
}
96104

105+
// Validate and normalize profile input
106+
profile = strings.TrimSpace(profile)
107+
switch profile {
108+
case "":
109+
// default to minimal. no warning as this is the default
110+
profile = ProfileMinimal
111+
case ProfileDemo, ProfileMinimal:
112+
// valid, no change
113+
default:
114+
fmt.Fprintln(os.Stderr, "Invalid --profile value, defaulting to minimal")
115+
profile = ProfileMinimal
116+
}
117+
97118
// spinner for installation progress
98119
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond)
99120

100121
// First install kagent-crds
101122
s.Suffix = " Installing kagent-crds from " + helmRegistry
102123
defer s.Stop()
103124
s.Start()
104-
if output, err := installChart(ctx, "kagent-crds", cfg.Namespace, helmRegistry, helmVersion, nil, s); err != nil {
125+
if output, err := installChart(ctx, "kagent-crds", cfg.Namespace, helmRegistry, helmVersion, nil, "", s); err != nil {
105126
// Always stop the spinner before printing error messages
106127
s.Stop()
107128

@@ -120,24 +141,8 @@ func InstallCmd(ctx context.Context, cfg *config.Config) *PortForward {
120141
}
121142

122143
// Update status
123-
var profile string
124-
fmt.Fprintln(os.Stdout, "Select a profile:")
125-
fmt.Fprintln(os.Stdout, "1. Minimal (no agents enabled, default)")
126-
fmt.Fprintln(os.Stdout, "2. Demo (all agents enabled)")
127-
fmt.Fprint(os.Stdout, "Enter the profile number: ")
128-
fmt.Scanln(&profile)
129-
switch profile {
130-
case "1":
131-
values = append(values, "-f", GetHelmProfileUrl(ProfileMinimal))
132-
case "2":
133-
values = append(values, "-f", GetHelmProfileUrl(ProfileDemo))
134-
default:
135-
fmt.Fprintln(os.Stderr, "Invalid profile number, defaulting to minimal profile")
136-
values = append(values, "-f", GetHelmProfileUrl(ProfileMinimal))
137-
}
138-
139-
s.Suffix = fmt.Sprintf(" Installing kagent [%s] Using %s:%s %v", modelProvider, helmRegistry, helmVersion, extraValues)
140-
if output, err := installChart(ctx, "kagent", cfg.Namespace, helmRegistry, helmVersion, values, s); err != nil {
144+
s.Suffix = fmt.Sprintf(" Installing kagent with %s profile [%s] Using %s:%s %v", profile, modelProvider, helmRegistry, helmVersion, extraValues)
145+
if output, err := installChart(ctx, "kagent", cfg.Namespace, helmRegistry, helmVersion, values, GetHelmProfileUrl(profile), s); err != nil {
141146
// Always stop the spinner before printing error messages
142147
s.Stop()
143148
fmt.Fprintln(os.Stderr, "Error installing kagent:", output)
@@ -195,14 +200,18 @@ func InteractiveInstallCmd(ctx context.Context, c *ishell.Context) *PortForward
195200
values = append(values, hev)
196201
}
197202

203+
// Add profile selection
204+
profileIdx := c.MultiChoice(Profiles, "Select a profile:")
205+
selectedProfile := Profiles[profileIdx]
206+
198207
// spinner for installation progress
199208
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond)
200209

201210
// First install kagent-crds
202211
s.Suffix = " Installing kagent-crds from " + helmRegistry
203212
defer s.Stop()
204213
s.Start()
205-
if output, err := installChart(ctx, "kagent-crds", cfg.Namespace, helmRegistry, helmVersion, nil, s); err != nil {
214+
if output, err := installChart(ctx, "kagent-crds", cfg.Namespace, helmRegistry, helmVersion, nil, "", s); err != nil {
206215
// Always stop the spinner before printing error messages
207216
s.Stop()
208217

@@ -220,14 +229,9 @@ func InteractiveInstallCmd(ctx context.Context, c *ishell.Context) *PortForward
220229
}
221230
}
222231

223-
// Add profile selection
224-
profiles := []string{ProfileMinimal, ProfileDemo}
225-
profileIdx := c.MultiChoice(profiles, "Select a profile:")
226-
values = append(values, "-f", GetHelmProfileUrl(profiles[profileIdx]))
227-
228232
// Update status
229233
s.Suffix = fmt.Sprintf(" Installing kagent [%s] Using %s:%s %v", modelProvider, helmRegistry, helmVersion, extraValues)
230-
if output, err := installChart(ctx, "kagent", cfg.Namespace, helmRegistry, helmVersion, values, s); err != nil {
234+
if output, err := installChart(ctx, "kagent", cfg.Namespace, helmRegistry, helmVersion, values, GetHelmProfileUrl(selectedProfile), s); err != nil {
231235
// Always stop the spinner before printing error messages
232236
s.Stop()
233237
fmt.Fprintln(os.Stderr, "Error installing kagent:", output)

0 commit comments

Comments
 (0)