-
Notifications
You must be signed in to change notification settings - Fork 250
/
imagestream.go
60 lines (55 loc) · 1.73 KB
/
imagestream.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
package util
import (
"fmt"
"strings"
imageapi "github.com/openshift/api/image/v1"
"github.com/openshift/ci-tools/pkg/api"
)
// ParseImageStreamTagReference creates a reference from an "is:tag" string.
func ParseImageStreamTagReference(s string) (api.ImageStreamTagReference, error) {
var ret api.ImageStreamTagReference
i := strings.LastIndex(s, ":")
if i == -1 {
return ret, fmt.Errorf("invalid ImageStreamTagReference: %s", s)
}
ret.Name = s[:i]
ret.Tag = s[i+1:]
if strings.Contains(ret.Name, ":") {
return ret, fmt.Errorf("invalid ImageStreamTagReference: %s", s)
}
return ret, nil
}
// ResolvePullSpec if a tag of an imagestream is resolved
func ResolvePullSpec(is *imageapi.ImageStream, tag string, requireExact bool) (string, bool, imageapi.TagEventCondition) {
var condition imageapi.TagEventCondition
for _, tags := range is.Status.Tags {
if tags.Tag != tag {
continue
}
if conditions := tags.Conditions; len(conditions) > 0 {
condition = conditions[0]
}
if len(tags.Items) == 0 {
break
}
if image := tags.Items[0].Image; len(image) > 0 {
if len(is.Status.PublicDockerImageRepository) > 0 {
return fmt.Sprintf("%s@%s", is.Status.PublicDockerImageRepository, image), true, condition
}
if len(is.Status.DockerImageRepository) > 0 {
return fmt.Sprintf("%s@%s", is.Status.DockerImageRepository, image), true, condition
}
}
break
}
if requireExact {
return "", false, condition
}
if len(is.Status.PublicDockerImageRepository) > 0 {
return fmt.Sprintf("%s:%s", is.Status.PublicDockerImageRepository, tag), true, condition
}
if len(is.Status.DockerImageRepository) > 0 {
return fmt.Sprintf("%s:%s", is.Status.DockerImageRepository, tag), true, condition
}
return "", false, condition
}