Skip to content

Commit 5f6fedf

Browse files
authored
Merge pull request #30 from replicatedhq/run
Remove run subcommand
2 parents e42b7c3 + c2fd9cc commit 5f6fedf

File tree

10 files changed

+85
-221
lines changed

10 files changed

+85
-221
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ local-release:
9898

9999
.PHONY: run-preflight
100100
run-preflight: preflight
101-
./bin/preflight run \
101+
./bin/preflight \
102102
--image=localhost:32000/troubleshoot:alpha \
103103
--pullpolicy=Always \
104104
./config/samples/troubleshoot_v1beta1_preflight.yaml
105105

106106
.PHONY: run-troubleshoot
107107
run-troubleshoot: troubleshoot
108-
./bin/troubleshoot run \
108+
./bin/troubleshoot \
109109
--image=localhost:32000/troubleshoot:alpha \
110110
--pullpolicy=Always \
111111
./config/samples/troubleshoot_v1beta1_collector.yaml

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Preflight checks are an easy-to-run set of conformance tests that can be written
88
To run a sample preflight check from a sample application, [install the preflight kubectl plugin](https://help.replicated.com/docs/troubleshoot/kubernetes/preflight/running-as-kubectl-plugin/) and run:
99

1010
```shell
11-
kubectl preflight https://git.io/preflight-checks
11+
kubectl preflight https://preflight.replicated.com
1212
```
1313

1414
For a full description of the supported preflight checks, visit the [docs](https://help.replicated.com/docs/troubleshoot/kubernetes/analysis/analysis-phase/).
@@ -19,5 +19,5 @@ A support bundle is an archive that's created in-cluster, by collecting logs, cl
1919
To collect a sample support bundle, [install the troubleshoot kubectl plugin](/docs/troubleshoot/kubernetes/troubleshoot/running-as-kubectl-plugin/) and run:
2020

2121
```shell
22-
kubectl troubleshoot https://git.io/support-bundle
22+
kubectl troubleshoot https://troubleshoot.replicated.com
2323
```

cmd/preflight/cli/root.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,50 @@ package cli
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67
"strings"
78

9+
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
810
"github.com/spf13/cobra"
911
"github.com/spf13/viper"
1012
)
1113

1214
func RootCmd() *cobra.Command {
1315
cmd := &cobra.Command{
14-
Use: "preflight",
16+
Use: "preflight [url]",
1517
Short: "Run and retrieve preflight checks in a cluster",
1618
Long: `A preflight check is a set of validations that can and should be run to ensure
1719
that a cluster meets the requirements to run an application.`,
18-
SilenceUsage: true,
20+
PreRun: func(cmd *cobra.Command, args []string) {
21+
viper.BindPFlags(cmd.Flags())
22+
},
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
v := viper.GetViper()
25+
26+
if len(args) == 0 {
27+
return runPreflightsCRD(v)
28+
}
29+
30+
return runPreflightsNoCRD(v, args[0])
31+
},
1932
}
2033

2134
cobra.OnInitialize(initConfig)
2235

23-
cmd.AddCommand(Run())
24-
cmd.AddCommand(Server())
36+
cmd.Flags().Bool("interactive", true, "interactive preflights")
37+
cmd.Flags().String("format", "human", "output format, one of human, json, yaml. only used when interactive is set to false")
38+
39+
cmd.Flags().String("preflight", "", "name of the preflight to use")
40+
cmd.Flags().String("namespace", "default", "namespace the preflight can be found in")
41+
42+
cmd.Flags().String("kubecontext", filepath.Join(homeDir(), ".kube", "config"), "the kubecontext to use when connecting")
43+
44+
cmd.Flags().String("image", "", "the full name of the preflight image to use")
45+
cmd.Flags().String("pullpolicy", "", "the pull policy of the preflight image")
46+
cmd.Flags().String("collector-image", "", "the full name of the collector image to use")
47+
cmd.Flags().String("collector-pullpolicy", "", "the pull policy of the collector image")
48+
49+
cmd.Flags().String("serviceaccount", "", "name of the service account to use. if not provided, one will be created")
2550

2651
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
2752
return cmd
@@ -38,3 +63,16 @@ func initConfig() {
3863
viper.SetEnvPrefix("PREFLIGHT")
3964
viper.AutomaticEnv()
4065
}
66+
67+
func ensureCollectorInList(list []*troubleshootv1beta1.Collect, collector troubleshootv1beta1.Collect) []*troubleshootv1beta1.Collect {
68+
for _, inList := range list {
69+
if collector.ClusterResources != nil && inList.ClusterResources != nil {
70+
return list
71+
}
72+
if collector.ClusterInfo != nil && inList.ClusterInfo != nil {
73+
return list
74+
}
75+
}
76+
77+
return append(list, &collector)
78+
}

cmd/preflight/cli/run.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

cmd/preflight/cli/server.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

cmd/troubleshoot/cli/root.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,47 @@ package cli
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
67
"strings"
78

9+
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
810
"github.com/spf13/cobra"
911
"github.com/spf13/viper"
1012
)
1113

1214
func RootCmd() *cobra.Command {
1315
cmd := &cobra.Command{
14-
Use: "troubleshoot",
16+
Use: "troubleshoot [url]",
1517
Short: "Generate and manage support bundles",
1618
Long: `A support bundle is an archive of files, output, metrics and state
1719
from a server that can be used to assist when troubleshooting a server.`,
18-
SilenceUsage: true,
20+
PreRun: func(cmd *cobra.Command, args []string) {
21+
viper.BindPFlags(cmd.Flags())
22+
},
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
v := viper.GetViper()
25+
26+
if len(args) == 0 {
27+
return runTroubleshootCRD(v)
28+
}
29+
30+
return runTroubleshootNoCRD(v, args[0])
31+
},
1932
}
2033

2134
cobra.OnInitialize(initConfig)
2235

23-
cmd.AddCommand(Run())
24-
cmd.AddCommand(Retrieve())
36+
cmd.Flags().String("collectors", "", "name of the collectors to use")
37+
cmd.Flags().String("namespace", "default", "namespace the collectors can be found in")
38+
39+
cmd.Flags().String("kubecontext", filepath.Join(homeDir(), ".kube", "config"), "the kubecontext to use when connecting")
40+
41+
cmd.Flags().String("image", "", "the full name of the collector image to use")
42+
cmd.Flags().String("pullpolicy", "", "the pull policy of the collector image")
43+
cmd.Flags().Bool("redact", true, "enable/disable default redactions")
44+
45+
cmd.Flags().String("serviceaccount", "", "name of the service account to use. if not provided, one will be created")
46+
viper.BindPFlags(cmd.Flags())
2547

2648
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
2749
return cmd
@@ -38,3 +60,16 @@ func initConfig() {
3860
viper.SetEnvPrefix("TROUBLESHOOT")
3961
viper.AutomaticEnv()
4062
}
63+
64+
func ensureCollectorInList(list []*troubleshootv1beta1.Collect, collector troubleshootv1beta1.Collect) []*troubleshootv1beta1.Collect {
65+
for _, inList := range list {
66+
if collector.ClusterResources != nil && inList.ClusterResources != nil {
67+
return list
68+
}
69+
if collector.ClusterInfo != nil && inList.ClusterInfo != nil {
70+
return list
71+
}
72+
}
73+
74+
return append(list, &collector)
75+
}

cmd/troubleshoot/cli/run.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

examples/troubleshoot/sample-troubleshoot.yaml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,9 @@ spec:
2323
command: ["ping"]
2424
args: ["www.google.com"]
2525
timeout: 5s
26-
- exec:
27-
collectorName: mysql-vars
28-
selector:
29-
- app=mysql
30-
namespace: default
31-
command: ["mysql"]
32-
args: ["-ureplicated", "-ppassword", "-e", "show processlist"]
33-
timeout: 60m
34-
- exec:
35-
collectorName: hosts
36-
selector:
37-
- app=graphql-api
38-
namespace: default
39-
command: ["cat"]
40-
args: ["/etc/hosts"]
41-
timeout: 60m
42-
- exec:
43-
collectorName: broken
44-
selector:
45-
- app=graphql-api
46-
namespace: default
47-
command: ["cat"]
48-
args: ["/etc/hostdasddsda"]
49-
timeout: 60m
5026
- http:
5127
collectorName: test-get
5228
get:
5329
url: https://api.staging.replicated.com/market/v1/echo/ip
5430
insecureSkipVerify: false
5531
headers: {}
56-
- http:
57-
collectorName: test-post
58-
post:
59-
url: http://httpbin.org/headers
60-
insecureSkipVerify: false
61-
headers:
62-
X-Custom-Header: "post-request"
63-
- http:
64-
collectorName: test-put
65-
put:
66-
url: http://httpbin.org/anything
67-
insecureSkipVerify: false
68-
headers:
69-
X-Custom-Header: "put-request"
70-
- http:
71-
collectorName: test-broken
72-
put:
73-
url: ""

0 commit comments

Comments
 (0)