Skip to content
Open
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
6 changes: 6 additions & 0 deletions pkg/sanitizer/determinize.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ func isCIOperatorLatest(image string) bool {

func determineCluster(jb prowconfig.JobBase, config *dispatcher.Config, pjs map[string]dispatcher.ProwJobData, path string, mostUsedCluster string, blocked sets.Set[string], cm dispatcher.ClusterMap) (string, error) {
if pjs == nil {
// If the job already has a cluster assigned, check if it's a valid build farm cluster
// that's not blocked. If so, preserve the existing assignment to avoid
// inconsistencies between what the dispatcher assigned and what this function would calculate.
if jb.Cluster != "" && !blocked.Has(jb.Cluster) && config.IsInBuildFarm(api.Cluster(jb.Cluster)) != "" {
return jb.Cluster, nil
}
c, canBeRelocated, err := config.DetermineClusterForJob(jb, path, cm)
if err != nil {
return "", err
Expand Down
90 changes: 90 additions & 0 deletions pkg/sanitizer/determinize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/prow/pkg/config"

"github.com/openshift/ci-tools/pkg/api"
"github.com/openshift/ci-tools/pkg/dispatcher"
)

Expand Down Expand Up @@ -48,6 +49,95 @@ func TestDefaultJobConfig(t *testing.T) {
}
}

func TestDetermineClusterPreservesValidBuildFarmCluster(t *testing.T) {
testCases := []struct {
name string
jobCluster string
blocked sets.Set[string]
buildFarm map[api.Cloud]map[api.Cluster]*dispatcher.BuildFarmConfig
groups dispatcher.JobGroups
expectedCluster string
}{
{
name: "preserves existing valid build farm cluster",
jobCluster: "build01",
blocked: sets.New[string](),
buildFarm: map[api.Cloud]map[api.Cluster]*dispatcher.BuildFarmConfig{
api.CloudAWS: {
"build01": {Filenames: sets.New[string]()},
"build02": {Filenames: sets.New[string]()},
},
},
expectedCluster: "build01",
},
{
name: "uses algorithm when cluster is blocked",
jobCluster: "build01",
blocked: sets.New[string]("build01"),
buildFarm: map[api.Cloud]map[api.Cluster]*dispatcher.BuildFarmConfig{
api.CloudAWS: {
"build01": {Filenames: sets.New[string]()},
"build02": {Filenames: sets.New[string]()},
},
},
groups: dispatcher.JobGroups{
"special-cluster": {Jobs: []string{"test-job"}},
},
expectedCluster: "special-cluster", // algorithm matches job name in Groups
},
{
name: "uses algorithm when cluster is not in build farm",
jobCluster: "some-other-cluster",
blocked: sets.New[string](),
buildFarm: map[api.Cloud]map[api.Cluster]*dispatcher.BuildFarmConfig{
api.CloudAWS: {
"build01": {Filenames: sets.New[string]()},
"build02": {Filenames: sets.New[string]()},
},
},
groups: dispatcher.JobGroups{
"special-cluster": {Jobs: []string{"test-job"}},
},
expectedCluster: "special-cluster", // algorithm matches job name in Groups
},
{
name: "uses algorithm when cluster is empty",
jobCluster: "",
blocked: sets.New[string](),
buildFarm: map[api.Cloud]map[api.Cluster]*dispatcher.BuildFarmConfig{},
groups: dispatcher.JobGroups{
"special-cluster": {Jobs: []string{"test-job"}},
},
expectedCluster: "special-cluster", // algorithm matches job name in Groups
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
jc := &config.JobConfig{
PresubmitsStatic: map[string][]config.Presubmit{
"org/repo": {{JobBase: config.JobBase{Agent: "kubernetes", Cluster: tc.jobCluster, Name: "test-job"}}},
},
}

cfg := &dispatcher.Config{
Default: "api.ci",
BuildFarm: tc.buildFarm,
Groups: tc.groups,
}

if err := defaultJobConfig(jc, "org/repo/test.yaml", cfg, nil, tc.blocked, dispatcher.ClusterMap{}); err != nil {
t.Fatalf("failed to default job config: %v", err)
}

got := jc.PresubmitsStatic["org/repo"][0].Cluster
if got != tc.expectedCluster {
t.Errorf("expected cluster %q, got %q", tc.expectedCluster, got)
}
})
}
}

func TestIsCIOperatorLatest(t *testing.T) {
testCases := []struct {
name string
Expand Down