Skip to content

Commit 5282b36

Browse files
authored
Fix installer tracetest dev docker warning and add options to run installer directly without user input. (#2462)
* Adding options to run installer with previously chosen options * Adding empty TRACETEST_DEV env when loading docker-compose on installation to avoid warning
1 parent c133ffb commit 5282b36

File tree

5 files changed

+115
-9
lines changed

5 files changed

+115
-9
lines changed

cli/cmd/server_install_cmd.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
)
88

99
var (
10-
force = false
10+
force = false
11+
runEnvironment = installer.NoneRunEnvironmentType
12+
installationMode = installer.NotChosenInstallationModeType
1113
)
1214

1315
var serverInstallCmd = &cobra.Command{
@@ -17,13 +19,21 @@ var serverInstallCmd = &cobra.Command{
1719
PreRun: setupCommand(SkipConfigValidation()),
1820
Run: func(cmd *cobra.Command, args []string) {
1921
installer.Force = force
22+
installer.RunEnvironment = runEnvironment
23+
installer.InstallationMode = installationMode
24+
2025
analytics.Track("Server Install", "cmd", map[string]string{})
2126
installer.Start()
2227
},
2328
PostRun: teardownCommand,
2429
}
2530

2631
func init() {
27-
serverInstallCmd.Flags().BoolVarP(&force, "force", "f", false, "overwrite existing files")
32+
serverInstallCmd.Flags().BoolVarP(&force, "force", "f", false, "Overwrite existing files")
33+
34+
// these commands will not have shorthand parameters to avoid colision with existing ones in other commands
35+
serverInstallCmd.Flags().Var(&installationMode, "mode", "Indicate the type of demo environment to be installed with Tracetest. It can be 'with-demo' or 'just-tracetest'.")
36+
serverInstallCmd.Flags().Var(&runEnvironment, "run-environment", "Type of environment were Tracetest will be installed. It can be 'docker' or 'kubernetes'.")
37+
2838
serverCmd.AddCommand(serverInstallCmd)
2939
}

cli/installer/docker_compose.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ func getCompleteProject(ui cliUI.UI, config configuration) *types.Project {
325325
project, err := loader.Load(types.ConfigDetails{
326326
WorkingDir: workingDir,
327327
ConfigFiles: configFiles,
328+
Environment: map[string]string{
329+
"TRACETEST_DEV": "",
330+
},
328331
})
329332
if err != nil {
330333
ui.Exit(fmt.Errorf("cannot parse docker-compose file: %w", err).Error())

cli/installer/installer.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
)
99

1010
var (
11-
Force = false
11+
Force = false
12+
RunEnvironment = NoneRunEnvironmentType
13+
InstallationMode = NotChosenInstallationModeType
1214
)
1315

1416
const createIssueMsg = "If you need help, please create an issue: https://github.com/kubeshop/tracetest/issues/new/choose"
@@ -30,9 +32,23 @@ or reach us on Discord https://discord.gg/6zupCZFQbe
3032
3133
`)
3234

35+
if RunEnvironment == DockerRunEnvironmentType { // check if docker was previously chosen as a CLI arg
36+
ui.Println("How do you want to run TraceTest?")
37+
ui.Println(" > Using Docker Compose")
38+
dockerCompose.Install(ui)
39+
return
40+
}
41+
42+
if RunEnvironment == KubernetesRunEnvironmentType { // check if kubernetes was previously chosen as a CLI arg
43+
ui.Println("How do you want to run TraceTest?")
44+
ui.Println(" > Using Kubernetes")
45+
kubernetes.Install(ui)
46+
return
47+
}
48+
3349
option := ui.Select("How do you want to run TraceTest?", []cliUI.Option{
34-
{"Using Docker Compose", dockerCompose.Install},
35-
{"Using Kubernetes", kubernetes.Install},
50+
{Text: "Using Docker Compose", Fn: dockerCompose.Install},
51+
{Text: "Using Kubernetes", Fn: kubernetes.Install},
3652
}, 0)
3753

3854
option.Fn(ui)
@@ -82,11 +98,25 @@ func (i installer) Install(ui cliUI.UI) {
8298
type preChecker func(ui cliUI.UI)
8399

84100
func setInstallationType(ui cliUI.UI, config configuration) {
101+
if InstallationMode == WithoutDemoInstallationModeType { // check if it was previously chosen
102+
ui.Println("Do you have OpenTelemetry based tracing already set up, or would you like us to install a demo tracing environment and app?")
103+
ui.Println(" > I have a tracing environment already. Just install Tracetest")
104+
config.set("installer.only_tracetest", true)
105+
return
106+
}
107+
108+
if InstallationMode == WithDemoInstallationModeType { // check if it was previously chosen
109+
ui.Println("Do you have OpenTelemetry based tracing already set up, or would you like us to install a demo tracing environment and app?")
110+
ui.Println(" > Just learning tracing! Install Tracetest, OpenTelemetry Collector and the sample app.")
111+
config.set("installer.only_tracetest", false)
112+
return
113+
}
114+
85115
option := ui.Select("Do you have OpenTelemetry based tracing already set up, or would you like us to install a demo tracing environment and app?", []cliUI.Option{
86-
{"I have a tracing environment already. Just install Tracetest", func(ui cliUI.UI) {
116+
{Text: "I have a tracing environment already. Just install Tracetest", Fn: func(ui cliUI.UI) {
87117
config.set("installer.only_tracetest", true)
88118
}},
89-
{"Just learning tracing! Install Tracetest, OpenTelemetry Collector and the sample app.", func(ui cliUI.UI) {
119+
{Text: "Just learning tracing! Install Tracetest, OpenTelemetry Collector and the sample app.", Fn: func(ui cliUI.UI) {
90120
config.set("installer.only_tracetest", false)
91121
}},
92122
}, 0)

cli/installer/kubernetes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func windowsGnuToolsChecker(ui cliUI.UI) {
4040

4141
ui.Warning("I didn't find sed in your system")
4242
option := ui.Select("What do you want to do?", []cliUI.Option{
43-
{"Install sed", installSed},
44-
{"Fix it manually", exitOption(
43+
{Text: "Install sed", Fn: installSed},
44+
{Text: "Fix it manually", Fn: exitOption(
4545
"Check the helm install docs on https://community.chocolatey.org/packages/sed",
4646
)},
4747
}, 0)

cli/installer/types.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package installer
2+
3+
import (
4+
"errors"
5+
6+
"github.com/spf13/pflag"
7+
)
8+
9+
type RunEnvironmentType string
10+
11+
var _ pflag.Value = (*RunEnvironmentType)(nil)
12+
13+
const (
14+
DockerRunEnvironmentType RunEnvironmentType = "docker"
15+
KubernetesRunEnvironmentType RunEnvironmentType = "kubernetes"
16+
NoneRunEnvironmentType RunEnvironmentType = "none" // stands for "no option chosen"
17+
)
18+
19+
func (e *RunEnvironmentType) String() string {
20+
return string(*e)
21+
}
22+
23+
func (e *RunEnvironmentType) Set(v string) error {
24+
switch v {
25+
case "docker", "kubernetes":
26+
*e = RunEnvironmentType(v)
27+
return nil
28+
default:
29+
return errors.New(`must be "docker" or "kubernetes"`)
30+
}
31+
}
32+
33+
func (e *RunEnvironmentType) Type() string {
34+
return "(docker|kubernetes)"
35+
}
36+
37+
type InstallationModeType string
38+
39+
var _ pflag.Value = (*InstallationModeType)(nil)
40+
41+
const (
42+
WithDemoInstallationModeType InstallationModeType = "with-demo"
43+
WithoutDemoInstallationModeType InstallationModeType = "just-tracetest"
44+
NotChosenInstallationModeType InstallationModeType = "none" // stands for "no option chosen"
45+
)
46+
47+
func (e *InstallationModeType) String() string {
48+
return string(*e)
49+
}
50+
51+
func (e *InstallationModeType) Set(v string) error {
52+
switch v {
53+
case "with-demo", "just-tracetest":
54+
*e = InstallationModeType(v)
55+
return nil
56+
default:
57+
return errors.New(`must be "with-demo" or "just-tracetest"`)
58+
}
59+
}
60+
61+
func (e *InstallationModeType) Type() string {
62+
return "(with-demo|just-tracetest)"
63+
}

0 commit comments

Comments
 (0)