-
Notifications
You must be signed in to change notification settings - Fork 787
/
pjutil.go
37 lines (33 loc) · 1.08 KB
/
pjutil.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
package prow
import (
"github.com/google/uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
prowapi "k8s.io/test-infra/prow/apis/prowjobs/v1"
"k8s.io/test-infra/prow/pod-utils/decorate"
)
// NewProwJob initializes a ProwJob out of a ProwJobSpec.
func NewProwJob(spec prowapi.ProwJobSpec, labels map[string]string) prowapi.ProwJob {
return newProwJob(spec, labels, nil)
}
// TODO pmuir copied and pasted this from prow to avoid a direct dependence on the pjutil.go file,
// and to allow us to upgrade go.uuid
func newProwJob(spec prowapi.ProwJobSpec, extraLabels, extraAnnotations map[string]string) prowapi.ProwJob {
labels, annotations := decorate.LabelsAndAnnotationsForSpec(spec, extraLabels, extraAnnotations)
name := uuid.New()
return prowapi.ProwJob{
TypeMeta: metav1.TypeMeta{
APIVersion: "prow.k8s.io/v1",
Kind: "ProwJob",
},
ObjectMeta: metav1.ObjectMeta{
Name: name.String(),
Labels: labels,
Annotations: annotations,
},
Spec: spec,
Status: prowapi.ProwJobStatus{
StartTime: metav1.Now(),
State: prowapi.TriggeredState,
},
}
}