Skip to content

Commit f8e1f11

Browse files
Merge pull request #1130 from SgtCoDFish/trivy-changes
Run trivy tests more often and improve reporting
2 parents 671cef1 + 8eee059 commit f8e1f11

File tree

6 files changed

+66
-33
lines changed

6 files changed

+66
-33
lines changed

config/jobs/cert-manager/cert-manager/master/cert-manager-master.yaml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,10 @@ periodics:
10281028
annotations:
10291029
description: Runs a Trivy scan against the controller container
10301030
testgrid-alert-email: [email protected]
1031-
testgrid-alert-stale-results-hours: "36"
1031+
testgrid-alert-stale-results-hours: "18"
10321032
testgrid-create-job-group: "true"
10331033
testgrid-dashboards: cert-manager-periodics-master
1034+
testgrid-num-columns-recent: "1"
10341035
testgrid-num-failures-to-alert: "1"
10351036
labels:
10361037
preset-dind-enabled: "true"
@@ -1061,16 +1062,17 @@ periodics:
10611062
- org: cert-manager
10621063
repo: cert-manager
10631064
base_ref: master
1064-
cron: 48 11-23/24 * * *
1065+
cron: 48 02-23/12 * * *
10651066
- name: ci-cert-manager-master-trivy-test-acmesolver
10661067
max_concurrency: 2
10671068
decorate: true
10681069
annotations:
10691070
description: Runs a Trivy scan against the acmesolver container
10701071
testgrid-alert-email: [email protected]
1071-
testgrid-alert-stale-results-hours: "36"
1072+
testgrid-alert-stale-results-hours: "18"
10721073
testgrid-create-job-group: "true"
10731074
testgrid-dashboards: cert-manager-periodics-master
1075+
testgrid-num-columns-recent: "1"
10741076
testgrid-num-failures-to-alert: "1"
10751077
labels:
10761078
preset-dind-enabled: "true"
@@ -1101,16 +1103,17 @@ periodics:
11011103
- org: cert-manager
11021104
repo: cert-manager
11031105
base_ref: master
1104-
cron: 52 18-23/24 * * *
1106+
cron: 52 04-23/12 * * *
11051107
- name: ci-cert-manager-master-trivy-test-startupapicheck
11061108
max_concurrency: 2
11071109
decorate: true
11081110
annotations:
11091111
description: Runs a Trivy scan against the startupapicheck container
11101112
testgrid-alert-email: [email protected]
1111-
testgrid-alert-stale-results-hours: "36"
1113+
testgrid-alert-stale-results-hours: "18"
11121114
testgrid-create-job-group: "true"
11131115
testgrid-dashboards: cert-manager-periodics-master
1116+
testgrid-num-columns-recent: "1"
11141117
testgrid-num-failures-to-alert: "1"
11151118
labels:
11161119
preset-dind-enabled: "true"
@@ -1141,16 +1144,17 @@ periodics:
11411144
- org: cert-manager
11421145
repo: cert-manager
11431146
base_ref: master
1144-
cron: 56 01-23/24 * * *
1147+
cron: 56 06-23/12 * * *
11451148
- name: ci-cert-manager-master-trivy-test-cainjector
11461149
max_concurrency: 2
11471150
decorate: true
11481151
annotations:
11491152
description: Runs a Trivy scan against the cainjector container
11501153
testgrid-alert-email: [email protected]
1151-
testgrid-alert-stale-results-hours: "36"
1154+
testgrid-alert-stale-results-hours: "18"
11521155
testgrid-create-job-group: "true"
11531156
testgrid-dashboards: cert-manager-periodics-master
1157+
testgrid-num-columns-recent: "1"
11541158
testgrid-num-failures-to-alert: "1"
11551159
labels:
11561160
preset-dind-enabled: "true"
@@ -1181,16 +1185,17 @@ periodics:
11811185
- org: cert-manager
11821186
repo: cert-manager
11831187
base_ref: master
1184-
cron: 00 08-23/24 * * *
1188+
cron: 00 08-23/12 * * *
11851189
- name: ci-cert-manager-master-trivy-test-webhook
11861190
max_concurrency: 2
11871191
decorate: true
11881192
annotations:
11891193
description: Runs a Trivy scan against the webhook container
11901194
testgrid-alert-email: [email protected]
1191-
testgrid-alert-stale-results-hours: "36"
1195+
testgrid-alert-stale-results-hours: "18"
11921196
testgrid-create-job-group: "true"
11931197
testgrid-dashboards: cert-manager-periodics-master
1198+
testgrid-num-columns-recent: "1"
11941199
testgrid-num-failures-to-alert: "1"
11951200
labels:
11961201
preset-dind-enabled: "true"
@@ -1221,4 +1226,4 @@ periodics:
12211226
- org: cert-manager
12221227
repo: cert-manager
12231228
base_ref: master
1224-
cron: 04 15-23/24 * * *
1229+
cron: 04 10-23/12 * * *

config/jobs/cert-manager/cert-manager/release-1.18/cert-manager-release-1.18.yaml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,10 @@ periodics:
11231123
annotations:
11241124
description: Runs a Trivy scan against the controller container
11251125
testgrid-alert-email: [email protected]
1126-
testgrid-alert-stale-results-hours: "36"
1126+
testgrid-alert-stale-results-hours: "18"
11271127
testgrid-create-job-group: "true"
11281128
testgrid-dashboards: cert-manager-periodics-release-1.18
1129+
testgrid-num-columns-recent: "1"
11291130
testgrid-num-failures-to-alert: "1"
11301131
labels:
11311132
preset-dind-enabled: "true"
@@ -1156,16 +1157,17 @@ periodics:
11561157
- org: cert-manager
11571158
repo: cert-manager
11581159
base_ref: release-1.18
1159-
cron: 57 19-23/24 * * *
1160+
cron: 57 03-23/12 * * *
11601161
- name: ci-cert-manager-release-1.18-trivy-test-acmesolver
11611162
max_concurrency: 2
11621163
decorate: true
11631164
annotations:
11641165
description: Runs a Trivy scan against the acmesolver container
11651166
testgrid-alert-email: [email protected]
1166-
testgrid-alert-stale-results-hours: "36"
1167+
testgrid-alert-stale-results-hours: "18"
11671168
testgrid-create-job-group: "true"
11681169
testgrid-dashboards: cert-manager-periodics-release-1.18
1170+
testgrid-num-columns-recent: "1"
11691171
testgrid-num-failures-to-alert: "1"
11701172
labels:
11711173
preset-dind-enabled: "true"
@@ -1196,16 +1198,17 @@ periodics:
11961198
- org: cert-manager
11971199
repo: cert-manager
11981200
base_ref: release-1.18
1199-
cron: 01 02-23/24 * * *
1201+
cron: 01 05-23/12 * * *
12001202
- name: ci-cert-manager-release-1.18-trivy-test-startupapicheck
12011203
max_concurrency: 2
12021204
decorate: true
12031205
annotations:
12041206
description: Runs a Trivy scan against the startupapicheck container
12051207
testgrid-alert-email: [email protected]
1206-
testgrid-alert-stale-results-hours: "36"
1208+
testgrid-alert-stale-results-hours: "18"
12071209
testgrid-create-job-group: "true"
12081210
testgrid-dashboards: cert-manager-periodics-release-1.18
1211+
testgrid-num-columns-recent: "1"
12091212
testgrid-num-failures-to-alert: "1"
12101213
labels:
12111214
preset-dind-enabled: "true"
@@ -1236,16 +1239,17 @@ periodics:
12361239
- org: cert-manager
12371240
repo: cert-manager
12381241
base_ref: release-1.18
1239-
cron: 05 09-23/24 * * *
1242+
cron: 05 07-23/12 * * *
12401243
- name: ci-cert-manager-release-1.18-trivy-test-cainjector
12411244
max_concurrency: 2
12421245
decorate: true
12431246
annotations:
12441247
description: Runs a Trivy scan against the cainjector container
12451248
testgrid-alert-email: [email protected]
1246-
testgrid-alert-stale-results-hours: "36"
1249+
testgrid-alert-stale-results-hours: "18"
12471250
testgrid-create-job-group: "true"
12481251
testgrid-dashboards: cert-manager-periodics-release-1.18
1252+
testgrid-num-columns-recent: "1"
12491253
testgrid-num-failures-to-alert: "1"
12501254
labels:
12511255
preset-dind-enabled: "true"
@@ -1276,16 +1280,17 @@ periodics:
12761280
- org: cert-manager
12771281
repo: cert-manager
12781282
base_ref: release-1.18
1279-
cron: 09 16-23/24 * * *
1283+
cron: 09 09-23/12 * * *
12801284
- name: ci-cert-manager-release-1.18-trivy-test-webhook
12811285
max_concurrency: 2
12821286
decorate: true
12831287
annotations:
12841288
description: Runs a Trivy scan against the webhook container
12851289
testgrid-alert-email: [email protected]
1286-
testgrid-alert-stale-results-hours: "36"
1290+
testgrid-alert-stale-results-hours: "18"
12871291
testgrid-create-job-group: "true"
12881292
testgrid-dashboards: cert-manager-periodics-release-1.18
1293+
testgrid-num-columns-recent: "1"
12891294
testgrid-num-failures-to-alert: "1"
12901295
labels:
12911296
preset-dind-enabled: "true"
@@ -1316,4 +1321,4 @@ periodics:
13161321
- org: cert-manager
13171322
repo: cert-manager
13181323
base_ref: release-1.18
1319-
cron: 13 23-23/24 * * *
1324+
cron: 13 11-23/12 * * *

config/jobs/cert-manager/cert-manager/release-1.19/cert-manager-release-1.19.yaml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,10 @@ periodics:
992992
annotations:
993993
description: Runs a Trivy scan against the controller container
994994
testgrid-alert-email: [email protected]
995-
testgrid-alert-stale-results-hours: "36"
995+
testgrid-alert-stale-results-hours: "18"
996996
testgrid-create-job-group: "true"
997997
testgrid-dashboards: cert-manager-periodics-release-1.19
998+
testgrid-num-columns-recent: "1"
998999
testgrid-num-failures-to-alert: "1"
9991000
labels:
10001001
preset-dind-enabled: "true"
@@ -1025,16 +1026,17 @@ periodics:
10251026
- org: cert-manager
10261027
repo: cert-manager
10271028
base_ref: release-1.19
1028-
cron: 50 13-23/24 * * *
1029+
cron: 50 04-23/12 * * *
10291030
- name: ci-cert-manager-release-1.19-trivy-test-acmesolver
10301031
max_concurrency: 2
10311032
decorate: true
10321033
annotations:
10331034
description: Runs a Trivy scan against the acmesolver container
10341035
testgrid-alert-email: [email protected]
1035-
testgrid-alert-stale-results-hours: "36"
1036+
testgrid-alert-stale-results-hours: "18"
10361037
testgrid-create-job-group: "true"
10371038
testgrid-dashboards: cert-manager-periodics-release-1.19
1039+
testgrid-num-columns-recent: "1"
10381040
testgrid-num-failures-to-alert: "1"
10391041
labels:
10401042
preset-dind-enabled: "true"
@@ -1065,16 +1067,17 @@ periodics:
10651067
- org: cert-manager
10661068
repo: cert-manager
10671069
base_ref: release-1.19
1068-
cron: 54 20-23/24 * * *
1070+
cron: 54 06-23/12 * * *
10691071
- name: ci-cert-manager-release-1.19-trivy-test-startupapicheck
10701072
max_concurrency: 2
10711073
decorate: true
10721074
annotations:
10731075
description: Runs a Trivy scan against the startupapicheck container
10741076
testgrid-alert-email: [email protected]
1075-
testgrid-alert-stale-results-hours: "36"
1077+
testgrid-alert-stale-results-hours: "18"
10761078
testgrid-create-job-group: "true"
10771079
testgrid-dashboards: cert-manager-periodics-release-1.19
1080+
testgrid-num-columns-recent: "1"
10781081
testgrid-num-failures-to-alert: "1"
10791082
labels:
10801083
preset-dind-enabled: "true"
@@ -1105,16 +1108,17 @@ periodics:
11051108
- org: cert-manager
11061109
repo: cert-manager
11071110
base_ref: release-1.19
1108-
cron: 58 03-23/24 * * *
1111+
cron: 58 08-23/12 * * *
11091112
- name: ci-cert-manager-release-1.19-trivy-test-cainjector
11101113
max_concurrency: 2
11111114
decorate: true
11121115
annotations:
11131116
description: Runs a Trivy scan against the cainjector container
11141117
testgrid-alert-email: [email protected]
1115-
testgrid-alert-stale-results-hours: "36"
1118+
testgrid-alert-stale-results-hours: "18"
11161119
testgrid-create-job-group: "true"
11171120
testgrid-dashboards: cert-manager-periodics-release-1.19
1121+
testgrid-num-columns-recent: "1"
11181122
testgrid-num-failures-to-alert: "1"
11191123
labels:
11201124
preset-dind-enabled: "true"
@@ -1145,16 +1149,17 @@ periodics:
11451149
- org: cert-manager
11461150
repo: cert-manager
11471151
base_ref: release-1.19
1148-
cron: 02 10-23/24 * * *
1152+
cron: 02 10-23/12 * * *
11491153
- name: ci-cert-manager-release-1.19-trivy-test-webhook
11501154
max_concurrency: 2
11511155
decorate: true
11521156
annotations:
11531157
description: Runs a Trivy scan against the webhook container
11541158
testgrid-alert-email: [email protected]
1155-
testgrid-alert-stale-results-hours: "36"
1159+
testgrid-alert-stale-results-hours: "18"
11561160
testgrid-create-job-group: "true"
11571161
testgrid-dashboards: cert-manager-periodics-release-1.19
1162+
testgrid-num-columns-recent: "1"
11581163
testgrid-num-failures-to-alert: "1"
11591164
labels:
11601165
preset-dind-enabled: "true"
@@ -1185,4 +1190,4 @@ periodics:
11851190
- org: cert-manager
11861191
repo: cert-manager
11871192
base_ref: release-1.19
1188-
cron: 06 17-23/24 * * *
1193+
cron: 06 00-23/12 * * *

config/prowgen/pkg/configurers.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ func addTestGridCustomFailuresToAlert(failuresToAlert int) JobConfigurer {
147147
}
148148
}
149149

150+
// addTestGridNumColumnsRecent changes the number of test results to considered when testgrid
151+
// decides whether a test is "flaky"
152+
// See https://github.com/kubernetes/test-infra/blob/737791c6e2ee79bdc8efce2195eb6d20ebb6eb04/testgrid/config.md#prow-job-configuration
153+
func addTestGridNumColumnsRecent(numColumnsRecent int) JobConfigurer {
154+
return func(job *Job) {
155+
job.Annotations["testgrid-num-columns-recent"] = fmt.Sprintf("%d", numColumnsRecent)
156+
}
157+
}
158+
150159
// addTestGridStaleResultsAlert sets, in hours, the length of time before a job should be
151160
// considered stale. This guards against a job not running for whatever reason.
152161
func addTestGridStaleResultsAlert(hoursUntilStale int) JobConfigurer {

config/prowgen/pkg/generators.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package pkg
1919

2020
import (
2121
"fmt"
22+
"math"
2223
"strings"
2324
)
2425

@@ -328,9 +329,12 @@ func UpgradeTest(ctx *ProwContext, k8sVersion string) *Job {
328329
// so e.g. if there's a vuln in the "controller" container we might never scan "ctl" container.
329330
// Instead, we generate a test for each container so it's obvious which ones have failures and it's easier to get results
330331
// for each container
331-
func TrivyTest(ctx *ProwContext, containerName string) *Job {
332+
// periodicity is the number of hours between runs of this job; this is used to calculate when the job should be considered stale
333+
func TrivyTest(ctx *ProwContext, containerName string, periodicity int) *Job {
332334
containerName = strings.ToLower(containerName)
333335

336+
stale := math.Round(float64(periodicity) * 1.5)
337+
334338
job := jobTemplate(
335339
fmt.Sprintf("trivy-test-%s", containerName),
336340
fmt.Sprintf("Runs a Trivy scan against the %s container", containerName),
@@ -342,9 +346,13 @@ func TrivyTest(ctx *ProwContext, containerName string) *Job {
342346
// Need to ensure that trivy tests send a failure email as soon as they fail since
343347
// they tend to be run relatively infrequently and a failure is important to address
344348
addTestGridCustomFailuresToAlert(1),
349+
// Trivy tests are quite binary - either the scan passes or fails.
350+
// Having a fixed test report as "flaky" isn't helpful, so set "num columns recent" to 1
351+
// so that the test should report as either passing or failing but not flaky.
352+
addTestGridNumColumnsRecent(1),
345353
// Ask TestGrid to alert us if the job hasn't run in the last 36 hours. Sets
346354
// an upper limit on how regularly the job can be scheduled.
347-
addTestGridStaleResultsAlert(36),
355+
addTestGridStaleResultsAlert(int(stale)),
348356
)
349357

350358
makeJobs, cpuRequest := calculateMakeConcurrency("1000m")

config/prowgen/prowspecs/specs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ func (m *BranchSpec) GenerateJobFile() *pkg.JobFile {
167167
}
168168

169169
for _, container := range m.containerNames {
170-
m.prowContext.Periodics(pkg.TrivyTest(m.prowContext, container), 24)
170+
periodicity := 12
171+
m.prowContext.Periodics(pkg.TrivyTest(m.prowContext, container, periodicity), periodicity)
171172
}
172173

173174
return m.prowContext.JobFile()

0 commit comments

Comments
 (0)