From d37d037ad140d7d10274bc217f3df2d737fe0a52 Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Thu, 15 Aug 2019 01:22:17 +0000 Subject: [PATCH 1/2] Some fixes to troubleshoot, better error messages --- Makefile | 4 +-- README.md | 2 +- examples/preflight/sample-preflight.yaml | 22 +++++++++++++++- .../troubleshoot/sample-troubleshoot.yaml | 17 +++++------- pkg/analyze/cluster_version.go | 2 +- pkg/apis/addtoscheme_kots_v1beta1.go | 26 +++++++++++++++++++ pkg/collect/cluster_info.go | 9 ++++--- pkg/collect/logs.go | 5 ++-- 8 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 pkg/apis/addtoscheme_kots_v1beta1.go 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/apis/addtoscheme_kots_v1beta1.go b/pkg/apis/addtoscheme_kots_v1beta1.go new file mode 100644 index 00000000..afa9a02b --- /dev/null +++ b/pkg/apis/addtoscheme_kots_v1beta1.go @@ -0,0 +1,26 @@ +/* +Copyright 2019 Replicated, Inc.. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package apis + +import ( + "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) +} 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) } From 0f421ce104a83c20291759886e7504047bc68590 Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Thu, 15 Aug 2019 01:23:38 +0000 Subject: [PATCH 2/2] Remove --- pkg/apis/addtoscheme_kots_v1beta1.go | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 pkg/apis/addtoscheme_kots_v1beta1.go diff --git a/pkg/apis/addtoscheme_kots_v1beta1.go b/pkg/apis/addtoscheme_kots_v1beta1.go deleted file mode 100644 index afa9a02b..00000000 --- a/pkg/apis/addtoscheme_kots_v1beta1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 Replicated, Inc.. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package apis - -import ( - "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) -}