-
Notifications
You must be signed in to change notification settings - Fork 92
/
image_pull_secret.go
68 lines (60 loc) · 1.92 KB
/
image_pull_secret.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
57
58
59
60
61
62
63
64
65
66
67
68
package analyzer
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
)
func analyzeImagePullSecret(analyzer *troubleshootv1beta2.ImagePullSecret, getChildCollectedFileContents func(string) (map[string][]byte, error)) (*AnalyzeResult, error) {
imagePullSecrets, err := getChildCollectedFileContents("cluster-resources/image-pull-secrets")
if err != nil {
return nil, errors.Wrap(err, "failed to get file contents for image pull secrets")
}
var failOutcome *troubleshootv1beta2.SingleOutcome
var passOutcome *troubleshootv1beta2.SingleOutcome
for _, outcome := range analyzer.Outcomes {
if outcome.Fail != nil {
failOutcome = outcome.Fail
} else if outcome.Pass != nil {
passOutcome = outcome.Pass
}
}
title := analyzer.CheckName
if title == "" {
title = "Image Pull Secrets"
}
result := AnalyzeResult{
Title: title,
IconKey: "kubernetes_image_pull_secret",
IconURI: "https://troubleshoot.sh/images/analyzer-icons/image-pull-secret.svg?w=16&h=14",
IsFail: true,
}
if failOutcome != nil {
result.Message = failOutcome.Message
result.URI = failOutcome.URI
}
for _, v := range imagePullSecrets {
registryAndUsername := make(map[string]string)
if err := json.Unmarshal(v, ®istryAndUsername); err != nil {
return nil, errors.Wrap(err, "failed to parse registry secret")
}
for registry, _ := range registryAndUsername {
if registry == analyzer.RegistryName {
result.IsPass = true
result.IsFail = false
if passOutcome != nil {
result.Message = passOutcome.Message
result.URI = passOutcome.URI
}
}
}
}
if result.Message == "" {
if result.IsPass {
result.Message = fmt.Sprintf("Credentials to pull from: %s found", analyzer.RegistryName)
} else {
result.Message = fmt.Sprintf("Credentials to pull from: %s not ound", analyzer.RegistryName)
}
}
return &result, nil
}