-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem-registries.go
42 lines (35 loc) · 979 Bytes
/
item-registries.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
package main
import (
"regexp"
)
type ItemRegistries struct {
name, description, kind string
}
func (ir *ItemRegistries) Name() string {
return ir.name
}
func (ir *ItemRegistries) Description() string {
return ir.description
}
func (ir *ItemRegistries) Kind() string {
return ir.kind
}
func (ir *ItemRegistries) Lint(config *Config, params LinterParams) (ResultMap, error) {
resultRegistries := make(ResultMap)
problem := "not whitelisted"
re := regexp.MustCompile(params.WhitelistRegistriesPattern)
for _, item := range config.Items {
if item.Kind != ir.Kind() {
continue
}
if item.Spec != nil && item.Spec.Template != nil {
for _, container := range item.Spec.Template.Spec.Containers {
name := container.Name
if re.FindStringIndex(container.Image) == nil {
resultRegistries[problem] = append(resultRegistries[problem], ContainerSpec{item.Metadata.Namespace, item.Metadata.Name, name})
}
}
}
}
return resultRegistries, nil
}