-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem-image-pull-policy.go
43 lines (37 loc) · 1.18 KB
/
item-image-pull-policy.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
package main
import "strings"
type ItemImagePullPolicy struct {
name, description, kind string
}
func (iipp *ItemImagePullPolicy) Name() string {
return iipp.name
}
func (iipp *ItemImagePullPolicy) Description() string {
return iipp.description
}
func (iipp *ItemImagePullPolicy) Kind() string {
return iipp.kind
}
func (iipp *ItemImagePullPolicy) Lint(config *Config, params LinterParams) (ResultMap, error) {
resultImagePullPolicy := make(ResultMap)
var problem string
for _, item := range config.Items {
if item.Kind != iipp.Kind() {
continue
}
if item.Spec != nil && item.Spec.Template != nil {
for _, container := range item.Spec.Template.Spec.Containers {
name := container.Name
if container.ImagePullPolicy == "Always" {
problem = "always"
resultImagePullPolicy[problem] = append(resultImagePullPolicy[problem], ContainerSpec{item.Metadata.Namespace, item.Metadata.Name, name})
}
if strings.HasSuffix(container.Image, ":latest") {
problem = "latest"
resultImagePullPolicy[problem] = append(resultImagePullPolicy[problem], ContainerSpec{item.Metadata.Namespace, item.Metadata.Name, name})
}
}
}
}
return resultImagePullPolicy, nil
}