Skip to content

Commit d98c01a

Browse files
authored
Merge branch 'main' into xav/sc37229/ceph-secrets
2 parents 4acd7e4 + 0996b3b commit d98c01a

File tree

6 files changed

+98
-16
lines changed

6 files changed

+98
-16
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Thank you for your interest in Troubleshoot, we welcome your participation. Plea
1111
To get started we recommend:
1212

1313
1. Go (v1.17 or later)
14-
2. Kubernetes (we recommend https://k3d.io/. requires Docker v20.10.5 or later)
14+
2. A Kubernetes cluster (we recommend https://k3d.io/. This requires Docker v20.10.5 or later)
1515
3. Fork and clone the repo to $GOPATH/src/github.com/replicatedhq/
1616
4. Run `make support-bundle preflight` to generate binaries
1717
5. Run `make run-troubleshoot` to generate a support bundle with the `sample-troubleshoot.yaml` in the root of the repo

pkg/analyze/ceph_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ func Test_cephStatus(t *testing.T) {
219219
}`,
220220
},
221221
{
222-
name: "warn case with multiple health status messages",
222+
name: "warn case with health status message and summary",
223223
analyzer: troubleshootv1beta2.CephStatusAnalyze{},
224224
expectResult: AnalyzeResult{
225225
IsPass: false,
226226
IsWarn: true,
227227
IsFail: false,
228228
Title: "Ceph Status",
229-
Message: "Ceph status is HEALTH_WARN\nPOOL_NO_REDUNDANCY: 11 pool(s) have no replicas configured\nPOOL_PG_NUM_NOT_POWER_OF_TWO: 8 pool(s) have non-power-of-two pg_num",
229+
Message: "Ceph status is HEALTH_WARN\nPOOL_NO_REDUNDANCY: 11 pool(s) have no replicas configured",
230230
URI: "https://rook.io/docs/rook/v1.4/ceph-common-issues.html",
231231
IconKey: "rook",
232232
IconURI: "https://troubleshoot.sh/images/analyzer-icons/rook.svg?w=11&h=16",
@@ -244,12 +244,6 @@ func Test_cephStatus(t *testing.T) {
244244
"count": 11
245245
},
246246
"muted": false
247-
},
248-
"POOL_PG_NUM_NOT_POWER_OF_TWO": {
249-
"severity": "HEALTH_WARN",
250-
"summary": {
251-
"message": "8 pool(s) have non-power-of-two pg_num"
252-
}
253247
}
254248
}
255249
}

pkg/analyze/postgres.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ func analyzePostgres(analyzer *troubleshootv1beta2.DatabaseAnalyze, getCollected
3939
IconURI: "https://troubleshoot.sh/images/analyzer-icons/postgres-analyze.svg",
4040
}
4141

42-
if databaseConnection.Error != "" {
43-
result.IsFail = true
44-
result.Message = databaseConnection.Error
45-
return result, nil
46-
}
47-
4842
for _, outcome := range analyzer.Outcomes {
4943
if outcome.Fail != nil {
5044
if outcome.Fail.When == "" {
@@ -61,8 +55,14 @@ func analyzePostgres(analyzer *troubleshootv1beta2.DatabaseAnalyze, getCollected
6155
}
6256

6357
if isMatch {
58+
59+
if databaseConnection.Error != "" {
60+
result.Message = outcome.Fail.Message + " " + databaseConnection.Error
61+
} else {
62+
result.Message = outcome.Fail.Message
63+
}
64+
6465
result.IsFail = true
65-
result.Message = outcome.Fail.Message
6666
result.URI = outcome.Fail.URI
6767

6868
return result, nil

pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ type HostServices struct {
150150
HostCollectorMeta `json:",inline" yaml:",inline"`
151151
}
152152

153+
type HostRun struct {
154+
HostCollectorMeta `json:",inline" yaml:",inline"`
155+
Command string `json:"command"`
156+
Args []string `json:"args"`
157+
}
158+
153159
type HostCollect struct {
154160
CPU *CPU `json:"cpu,omitempty" yaml:"cpu,omitempty"`
155161
Memory *Memory `json:"memory,omitempty" yaml:"memory,omitempty"`
@@ -169,6 +175,7 @@ type HostCollect struct {
169175
Certificate *Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"`
170176
HostServices *HostServices `json:"hostServices,omitempty" yaml:"hostServices,omitempty"`
171177
HostOS *HostOS `json:"hostOS,omitempty" yaml:"hostOS,omitempty"`
178+
HostRun *HostRun `json:"run,omitempty" yaml:"run,omitempty"`
172179
}
173180

174181
func (c *HostCollect) GetName() string {

pkg/collect/host_collector.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func GetHostCollector(collector *troubleshootv1beta2.HostCollect, bundlePath str
5151
return &CollectHostServices{collector.HostServices, bundlePath}, true
5252
case collector.HostOS != nil:
5353
return &CollectHostOS{collector.HostOS, bundlePath}, true
54+
case collector.HostRun != nil:
55+
return &CollectHostRun{collector.HostRun, bundlePath}, true
5456
default:
5557
return nil, false
5658
}

pkg/collect/host_run.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package collect
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"os/exec"
7+
"path/filepath"
8+
"strings"
9+
10+
"github.com/pkg/errors"
11+
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
12+
)
13+
14+
type HostRunInfo struct {
15+
Command string `json:"command"`
16+
ExitCode string `json:"exitCode"`
17+
Error string `json:"error"`
18+
}
19+
20+
type CollectHostRun struct {
21+
hostCollector *troubleshootv1beta2.HostRun
22+
BundlePath string
23+
}
24+
25+
func (c *CollectHostRun) Title() string {
26+
return hostCollectorTitleOrDefault(c.hostCollector.HostCollectorMeta, "Run Host")
27+
}
28+
29+
func (c *CollectHostRun) IsExcluded() (bool, error) {
30+
return isExcluded(c.hostCollector.Exclude)
31+
}
32+
33+
func (c *CollectHostRun) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
34+
runHostCollector := c.hostCollector
35+
36+
cmd := exec.Command(runHostCollector.Command, runHostCollector.Args...)
37+
38+
var stdout, stderr bytes.Buffer
39+
cmd.Stdout = &stdout
40+
cmd.Stderr = &stderr
41+
42+
runInfo := HostRunInfo{
43+
Command: cmd.String(),
44+
ExitCode: "0",
45+
}
46+
47+
err := cmd.Run()
48+
if err != nil {
49+
if werr, ok := err.(*exec.ExitError); ok {
50+
runInfo.ExitCode = strings.TrimPrefix(werr.Error(), "exit status ")
51+
runInfo.Error = stderr.String()
52+
} else {
53+
return nil, errors.Wrap(err, "failed to run")
54+
}
55+
}
56+
57+
collectorName := c.hostCollector.CollectorName
58+
if collectorName == "" {
59+
collectorName = "run-host"
60+
}
61+
resultInfo := filepath.Join("host-collectors/run-host", collectorName+"-info.json")
62+
result := filepath.Join("host-collectors/run-host", collectorName+".txt")
63+
64+
b, err := json.Marshal(runInfo)
65+
if err != nil {
66+
return nil, errors.Wrap(err, "failed to marshal run host result")
67+
}
68+
69+
output := NewResult()
70+
output.SaveResult(c.BundlePath, resultInfo, bytes.NewBuffer(b))
71+
output.SaveResult(c.BundlePath, result, bytes.NewBuffer(stdout.Bytes()))
72+
73+
runHostOutput := map[string][]byte{
74+
resultInfo: b,
75+
result: stdout.Bytes(),
76+
}
77+
78+
return runHostOutput, nil
79+
}

0 commit comments

Comments
 (0)