Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions pkg/rehearse/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ func ConfigureRehearsalJobs(toBeRehearsed config.Presubmits, ciopConfigs config.
// The job selection is done by iterating in an unspecified order, which avoids picking the same job
// So if a template will be changed, find the jobs that are using a template in combination with the `aws`,`openstack`,`gcs` and `libvirt` cluster types.
func AddRandomJobsForChangedTemplates(templates []config.ConfigMapSource, toBeRehearsed config.Presubmits, prConfigPresubmits map[string][]prowconfig.Presubmit, loggers Loggers, prNumber int) config.Presubmits {
clusterTypes := getClusterTypes(prConfigPresubmits)
rehearsals := make(config.Presubmits)

for _, template := range templates {
templateFile := filepath.Base(template.Filename)
for _, clusterType := range []string{"aws", "gcs", "openstack", "libvirt", "vsphere", "gcp"} {

for _, clusterType := range clusterTypes {
if isAlreadyRehearsed(toBeRehearsed, clusterType, templateFile) {
continue
}
Expand All @@ -261,6 +261,27 @@ func AddRandomJobsForChangedTemplates(templates []config.ConfigMapSource, toBeRe
return rehearsals
}

func getClusterTypes(jobs map[string][]prowconfig.Presubmit) []string {
ret := sets.NewString()
for _, jobs := range jobs {
for _, j := range jobs {
if j.Spec != nil && j.Spec.Containers != nil {
for _, c := range j.Spec.Containers {
for _, e := range c.Env {
if e.Name == clusterTypeEnvName {
ret.Insert(e.Value)
}
}
}
}
}
}
if len(ret) == 0 {
return nil
}
return ret.List()
}

func isAlreadyRehearsed(toBeRehearsed config.Presubmits, clusterType, templateFile string) bool {
for _, jobs := range toBeRehearsed {
for _, job := range jobs {
Expand Down
48 changes: 48 additions & 0 deletions pkg/rehearse/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,3 +961,51 @@ func createVolumesHelper(name, key string) []v1.Volume {

return volumes
}

func TestGetClusterTypes(t *testing.T) {
makeJob := func(clusterType string) prowconfig.Presubmit {
ret := prowconfig.Presubmit{
JobBase: prowconfig.JobBase{
Agent: string(pjapi.KubernetesAgent),
},
}
if clusterType != "" {
ret.Spec = &v1.PodSpec{
Containers: []v1.Container{{
Env: []v1.EnvVar{{
Name: clusterTypeEnvName,
Value: clusterType,
}},
}},
}
}
return ret
}
type Jobs map[string][]prowconfig.Presubmit
for _, tc := range []struct {
id string
jobs Jobs
want []string
}{{
id: "no types",
jobs: Jobs{"org/repo": {makeJob("")}},
}, {
id: "one type",
jobs: Jobs{"org/repo": {makeJob(""), makeJob("aws")}},
want: []string{"aws"},
}, {
id: "multiple types",
jobs: Jobs{
"org/repo": {makeJob(""), makeJob("aws")},
"org/sitory": {makeJob("azure"), makeJob("vsphere")},
},
want: []string{"aws", "azure", "vsphere"},
}} {
t.Run(tc.id, func(t *testing.T) {
ret := getClusterTypes(tc.jobs)
if !reflect.DeepEqual(tc.want, ret) {
t.Fatal(diff.ObjectDiff(tc.want, ret))
}
})
}
}