Skip to content

Commit 91b33b0

Browse files
authored
Merge pull request #49 from replicatedhq/fixes
Some fixes to troubleshoot, better error messages
2 parents e6ecddf + 0f421ce commit 91b33b0

File tree

7 files changed

+40
-21
lines changed

7 files changed

+40
-21
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ run-preflight: preflight
101101
./bin/preflight \
102102
--image=localhost:32000/troubleshoot:alpha \
103103
--pullpolicy=Always \
104-
./config/samples/troubleshoot_v1beta1_preflight.yaml
104+
./examples/preflight/sample-preflight.yaml
105105

106106
.PHONY: run-troubleshoot
107107
run-troubleshoot: support-bundle
108108
./bin/support-bundle \
109109
--image=localhost:32000/troubleshoot:alpha \
110110
--pullpolicy=Always \
111-
./config/samples/troubleshoot_v1beta1_collector.yaml
111+
./examples/troubleshoot/sample-troubleshoot.yaml

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ A support bundle is an archive that's created in-cluster, by collecting logs, cl
1919
To collect a sample support bundle, [install the troubleshoot kubectl plugin](https://help.replicated.com/docs/troubleshoot/kubernetes/support-bundle/collecting/) and run:
2020

2121
```shell
22-
kubectl troubleshoot https://troubleshoot.replicated.com
22+
kubectl support-bundle https://troubleshoot.replicated.com
2323
```

examples/preflight/sample-preflight.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ kind: Preflight
33
metadata:
44
name: example-preflight-checks
55
spec:
6+
collectors:
7+
- secret:
8+
name: myapp-postgres
9+
namespace: default
10+
key: uri
11+
includeValue: false
612
analyzers:
713
- clusterVersion:
814
outcomes:
@@ -15,13 +21,15 @@ spec:
1521
message: Your cluster meets the minimum version of Kubernetes, but we recommend you update to 1.15.0 or later.
1622
uri: https://kubernetes.io
1723
- pass:
24+
when: ">= 1.15.0"
1825
message: Your cluster meets the recommended and required versions of Kubernetes.
1926
- customResourceDefinition:
2027
customResourceDefinitionName: constrainttemplates.templates.gatekeeper.sh
21-
checkName: Gatekeeper policy runtime is installed
28+
checkName: Gatekeeper policy runtime
2229
outcomes:
2330
- fail:
2431
message: Gatekeeper is required for the application, but not found in the cluster.
32+
uri: https://enterprise.support.io/installing/gatekeeper
2533
- pass:
2634
message: Found a supported version of Gatekeeper installed and running in the cluster.
2735
- imagePullSecret:
@@ -31,5 +39,17 @@ spec:
3139
- fail:
3240
message: |
3341
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.
42+
uri: https://enterprise.support.io/installing/registry-credentials
3443
- pass:
3544
message: Found credentials to pull from quay.io
45+
- secret:
46+
checkName: Postgres connection string
47+
secretName: myapp-postgres
48+
namespace: default
49+
key: uri
50+
outcomes:
51+
- fail:
52+
message: A secret named "myapp-postgres" must be deployed with a "uri" key
53+
uri: https://enterprise.support.io/installing/postgres
54+
- pass:
55+
message: Found a valid postgres connection string

examples/troubleshoot/sample-troubleshoot.yaml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ kind: Collector
33
metadata:
44
name: collector-sample
55
spec:
6-
- clusterInfo: {}
7-
- clusterResources: {}
86
- secret:
9-
name: illmannered-cricket-mysql
7+
name: myapp-postgres
108
namespace: default
11-
key: mysql-password
9+
key: uri
10+
includeValue: false
1211
- logs:
1312
selector:
14-
- name=nginx-ingress-microk8s
15-
namespace: default
13+
- name=cilium-operator
14+
namespace: kube-system
1615
limits:
1716
maxAge: 30d
1817
maxLines: 10000
@@ -24,8 +23,6 @@ spec:
2423
args: ["www.google.com"]
2524
timeout: 5s
2625
- http:
27-
collectorName: test-get
26+
collectorName: echo-ip
2827
get:
29-
url: https://api.staging.replicated.com/market/v1/echo/ip
30-
insecureSkipVerify: false
31-
headers: {}
28+
url: https://api.replicated.com/market/v1/echo/ip

pkg/analyze/cluster_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func analyzeClusterVersion(analyzer *troubleshootv1beta1.ClusterVersion, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
1414
clusterInfo, err := getCollectedFileContents("cluster-info/cluster_version.json")
1515
if err != nil {
16-
return nil, errors.Wrap(err, "failed top get contents of cluster_version.json")
16+
return nil, errors.Wrap(err, "failed to get contents of cluster_version.json")
1717
}
1818

1919
collectorClusterVersion := collect.ClusterVersion{}

pkg/collect/cluster_info.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66

7+
"github.com/pkg/errors"
78
"k8s.io/apimachinery/pkg/version"
89
"k8s.io/client-go/kubernetes"
910
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -22,12 +23,12 @@ type ClusterInfoOutput struct {
2223
func ClusterInfo() error {
2324
cfg, err := config.GetConfig()
2425
if err != nil {
25-
return err
26+
return errors.Wrap(err, "failed to get kubernetes config")
2627
}
2728

2829
client, err := kubernetes.NewForConfig(cfg)
2930
if err != nil {
30-
return err
31+
return errors.Wrap(err, "Failed to create kuberenetes clientset")
3132
}
3233

3334
clusterInfoOutput := ClusterInfoOutput{}
@@ -37,12 +38,12 @@ func ClusterInfo() error {
3738
clusterInfoOutput.ClusterVersion = clusterVersion
3839
clusterInfoOutput.Errors, err = marshalNonNil(clusterErrors)
3940
if err != nil {
40-
return err
41+
return errors.Wrap(err, "failed to marshal errors")
4142
}
4243

4344
b, err := json.MarshalIndent(clusterInfoOutput, "", " ")
4445
if err != nil {
45-
return err
46+
return errors.Wrap(err, "failed to marshal cluster info")
4647
}
4748

4849
fmt.Printf("%s\n", b)

pkg/collect/logs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func Logs(logsCollector *troubleshootv1beta1.Logs, redact bool) error {
3434

3535
logsOutput := &LogsOutput{
3636
PodLogs: make(map[string][]byte),
37+
Errors: make(map[string][]byte),
3738
}
3839

3940
pods, podsErrors := listPodsInSelectors(client, logsCollector.Namespace, logsCollector.Selector)
@@ -42,7 +43,7 @@ func Logs(logsCollector *troubleshootv1beta1.Logs, redact bool) error {
4243
if err != nil {
4344
return err
4445
}
45-
logsOutput.Errors[getLogsErrosFileName(logsCollector)] = errorBytes
46+
logsOutput.Errors[getLogsErrorsFileName(logsCollector)] = errorBytes
4647
}
4748

4849
if len(pods) > 0 {
@@ -150,7 +151,7 @@ func (l *LogsOutput) Redact() (*LogsOutput, error) {
150151
}, nil
151152
}
152153

153-
func getLogsErrosFileName(logsCollector *troubleshootv1beta1.Logs) string {
154+
func getLogsErrorsFileName(logsCollector *troubleshootv1beta1.Logs) string {
154155
if len(logsCollector.CollectorName) > 0 {
155156
return fmt.Sprintf("%s.json", logsCollector.CollectorName)
156157
}

0 commit comments

Comments
 (0)