Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove run subcommand #30

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ local-release:

.PHONY: run-preflight
run-preflight: preflight
./bin/preflight run \
./bin/preflight \
--image=localhost:32000/troubleshoot:alpha \
--pullpolicy=Always \
./config/samples/troubleshoot_v1beta1_preflight.yaml

.PHONY: run-troubleshoot
run-troubleshoot: troubleshoot
./bin/troubleshoot run \
./bin/troubleshoot \
--image=localhost:32000/troubleshoot:alpha \
--pullpolicy=Always \
./config/samples/troubleshoot_v1beta1_collector.yaml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Preflight checks are an easy-to-run set of conformance tests that can be written
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:

```shell
kubectl preflight https://git.io/preflight-checks
kubectl preflight https://preflight.replicated.com
```

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

```shell
kubectl troubleshoot https://git.io/support-bundle
kubectl troubleshoot https://troubleshoot.replicated.com
```
46 changes: 42 additions & 4 deletions cmd/preflight/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,50 @@ package cli
import (
"fmt"
"os"
"path/filepath"
"strings"

troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "preflight",
Use: "preflight [url]",
Short: "Run and retrieve preflight checks in a cluster",
Long: `A preflight check is a set of validations that can and should be run to ensure
that a cluster meets the requirements to run an application.`,
SilenceUsage: true,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()

if len(args) == 0 {
return runPreflightsCRD(v)
}

return runPreflightsNoCRD(v, args[0])
},
}

cobra.OnInitialize(initConfig)

cmd.AddCommand(Run())
cmd.AddCommand(Server())
cmd.Flags().Bool("interactive", true, "interactive preflights")
cmd.Flags().String("format", "human", "output format, one of human, json, yaml. only used when interactive is set to false")

cmd.Flags().String("preflight", "", "name of the preflight to use")
cmd.Flags().String("namespace", "default", "namespace the preflight can be found in")

cmd.Flags().String("kubecontext", filepath.Join(homeDir(), ".kube", "config"), "the kubecontext to use when connecting")

cmd.Flags().String("image", "", "the full name of the preflight image to use")
cmd.Flags().String("pullpolicy", "", "the pull policy of the preflight image")
cmd.Flags().String("collector-image", "", "the full name of the collector image to use")
cmd.Flags().String("collector-pullpolicy", "", "the pull policy of the collector image")

cmd.Flags().String("serviceaccount", "", "name of the service account to use. if not provided, one will be created")

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
Expand All @@ -38,3 +63,16 @@ func initConfig() {
viper.SetEnvPrefix("PREFLIGHT")
viper.AutomaticEnv()
}

func ensureCollectorInList(list []*troubleshootv1beta1.Collect, collector troubleshootv1beta1.Collect) []*troubleshootv1beta1.Collect {
for _, inList := range list {
if collector.ClusterResources != nil && inList.ClusterResources != nil {
return list
}
if collector.ClusterInfo != nil && inList.ClusterInfo != nil {
return list
}
}

return append(list, &collector)
}
61 changes: 0 additions & 61 deletions cmd/preflight/cli/run.go

This file was deleted.

43 changes: 0 additions & 43 deletions cmd/preflight/cli/server.go

This file was deleted.

43 changes: 39 additions & 4 deletions cmd/troubleshoot/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,47 @@ package cli
import (
"fmt"
"os"
"path/filepath"
"strings"

troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "troubleshoot",
Use: "troubleshoot [url]",
Short: "Generate and manage support bundles",
Long: `A support bundle is an archive of files, output, metrics and state
from a server that can be used to assist when troubleshooting a server.`,
SilenceUsage: true,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()

if len(args) == 0 {
return runTroubleshootCRD(v)
}

return runTroubleshootNoCRD(v, args[0])
},
}

cobra.OnInitialize(initConfig)

cmd.AddCommand(Run())
cmd.AddCommand(Retrieve())
cmd.Flags().String("collectors", "", "name of the collectors to use")
cmd.Flags().String("namespace", "default", "namespace the collectors can be found in")

cmd.Flags().String("kubecontext", filepath.Join(homeDir(), ".kube", "config"), "the kubecontext to use when connecting")

cmd.Flags().String("image", "", "the full name of the collector image to use")
cmd.Flags().String("pullpolicy", "", "the pull policy of the collector image")
cmd.Flags().Bool("redact", true, "enable/disable default redactions")

cmd.Flags().String("serviceaccount", "", "name of the service account to use. if not provided, one will be created")
viper.BindPFlags(cmd.Flags())

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
Expand All @@ -38,3 +60,16 @@ func initConfig() {
viper.SetEnvPrefix("TROUBLESHOOT")
viper.AutomaticEnv()
}

func ensureCollectorInList(list []*troubleshootv1beta1.Collect, collector troubleshootv1beta1.Collect) []*troubleshootv1beta1.Collect {
for _, inList := range list {
if collector.ClusterResources != nil && inList.ClusterResources != nil {
return list
}
if collector.ClusterInfo != nil && inList.ClusterInfo != nil {
return list
}
}

return append(list, &collector)
}
61 changes: 0 additions & 61 deletions cmd/troubleshoot/cli/run.go

This file was deleted.

42 changes: 0 additions & 42 deletions examples/troubleshoot/sample-troubleshoot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,9 @@ spec:
command: ["ping"]
args: ["www.google.com"]
timeout: 5s
- exec:
collectorName: mysql-vars
selector:
- app=mysql
namespace: default
command: ["mysql"]
args: ["-ureplicated", "-ppassword", "-e", "show processlist"]
timeout: 60m
- exec:
collectorName: hosts
selector:
- app=graphql-api
namespace: default
command: ["cat"]
args: ["/etc/hosts"]
timeout: 60m
- exec:
collectorName: broken
selector:
- app=graphql-api
namespace: default
command: ["cat"]
args: ["/etc/hostdasddsda"]
timeout: 60m
- http:
collectorName: test-get
get:
url: https://api.staging.replicated.com/market/v1/echo/ip
insecureSkipVerify: false
headers: {}
- http:
collectorName: test-post
post:
url: http://httpbin.org/headers
insecureSkipVerify: false
headers:
X-Custom-Header: "post-request"
- http:
collectorName: test-put
put:
url: http://httpbin.org/anything
insecureSkipVerify: false
headers:
X-Custom-Header: "put-request"
- http:
collectorName: test-broken
put:
url: ""
Loading