Merge pull request #49 from replicatedhq/fixes

Some fixes to troubleshoot, better error messages
This commit is contained in:
Marc Campbell
2019-08-14 20:35:10 -07:00
committed by GitHub
7 changed files with 40 additions and 21 deletions
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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
```
+21 -1
View File
@@ -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
+7 -10
View File
@@ -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
+1 -1
View File
@@ -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{}
+5 -4
View File
@@ -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)
+3 -2
View File
@@ -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)
}