mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
197 lines
4.6 KiB
Go
197 lines
4.6 KiB
Go
package analyzer
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/pkg/errors"
|
|
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
|
"github.com/replicatedhq/troubleshoot/pkg/multitype"
|
|
)
|
|
|
|
type AnalyzeResult struct {
|
|
IsPass bool
|
|
IsFail bool
|
|
IsWarn bool
|
|
|
|
Title string
|
|
Message string
|
|
URI string
|
|
IconKey string
|
|
IconURI string
|
|
}
|
|
|
|
type getCollectedFileContents func(string) ([]byte, error)
|
|
type getChildCollectedFileContents func(string) (map[string][]byte, error)
|
|
|
|
func isExcluded(excludeVal multitype.BoolOrString) (bool, error) {
|
|
if excludeVal.Type == multitype.Bool {
|
|
return excludeVal.BoolVal, nil
|
|
}
|
|
|
|
if excludeVal.StrVal == "" {
|
|
return false, nil
|
|
}
|
|
|
|
parsed, err := strconv.ParseBool(excludeVal.StrVal)
|
|
if err != nil {
|
|
return false, errors.Wrap(err, "failed to parse bool string")
|
|
}
|
|
|
|
return parsed, nil
|
|
}
|
|
|
|
func Analyze(analyzer *troubleshootv1beta1.Analyze, getFile getCollectedFileContents, findFiles getChildCollectedFileContents) (*AnalyzeResult, error) {
|
|
if analyzer.ClusterVersion != nil {
|
|
isExcluded, err := isExcluded(analyzer.ClusterVersion.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeClusterVersion(analyzer.ClusterVersion, getFile)
|
|
}
|
|
if analyzer.StorageClass != nil {
|
|
isExcluded, err := isExcluded(analyzer.StorageClass.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeStorageClass(analyzer.StorageClass, getFile)
|
|
}
|
|
if analyzer.CustomResourceDefinition != nil {
|
|
isExcluded, err := isExcluded(analyzer.CustomResourceDefinition.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeCustomResourceDefinition(analyzer.CustomResourceDefinition, getFile)
|
|
}
|
|
if analyzer.Ingress != nil {
|
|
isExcluded, err := isExcluded(analyzer.Ingress.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeIngress(analyzer.Ingress, getFile)
|
|
}
|
|
if analyzer.Secret != nil {
|
|
isExcluded, err := isExcluded(analyzer.Secret.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeSecret(analyzer.Secret, getFile)
|
|
}
|
|
if analyzer.ImagePullSecret != nil {
|
|
isExcluded, err := isExcluded(analyzer.ImagePullSecret.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeImagePullSecret(analyzer.ImagePullSecret, findFiles)
|
|
}
|
|
if analyzer.DeploymentStatus != nil {
|
|
isExcluded, err := isExcluded(analyzer.DeploymentStatus.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeDeploymentStatus(analyzer.DeploymentStatus, getFile)
|
|
}
|
|
if analyzer.StatefulsetStatus != nil {
|
|
isExcluded, err := isExcluded(analyzer.StatefulsetStatus.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeStatefulsetStatus(analyzer.StatefulsetStatus, getFile)
|
|
}
|
|
if analyzer.ContainerRuntime != nil {
|
|
isExcluded, err := isExcluded(analyzer.ContainerRuntime.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeContainerRuntime(analyzer.ContainerRuntime, getFile)
|
|
}
|
|
if analyzer.Distribution != nil {
|
|
isExcluded, err := isExcluded(analyzer.Distribution.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeDistribution(analyzer.Distribution, getFile)
|
|
}
|
|
if analyzer.NodeResources != nil {
|
|
isExcluded, err := isExcluded(analyzer.NodeResources.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeNodeResources(analyzer.NodeResources, getFile)
|
|
}
|
|
if analyzer.TextAnalyze != nil {
|
|
isExcluded, err := isExcluded(analyzer.TextAnalyze.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeTextAnalyze(analyzer.TextAnalyze, getFile)
|
|
}
|
|
if analyzer.Postgres != nil {
|
|
isExcluded, err := isExcluded(analyzer.Postgres.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzePostgres(analyzer.Postgres, getFile)
|
|
}
|
|
if analyzer.Mysql != nil {
|
|
isExcluded, err := isExcluded(analyzer.Mysql.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeMysql(analyzer.Mysql, getFile)
|
|
}
|
|
if analyzer.Redis != nil {
|
|
isExcluded, err := isExcluded(analyzer.Redis.Exclude)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if isExcluded {
|
|
return nil, nil
|
|
}
|
|
return analyzeRedis(analyzer.Redis, getFile)
|
|
}
|
|
|
|
return nil, errors.New("invalid analyzer")
|
|
}
|