forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
76 lines (67 loc) · 2.19 KB
/
util.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package util
import (
"strings"
kapi "k8s.io/kubernetes/pkg/api"
buildapi "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/util/namer"
)
const (
// BuildPodSuffix is the suffix used to append to a build pod name given a build name
BuildPodSuffix = "build"
// NoBuildLogsMessage reports that no build logs are available
NoBuildLogsMessage = "No logs are available."
)
// GetBuildPodName returns name of the build pod.
func GetBuildPodName(build *buildapi.Build) string {
return namer.GetPodName(build.Name, BuildPodSuffix)
}
// GetBuildName returns name of the build pod.
func GetBuildName(pod *kapi.Pod) string {
if pod.Annotations == nil {
return ""
}
return pod.Annotations[buildapi.BuildAnnotation]
}
// GetImageStreamForStrategy returns the ImageStream[Tag/Image] ObjectReference associated
// with the BuildStrategy.
func GetImageStreamForStrategy(strategy buildapi.BuildStrategy) *kapi.ObjectReference {
switch strategy.Type {
case buildapi.SourceBuildStrategyType:
if strategy.SourceStrategy == nil {
return nil
}
return &strategy.SourceStrategy.From
case buildapi.DockerBuildStrategyType:
if strategy.DockerStrategy == nil {
return nil
}
return strategy.DockerStrategy.From
case buildapi.CustomBuildStrategyType:
if strategy.CustomStrategy == nil {
return nil
}
return &strategy.CustomStrategy.From
default:
return nil
}
}
// NameFromImageStream returns a concatenated name representing an ImageStream[Tag/Image]
// reference. If the reference does not contain a Namespace, the namespace parameter
// is used instead.
func NameFromImageStream(namespace string, ref *kapi.ObjectReference, tag string) string {
var ret string
if ref.Namespace == "" {
ret = namespace
} else {
ret = ref.Namespace
}
ret = ret + "/" + ref.Name
if tag != "" && strings.Index(ref.Name, ":") == -1 && strings.Index(ref.Name, "@") == -1 {
ret = ret + ":" + tag
}
return ret
}
// IsBuildComplete returns whether the provided build is complete or not
func IsBuildComplete(build *buildapi.Build) bool {
return build.Status.Phase != buildapi.BuildPhaseRunning && build.Status.Phase != buildapi.BuildPhasePending && build.Status.Phase != buildapi.BuildPhaseNew
}