blob: ef7c88b4444278aa2a07cb842421f4a31a0d66c6 (
plain)
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
|
package image
import (
"strings"
)
// Shamelessly ripped from ArgoCD CLI code
type KustomizeImage string
func (i KustomizeImage) delim() string {
for _, d := range []string{"=", ":", "@"} {
if strings.Contains(string(i), d) {
return d
}
}
return ":"
}
// if the image name matches (i.e. up to the first delimiter)
func (i KustomizeImage) Match(j KustomizeImage) bool {
delim := j.delim()
if !strings.Contains(string(j), delim) {
return false
}
return strings.HasPrefix(string(i), strings.Split(string(j), delim)[0])
}
type KustomizeImages []KustomizeImage
// find the image or -1
func (images KustomizeImages) Find(image KustomizeImage) int {
for i, a := range images {
if a.Match(image) {
return i
}
}
return -1
}
|