forked from openshift/origin
/
helpers.go
52 lines (46 loc) · 1.78 KB
/
helpers.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
package buildapihelpers
import (
coreinternalapi "k8s.io/kubernetes/pkg/apis/core"
buildinternalapi "github.com/openshift/origin/pkg/build/apis/build"
)
// BuildToPodLogOptions builds a PodLogOptions object out of a BuildLogOptions.
// Currently BuildLogOptions.Container and BuildLogOptions.Previous aren't used
// so they won't be copied to PodLogOptions.
func BuildToPodLogOptions(opts *buildinternalapi.BuildLogOptions) *coreinternalapi.PodLogOptions {
return &coreinternalapi.PodLogOptions{
Follow: opts.Follow,
SinceSeconds: opts.SinceSeconds,
SinceTime: opts.SinceTime,
Timestamps: opts.Timestamps,
TailLines: opts.TailLines,
LimitBytes: opts.LimitBytes,
}
}
// FindTriggerPolicy retrieves the BuildTrigger(s) of a given type from a build configuration.
// Returns nil if no matches are found.
func FindTriggerPolicy(triggerType buildinternalapi.BuildTriggerType, config *buildinternalapi.BuildConfig) (buildTriggers []buildinternalapi.BuildTriggerPolicy) {
for _, specTrigger := range config.Spec.Triggers {
if specTrigger.Type == triggerType {
buildTriggers = append(buildTriggers, specTrigger)
}
}
return buildTriggers
}
func HasTriggerType(triggerType buildinternalapi.BuildTriggerType, bc *buildinternalapi.BuildConfig) bool {
matches := FindTriggerPolicy(triggerType, bc)
return len(matches) > 0
}
// GetInputReference returns the From ObjectReference associated with the
// BuildStrategy.
func GetInputReference(strategy buildinternalapi.BuildStrategy) *coreinternalapi.ObjectReference {
switch {
case strategy.SourceStrategy != nil:
return &strategy.SourceStrategy.From
case strategy.DockerStrategy != nil:
return strategy.DockerStrategy.From
case strategy.CustomStrategy != nil:
return &strategy.CustomStrategy.From
default:
return nil
}
}