Skip to content

Commit

Permalink
feat: goldpinger collector and analyser (replicatedhq#1398)
Browse files Browse the repository at this point in the history
* feat: goldpinger analyser

Analyser to generate a report from goldpinger results

* Add goldpinger testdata

* Goldpinger collector

* Improvements after running tests

* More minor updates after further testing

* Better error message if a container fails to start

* A few more updates

* Add goldpinger e2e test

* Update schemas

* Clean up help installs in e2e tests

* Add resource limits to goldpinger pods

* Some minor improvements

* Some more changes noted when writing docs

* Update schemas

* A few more updates when testing with kURL

* Log goldpinger tests

* Tests before exit code
  • Loading branch information
banjoh authored Dec 12, 2023
1 parent b0907d7 commit 53113c0
Show file tree
Hide file tree
Showing 33 changed files with 1,657 additions and 39 deletions.
51 changes: 51 additions & 0 deletions config/crds/troubleshoot.sh_analyzers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,57 @@ spec:
required:
- outcomes
type: object
goldpinger:
properties:
annotations:
additionalProperties:
type: string
type: object
checkName:
type: string
collectorName:
type: string
exclude:
type: BoolString
filePath:
type: string
outcomes:
items:
properties:
fail:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
pass:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
warn:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
type: object
type: array
strict:
type: BoolString
required:
- collectorName
type: object
imagePullSecret:
properties:
annotations:
Expand Down
29 changes: 29 additions & 0 deletions config/crds/troubleshoot.sh_collectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,35 @@ spec:
- namespace
- selector
type: object
goldpinger:
properties:
collectorName:
type: string
exclude:
type: BoolString
namespace:
type: string
podLaunchOptions:
properties:
image:
type: string
imagePullSecret:
properties:
data:
additionalProperties:
type: string
type: object
name:
type: string
type:
type: string
type: object
namespace:
type: string
serviceAccountName:
type: string
type: object
type: object
helm:
properties:
collectorName:
Expand Down
80 changes: 80 additions & 0 deletions config/crds/troubleshoot.sh_preflights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,57 @@ spec:
required:
- outcomes
type: object
goldpinger:
properties:
annotations:
additionalProperties:
type: string
type: object
checkName:
type: string
collectorName:
type: string
exclude:
type: BoolString
filePath:
type: string
outcomes:
items:
properties:
fail:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
pass:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
warn:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
type: object
type: array
strict:
type: BoolString
required:
- collectorName
type: object
imagePullSecret:
properties:
annotations:
Expand Down Expand Up @@ -1828,6 +1879,35 @@ spec:
- namespace
- selector
type: object
goldpinger:
properties:
collectorName:
type: string
exclude:
type: BoolString
namespace:
type: string
podLaunchOptions:
properties:
image:
type: string
imagePullSecret:
properties:
data:
additionalProperties:
type: string
type: object
name:
type: string
type:
type: string
type: object
namespace:
type: string
serviceAccountName:
type: string
type: object
type: object
helm:
properties:
collectorName:
Expand Down
80 changes: 80 additions & 0 deletions config/crds/troubleshoot.sh_supportbundles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,57 @@ spec:
required:
- outcomes
type: object
goldpinger:
properties:
annotations:
additionalProperties:
type: string
type: object
checkName:
type: string
collectorName:
type: string
exclude:
type: BoolString
filePath:
type: string
outcomes:
items:
properties:
fail:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
pass:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
warn:
properties:
message:
type: string
uri:
type: string
when:
type: string
type: object
type: object
type: array
strict:
type: BoolString
required:
- collectorName
type: object
imagePullSecret:
properties:
annotations:
Expand Down Expand Up @@ -1859,6 +1910,35 @@ spec:
- namespace
- selector
type: object
goldpinger:
properties:
collectorName:
type: string
exclude:
type: BoolString
namespace:
type: string
podLaunchOptions:
properties:
image:
type: string
imagePullSecret:
properties:
data:
additionalProperties:
type: string
type: object
name:
type: string
type:
type: string
type: object
namespace:
type: string
serviceAccountName:
type: string
type: object
type: object
helm:
properties:
collectorName:
Expand Down
21 changes: 15 additions & 6 deletions internal/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ import (

func GetTestFixture(t *testing.T, path string) string {
t.Helper()
p := path
if !filepath.IsAbs(path) {
p = filepath.Join("../../testdata", path)
}
b, err := os.ReadFile(p)

b, err := os.ReadFile(TestFixtureFilePath(t, path))
require.NoError(t, err)
return string(b)
}

// FileDir returns the directory of the current source file.
func TestFixtureFilePath(t *testing.T, path string) string {
t.Helper()

if !filepath.IsAbs(path) {
p, err := filepath.Abs(filepath.Join(FileDir(), "../../testdata", path))
require.NoError(t, err)
return p
} else {
return path
}
}

// FileDir returns the directory of this source file
func FileDir() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Dir(filename)
Expand Down
12 changes: 12 additions & 0 deletions internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ func Append[T any](target []T, src []T) []T {
}
return append(target, src...)
}

// IsInCluster returns true if the code is running within a process
// inside a kubernetes pod
func IsInCluster() bool {
// This is a best effort check, it's not guaranteed to be accurate
host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT")
if len(host) == 0 || len(port) == 0 {
return false
}

return true
}
2 changes: 2 additions & 0 deletions pkg/analyze/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func getAnalyzer(analyzer *troubleshootv1beta2.Analyze) Analyzer {
return &AnalyzeClusterResource{analyzer: analyzer.ClusterResource}
case analyzer.Certificates != nil:
return &AnalyzeCertificates{analyzer: analyzer.Certificates}
case analyzer.Goldpinger != nil:
return &AnalyzeGoldpinger{analyzer: analyzer.Goldpinger}
default:
return nil
}
Expand Down
Loading

0 comments on commit 53113c0

Please sign in to comment.