/
tracked_container_image.go
38 lines (32 loc) · 1.03 KB
/
tracked_container_image.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
package docker
import (
"regexp"
"github.com/sirupsen/logrus"
)
// execute a custom regex pattern against the container image name
func (tc *TrackedContainer) MatchImageRegex(pattern string) bool {
expr, err := regexp.Compile(pattern)
if err != nil {
panic(err)
}
if expr.MatchString(tc.Container.Image) {
logrus.Debugf(`matching image = "%v" against pattern = "%v": true`, tc.Container.Image, pattern)
return true
} else {
logrus.Debugf(`matching image = "%v" against pattern = "%v": false`, tc.Container.Image, pattern)
}
// match against each tag
for _, tag := range tc.Image.RepoTags {
if expr.MatchString(tag) {
logrus.Debugf(`matching image = "%v" against pattern = "%v": true`, tag, pattern)
return true
} else {
logrus.Debugf(`matching image = "%v" against pattern = "%v": false`, tag, pattern)
}
}
return false
}
// Look for an exact match of the image but ignore the tag
func (tc *TrackedContainer) MatchImage(pattern string) bool {
return tc.MatchImageRegex("^" + regexp.QuoteMeta(pattern) + "(:.*)?$")
}