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
7 changes: 6 additions & 1 deletion pkg/dispatcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dispatcher
import (
"io/ioutil"
"regexp"
"strings"

"github.com/pkg/errors"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
Expand Down Expand Up @@ -48,6 +49,7 @@ const (
ClusterBuild01 ClusterName = "build01"
// ClusterBuild02 is the cluster build02 in the build farm
ClusterBuild02 ClusterName = "build02"
ClusterVSphere ClusterName = "vsphere"
)

// JobGroups maps a group of jobs to a cluster
Expand All @@ -70,10 +72,13 @@ func (config *Config) GetClusterForJob(jobBase prowconfig.JobBase, path string)
}

// DetermineClusterForJob return the cluster for a prow job and if it can be relocated to a cluster in build farm
func (config *Config) DetermineClusterForJob(jobBase prowconfig.JobBase, path string) (ClusterName, bool) {
func (config *Config) DetermineClusterForJob(jobBase prowconfig.JobBase, path string) (_ ClusterName, mayBeRelocated bool) {
if jobBase.Agent != "kubernetes" {
return config.NonKubernetes, false
}
if strings.Contains(jobBase.Name, "vsphere") {
return ClusterVSphere, false
}
if isSSHBastionJob(jobBase) {
return config.SSHBastion, false
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/dispatcher/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,43 +258,43 @@ func TestDetermineClusterForJob(t *testing.T) {
}{
{
name: "some job",
config: &configWithBuildFarmWithJobs,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can remove it from the struct too?

jobBase: config.JobBase{Agent: "kubernetes", Name: "some-job"},
path: "org/repo/some-postsubmits.yaml",
expected: "api.ci",
},
{
name: "job must on build01",
config: &configWithBuildFarmWithJobs,
jobBase: config.JobBase{Agent: "kubernetes", Name: "periodic-build01-upgrade"},
expected: "build01",
},
{
name: "some periodic job in release repo",
config: &configWithBuildFarmWithJobs,
jobBase: config.JobBase{Agent: "kubernetes", Name: "promote-release-openshift-machine-os-content-e2e-aws-4.1"},
path: "ci-operator/jobs/openshift/release/openshift-release-release-4.1-periodics.yaml",
expected: "api.ci",
},
{
name: "some jenkins job",
config: &configWithBuildFarmWithJobs,
jobBase: config.JobBase{Agent: "jenkins", Name: "test_branch_wildfly_images"},
path: "ci-operator/jobs/openshift-s2i/s2i-wildfly/openshift-s2i-s2i-wildfly-master-postsubmits.yaml",
expected: "app.ci",
},
{
name: "some job in build farm",
config: &configWithBuildFarmWithJobs,
jobBase: config.JobBase{Agent: "kubernetes", Name: "some-build-farm-job"},
path: "org/repo/some-build-farm-presubmits.yaml",
expected: "build01",
expectedCanBeRelocated: true,
},
{
name: "Vsphere job",
jobBase: config.JobBase{Agent: "kubernetes", Name: "yalayala-vsphere"},
expected: "vsphere",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual, canBeRelocated := tc.config.DetermineClusterForJob(tc.jobBase, tc.path)
actual, canBeRelocated := configWithBuildFarmWithJobs.DetermineClusterForJob(tc.jobBase, tc.path)
if !reflect.DeepEqual(tc.expected, actual) {
t.Errorf("%s: actual differs from expected:\n%s", t.Name(), cmp.Diff(tc.expected, actual))
}
Expand Down