mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
* Add collect command and remote host collectors
Adds the ability to run a host collector on a set of remote k8s nodes.
Target nodes can be filtered using the --selector flag, with the same
syntax as kubectl. Existing flags for --collector-image,
--collector-pullpolicy and --request-timeout are used. To run on a
specified node, --selector="kubernetes.io/hostname=kind-worker2" could
be used.
The collect command is used by the remote collector to output the
results using a "raw" format, which uses the filename as the key, and
the value the output as a escaped json string. When run manually it
defaults to fully decoded json. The existing block devices,
ipv4interfaces and services host collectors don't decode properly - the
fix is to convert their slice output to a map (fix not included as
unsure what depends on the existing format).
The collect command is also useful for troubleshooting preflight issues.
Examples are included to show remote collector usage.
```
bin/collect --collector-image=croomes/troubleshoot:latest examples/collect/remote/memory.yaml --namespace test
{
"kind-control-plane": {
"system/memory.json": {
"total": 1304207360
}
},
"kind-worker": {
"system/memory.json": {
"total": 1695780864
}
},
"kind-worker2": {
"system/memory.json": {
"total": 1726353408
}
}
}
```
The preflight command has been updated to run remote collectors. To run
a host collector remotely it must be specified in the spec as a
`remoteCollector`:
```
apiVersion: troubleshoot.sh/v1beta2
kind: HostPreflight
metadata:
name: memory
spec:
remoteCollectors:
- memory:
collectorName: memory
analyzers:
- memory:
outcomes:
- fail:
when: "< 8Gi"
message: At least 8Gi of memory is required
- warn:
when: "< 32Gi"
message: At least 32Gi of memory is recommended
- pass:
message: The system has as sufficient memory
```
Results for each node are analyzed separately, with the node name
appended to the title:
```
bin/preflight --interactive=false --collector-image=croomes/troubleshoot:latest examples/preflight/remote/memory.yaml --format=json
{memory running 0 1}
{memory completed 1 1}
{
"fail": [
{
"title": "Amount of Memory (kind-worker2)",
"message": "At least 8Gi of memory is required"
},
{
"title": "Amount of Memory (kind-worker)",
"message": "At least 8Gi of memory is required"
},
{
"title": "Amount of Memory (kind-control-plane)",
"message": "At least 8Gi of memory is required"
}
]
}
```
Also added a host collector to allow preflight checks of required kernel
modules, which is the main driver for this change.
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
|
|
"github.com/replicatedhq/troubleshoot/pkg/logger"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func RootCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "collect [url]",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Short: "Run a collector",
|
|
Long: `Run a collector and output the results.`,
|
|
SilenceUsage: true,
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
viper.BindPFlags(cmd.Flags())
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
v := viper.GetViper()
|
|
|
|
logger.SetQuiet(v.GetBool("quiet"))
|
|
return runCollect(v, args[0])
|
|
},
|
|
}
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
cmd.AddCommand(VersionCmd())
|
|
|
|
cmd.Flags().StringSlice("redactors", []string{}, "names of the additional redactors to use")
|
|
cmd.Flags().Bool("redact", true, "enable/disable default redactions")
|
|
cmd.Flags().String("format", "json", "output format, one of json or raw.")
|
|
cmd.Flags().String("collector-image", "", "the full name of the collector image to use")
|
|
cmd.Flags().String("collector-pull-policy", "", "the pull policy of the collector image")
|
|
cmd.Flags().String("selector", "", "selector (label query) to filter remote collection nodes on.")
|
|
cmd.Flags().Bool("collect-without-permissions", false, "always generate a support bundle, even if it some require additional permissions")
|
|
|
|
// hidden in favor of the `insecure-skip-tls-verify` flag
|
|
cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results")
|
|
cmd.Flags().MarkHidden("allow-insecure-connections")
|
|
|
|
viper.BindPFlags(cmd.Flags())
|
|
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
|
|
|
k8sutil.AddFlags(cmd.Flags())
|
|
|
|
return cmd
|
|
}
|
|
|
|
func InitAndExecute() {
|
|
if err := RootCmd().Execute(); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func initConfig() {
|
|
viper.SetEnvPrefix("TROUBLESHOOT")
|
|
viper.AutomaticEnv()
|
|
}
|