-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathspec.go
167 lines (133 loc) · 6.02 KB
/
spec.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package spec
import (
"log"
v1 "k8s.io/api/core/v1"
prowjob "sigs.k8s.io/prow/pkg/apis/prowjobs/v1"
"sigs.k8s.io/yaml"
)
// BaseConfig represents the fields that can be defined in a .base.yaml file,
// which is shared by all the meta job config files under the same folder.
type BaseConfig struct {
CommonConfig
AutoMaxProcs bool `json:"auto_max_procs,omitempty"`
AutogenHeader string `json:"autogen_header,omitempty"`
PathAliases map[string]string `json:"path_aliases,omitempty"`
ClusterOverrides map[string]string `json:"cluster_overrides,omitempty"`
TestgridConfig TestgridConfig `json:"testgrid_config,omitempty"`
}
func (baseConfig *BaseConfig) DeepCopy() BaseConfig {
bc, _ := yaml.Marshal(baseConfig)
newBaseConfig := BaseConfig{}
if err := yaml.Unmarshal(bc, &newBaseConfig); err != nil {
log.Fatalf("Failed to unmarshal BaseConfig: %v", err)
}
return newBaseConfig
}
type TestgridConfig struct {
Enabled bool `json:"enabled,omitempty"`
AlertEmail string `json:"alert_email,omitempty"`
NumFailuresToAlert string `json:"num_failures_to_alert,omitempty"`
}
// JobsConfig represents the fields that can be defined in a meta job file, and
// it can contain multiple Jobs.
type JobsConfig struct {
CommonConfig
SupportReleaseBranching bool `json:"support_release_branching,omitempty"`
Repo string `json:"repo,omitempty"`
Org string `json:"org,omitempty"`
CloneURI string `json:"clone_uri,omitempty"`
Branches []string `json:"branches,omitempty"`
Jobs []Job `json:"jobs,omitempty"`
}
// Job is the last layer for defining the actual Prow jobs.
type Job struct {
CommonConfig
DisableReleaseBranching bool `json:"disable_release_branching,omitempty"`
Name string `json:"name,omitempty"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Tags []string `json:"tags,omitempty"`
Types []string `json:"types,omitempty"`
Repos []string `json:"repos,omitempty"`
// Architectures defines architectures to build as. Defaults to amd64.
Architectures []string `json:"architectures,omitempty"`
GerritPresubmitLabel string `json:"gerrit_presubmit_label,omitempty"`
GerritPostsubmitLabel string `json:"gerrit_postsubmit_label,omitempty"`
ReporterConfig *prowjob.ReporterConfig `json:"reporter_config,omitempty"`
}
// CommonConfig contains all the common fields that can be overlayed through
// BaseConfig->JobsConfig->Job
type CommonConfig struct {
GCSLogBucket string `json:"gcs_log_bucket,omitempty"`
TerminationGracePeriodSeconds int64 `json:"termination_grace_period_seconds,omitempty"`
Interval string `json:"interval,omitempty"`
Cron string `json:"cron,omitempty"`
Cluster string `json:"cluster,omitempty"`
NodeSelector map[string]string `json:"node_selector,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Matrix map[string][]string `json:"matrix,omitempty"`
Params map[string]string `json:"params,omitempty"`
ResourcePresets map[string]v1.ResourceRequirements `json:"resources_presets,omitempty"`
RequirementPresets map[string]RequirementPreset `json:"requirement_presets,omitempty"`
Requirements []string `json:"requirements,omitempty"`
ExcludedRequirements []string `json:"excluded_requirements,omitempty"`
Env []v1.EnvVar `json:"env,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"image_pull_policy,omitempty"`
ImagePullSecrets []string `json:"image_pull_secrets,omitempty"`
ServiceAccountName string `json:"service_account_name,omitempty"`
Regex string `json:"regex,omitempty"`
Trigger string `json:"trigger,omitempty"`
Timeout *prowjob.Duration `json:"timeout,omitempty"`
MaxConcurrency int `json:"max_concurrency,omitempty"`
Resources string `json:"resources,omitempty"`
Modifiers []string `json:"modifiers,omitempty"`
}
func (commonConfig *CommonConfig) DeepCopy() CommonConfig {
cc, _ := yaml.Marshal(commonConfig)
newCommonConfig := CommonConfig{}
if err := yaml.Unmarshal(cc, &newCommonConfig); err != nil {
log.Fatalf("Failed to unmarshal CommonConfig: %v", err)
}
return newCommonConfig
}
// RequirementPreset can be used to re-use settings across multiple jobs.
type RequirementPreset struct {
Annotations map[string]string `json:"annotations,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Env []v1.EnvVar `json:"env,omitempty"`
Volumes []v1.Volume `json:"volumes,omitempty"`
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
Args []string `json:"args,omitempty"`
Cron string `json:"cron,omitempty"`
Secrets []Secret `json:"secrets,omitempty"`
PodSpec *v1.PodSpec `json:"podSpec,omitempty"` // Use this field to add extra PodSpec fields except containers and metadata
}
func (r *RequirementPreset) DeepCopy() RequirementPreset {
rp, _ := yaml.Marshal(r)
newRequirementPreset := RequirementPreset{}
if err := yaml.Unmarshal(rp, &newRequirementPreset); err != nil {
log.Fatalf("Failed to unmarshal RequirementPreset: %v", err)
}
return newRequirementPreset
}
type Secret struct {
Name string `json:"secret,omitempty"`
Project string `json:"project,omitempty"`
Env string `json:"env,omitempty"`
File string `json:"file,omitempty"`
}