Skip to content

Commit

Permalink
config/jobs: fix k8s-infra-prow-build-trusted test
Browse files Browse the repository at this point in the history
Catch the mistake I made, where I added jobs to a trusted path, but
forgot to add them to the trusted cluster.

Old test allowed jobs defined in trusted paths to run on any cluster.

New test verifies jobs defined in trusted paths must run on trusted
cluster, jobs defined anywhere else cannot run on trusted cluster
  • Loading branch information
spiffxp committed Jul 26, 2021
1 parent 4147177 commit 0927e3a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions config/tests/jobs/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ func TestK8sInfraTrusted(t *testing.T) {
}
}

// Postsubmits and periodics must
// - be defined in config/jobs/image-pushing/ and be a valid image-pushing job, OR
// - be defined in config/jobs/kubernetes/wg-k8s-infra/trusted/
// Postsubmits and periodics:
// - jobs in config/jobs/image-pushing must run in cluster: k8s-infra-prow-build-trusted
// - jobs in config/jobs/kubernetes/wg-k8s-infra/trusted must run in cluster: k8s-infra-prow-build-trusted
// - jobs defined anywhere else may not run in cluster: k8s-infra-prow-build-trusted
jobs := []cfg.JobBase{}
for _, job := range c.AllStaticPostsubmits(nil) {
jobs = append(jobs, job.JobBase)
Expand All @@ -342,10 +343,12 @@ func TestK8sInfraTrusted(t *testing.T) {
jobs = append(jobs, job.JobBase)
}
for _, job := range jobs {
if job.Cluster != trusted {
continue
}
if !strings.HasPrefix(job.SourcePath, imagePushingDir) && !strings.HasPrefix(job.SourcePath, trustedPath) {
isTrustedCluster := job.Cluster == trusted
isTrustedPath := strings.HasPrefix(job.SourcePath, imagePushingDir) || strings.HasPrefix(job.SourcePath, trustedPath)
if isTrustedPath && !isTrustedCluster {
jobsToFix++
errs = append(errs, fmt.Errorf("%s defined in %s must run in cluster: %s", job.Name, job.SourcePath, trusted))
} else if isTrustedCluster && !isTrustedPath {
jobsToFix++
errs = append(errs, fmt.Errorf("%s defined in %s may not run in cluster: %s", job.Name, job.SourcePath, trusted))
}
Expand Down

0 comments on commit 0927e3a

Please sign in to comment.