github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/prow/kube/prowjob.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package kube 18 19 import ( 20 "fmt" 21 "strings" 22 "time" 23 ) 24 25 type ProwJobType string 26 type ProwJobState string 27 type ProwJobAgent string 28 29 const ( 30 PresubmitJob ProwJobType = "presubmit" 31 PostsubmitJob = "postsubmit" 32 PeriodicJob = "periodic" 33 BatchJob = "batch" 34 ) 35 36 const ( 37 TriggeredState ProwJobState = "triggered" 38 PendingState = "pending" 39 SuccessState = "success" 40 FailureState = "failure" 41 AbortedState = "aborted" 42 ErrorState = "error" 43 ) 44 45 const ( 46 KubernetesAgent ProwJobAgent = "kubernetes" 47 JenkinsAgent = "jenkins" 48 ) 49 50 // CreatedByProw is added on pods created by prow. We cannot 51 // really use owner references because pods may reside on a 52 // different namespace from the namespace parent prowjobs 53 // live and that would cause the k8s garbage collector to 54 // identify those prow pods as orphans and delete them 55 // instantly. 56 const CreatedByProw = "created-by-prow" 57 58 type ProwJob struct { 59 APIVersion string `json:"apiVersion,omitempty"` 60 Kind string `json:"kind,omitempty"` 61 Metadata ObjectMeta `json:"metadata,omitempty"` 62 Spec ProwJobSpec `json:"spec,omitempty"` 63 Status ProwJobStatus `json:"status,omitempty"` 64 } 65 66 type ProwJobSpec struct { 67 Type ProwJobType `json:"type,omitempty"` 68 Agent ProwJobAgent `json:"agent,omitempty"` 69 Job string `json:"job,omitempty"` 70 Refs Refs `json:"refs,omitempty"` 71 72 Report bool `json:"report,omitempty"` 73 Context string `json:"context,omitempty"` 74 RerunCommand string `json:"rerun_command,omitempty"` 75 MaxConcurrency int `json:"max_concurrency,omitempty"` 76 77 PodSpec PodSpec `json:"pod_spec,omitempty"` 78 79 RunAfterSuccess []ProwJobSpec `json:"run_after_success,omitempty"` 80 } 81 82 type ProwJobStatus struct { 83 StartTime time.Time `json:"startTime,omitempty"` 84 CompletionTime time.Time `json:"completionTime,omitempty"` 85 State ProwJobState `json:"state,omitempty"` 86 Description string `json:"description,omitempty"` 87 URL string `json:"url,omitempty"` 88 PodName string `json:"pod_name,omitempty"` 89 BuildID string `json:"build_id,omitempty"` 90 } 91 92 func (j *ProwJob) Complete() bool { 93 return !j.Status.CompletionTime.IsZero() 94 } 95 96 type Pull struct { 97 Number int `json:"number,omitempty"` 98 Author string `json:"author,omitempty"` 99 SHA string `json:"sha,omitempty"` 100 } 101 102 type Refs struct { 103 Org string `json:"org,omitempty"` 104 Repo string `json:"repo,omitempty"` 105 106 BaseRef string `json:"base_ref,omitempty"` 107 BaseSHA string `json:"base_sha,omitempty"` 108 109 Pulls []Pull `json:"pulls,omitempty"` 110 } 111 112 func (r Refs) String() string { 113 rs := []string{fmt.Sprintf("%s:%s", r.BaseRef, r.BaseSHA)} 114 for _, pull := range r.Pulls { 115 rs = append(rs, fmt.Sprintf("%d:%s", pull.Number, pull.SHA)) 116 } 117 return strings.Join(rs, ",") 118 }