diff --git a/Makefile b/Makefile index 48dddf53..8fe9cdac 100644 --- a/Makefile +++ b/Makefile @@ -101,11 +101,11 @@ run-preflight: preflight ./bin/preflight \ --image=localhost:32000/troubleshoot:alpha \ --pullpolicy=Always \ - ./config/samples/troubleshoot_v1beta1_preflight.yaml + ./examples/preflight/sample-preflight.yaml .PHONY: run-troubleshoot run-troubleshoot: support-bundle ./bin/support-bundle \ --image=localhost:32000/troubleshoot:alpha \ --pullpolicy=Always \ - ./config/samples/troubleshoot_v1beta1_collector.yaml + ./examples/troubleshoot/sample-troubleshoot.yaml diff --git a/README.md b/README.md index e6bbd130..90cb0e33 100644 --- a/README.md +++ b/README.md @@ -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](https://help.replicated.com/docs/troubleshoot/kubernetes/support-bundle/collecting/) and run: ```shell -kubectl troubleshoot https://troubleshoot.replicated.com +kubectl support-bundle https://troubleshoot.replicated.com ``` diff --git a/examples/preflight/sample-preflight.yaml b/examples/preflight/sample-preflight.yaml index f03c58cc..3c48ecf2 100644 --- a/examples/preflight/sample-preflight.yaml +++ b/examples/preflight/sample-preflight.yaml @@ -3,6 +3,12 @@ kind: Preflight metadata: name: example-preflight-checks spec: + collectors: + - secret: + name: myapp-postgres + namespace: default + key: uri + includeValue: false analyzers: - clusterVersion: outcomes: @@ -15,13 +21,15 @@ spec: message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.15.0 or later. uri: https://kubernetes.io - pass: + when: ">= 1.15.0" message: Your cluster meets the recommended and required versions of Kubernetes. - customResourceDefinition: customResourceDefinitionName: constrainttemplates.templates.gatekeeper.sh - checkName: Gatekeeper policy runtime is installed + checkName: Gatekeeper policy runtime outcomes: - fail: message: Gatekeeper is required for the application, but not found in the cluster. + uri: https://enterprise.support.io/installing/gatekeeper - pass: message: Found a supported version of Gatekeeper installed and running in the cluster. - imagePullSecret: @@ -31,5 +39,17 @@ spec: - fail: message: | Cannot pull from quay.io. An image pull secret should be deployed to the cluster that has credentials to pull the images. To obtain this secret, please contact your support rep. + uri: https://enterprise.support.io/installing/registry-credentials - pass: message: Found credentials to pull from quay.io + - secret: + checkName: Postgres connection string + secretName: myapp-postgres + namespace: default + key: uri + outcomes: + - fail: + message: A secret named "myapp-postgres" must be deployed with a "uri" key + uri: https://enterprise.support.io/installing/postgres + - pass: + message: Found a valid postgres connection string diff --git a/examples/troubleshoot/sample-troubleshoot.yaml b/examples/troubleshoot/sample-troubleshoot.yaml index 2379cee9..094701ae 100644 --- a/examples/troubleshoot/sample-troubleshoot.yaml +++ b/examples/troubleshoot/sample-troubleshoot.yaml @@ -3,16 +3,15 @@ kind: Collector metadata: name: collector-sample spec: - - clusterInfo: {} - - clusterResources: {} - secret: - name: illmannered-cricket-mysql + name: myapp-postgres namespace: default - key: mysql-password + key: uri + includeValue: false - logs: selector: - - name=nginx-ingress-microk8s - namespace: default + - name=cilium-operator + namespace: kube-system limits: maxAge: 30d maxLines: 10000 @@ -24,8 +23,6 @@ spec: args: ["www.google.com"] timeout: 5s - http: - collectorName: test-get + collectorName: echo-ip get: - url: https://api.staging.replicated.com/market/v1/echo/ip - insecureSkipVerify: false - headers: {} + url: https://api.replicated.com/market/v1/echo/ip diff --git a/pkg/analyze/cluster_version.go b/pkg/analyze/cluster_version.go index 09e185a8..fbe6be27 100644 --- a/pkg/analyze/cluster_version.go +++ b/pkg/analyze/cluster_version.go @@ -13,7 +13,7 @@ import ( func analyzeClusterVersion(analyzer *troubleshootv1beta1.ClusterVersion, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) { clusterInfo, err := getCollectedFileContents("cluster-info/cluster_version.json") if err != nil { - return nil, errors.Wrap(err, "failed top get contents of cluster_version.json") + return nil, errors.Wrap(err, "failed to get contents of cluster_version.json") } collectorClusterVersion := collect.ClusterVersion{} diff --git a/pkg/collect/cluster_info.go b/pkg/collect/cluster_info.go index bb19b5e5..bc7d0ade 100644 --- a/pkg/collect/cluster_info.go +++ b/pkg/collect/cluster_info.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/pkg/errors" "k8s.io/apimachinery/pkg/version" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/client/config" @@ -22,12 +23,12 @@ type ClusterInfoOutput struct { func ClusterInfo() error { cfg, err := config.GetConfig() if err != nil { - return err + return errors.Wrap(err, "failed to get kubernetes config") } client, err := kubernetes.NewForConfig(cfg) if err != nil { - return err + return errors.Wrap(err, "Failed to create kuberenetes clientset") } clusterInfoOutput := ClusterInfoOutput{} @@ -37,12 +38,12 @@ func ClusterInfo() error { clusterInfoOutput.ClusterVersion = clusterVersion clusterInfoOutput.Errors, err = marshalNonNil(clusterErrors) if err != nil { - return err + return errors.Wrap(err, "failed to marshal errors") } b, err := json.MarshalIndent(clusterInfoOutput, "", " ") if err != nil { - return err + return errors.Wrap(err, "failed to marshal cluster info") } fmt.Printf("%s\n", b) diff --git a/pkg/collect/logs.go b/pkg/collect/logs.go index 455f5ff9..8795c475 100644 --- a/pkg/collect/logs.go +++ b/pkg/collect/logs.go @@ -34,6 +34,7 @@ func Logs(logsCollector *troubleshootv1beta1.Logs, redact bool) error { logsOutput := &LogsOutput{ PodLogs: make(map[string][]byte), + Errors: make(map[string][]byte), } pods, podsErrors := listPodsInSelectors(client, logsCollector.Namespace, logsCollector.Selector) @@ -42,7 +43,7 @@ func Logs(logsCollector *troubleshootv1beta1.Logs, redact bool) error { if err != nil { return err } - logsOutput.Errors[getLogsErrosFileName(logsCollector)] = errorBytes + logsOutput.Errors[getLogsErrorsFileName(logsCollector)] = errorBytes } if len(pods) > 0 { @@ -150,7 +151,7 @@ func (l *LogsOutput) Redact() (*LogsOutput, error) { }, nil } -func getLogsErrosFileName(logsCollector *troubleshootv1beta1.Logs) string { +func getLogsErrorsFileName(logsCollector *troubleshootv1beta1.Logs) string { if len(logsCollector.CollectorName) > 0 { return fmt.Sprintf("%s.json", logsCollector.CollectorName) }