-
Notifications
You must be signed in to change notification settings - Fork 93
/
crd.go
56 lines (46 loc) · 1.49 KB
/
crd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package analyzer
import (
"encoding/json"
"fmt"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
)
func analyzeCustomResourceDefinition(analyzer *troubleshootv1beta2.CustomResourceDefinition, getCollectedFileContents func(string) ([]byte, error)) (*AnalyzeResult, error) {
crdData, err := getCollectedFileContents("cluster-resources/custom-resource-definitions.json")
if err != nil {
return nil, err
}
var crds []apiextensionsv1beta1.CustomResourceDefinition
if err := json.Unmarshal(crdData, &crds); err != nil {
return nil, err
}
title := analyzer.CheckName
if title == "" {
title = fmt.Sprintf("Custom resource definition %s", analyzer.CustomResourceDefinitionName)
}
result := AnalyzeResult{
Title: title,
IconKey: "kubernetes_custom_resource_definition",
IconURI: "https://troubleshoot.sh/images/analyzer-icons/custom-resource-definition.svg?w=13&h=16",
}
for _, crd := range crds {
if crd.Name == analyzer.CustomResourceDefinitionName {
result.IsPass = true
for _, outcome := range analyzer.Outcomes {
if outcome.Pass != nil {
result.Message = outcome.Pass.Message
result.URI = outcome.Pass.URI
}
}
return &result, nil
}
}
result.IsFail = true
for _, outcome := range analyzer.Outcomes {
if outcome.Fail != nil {
result.Message = outcome.Fail.Message
result.URI = outcome.Fail.URI
}
}
return &result, nil
}