sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/scheduler/strategy/default.go (about)

     1  /*
     2  Copyright 2024 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package strategy
    18  
    19  import (
    20  	"context"
    21  
    22  	prowv1 "sigs.k8s.io/prow/pkg/apis/prowjobs/v1"
    23  	"sigs.k8s.io/prow/pkg/config"
    24  )
    25  
    26  // Result is an answer that came out of a scheduling strategy
    27  type Result struct {
    28  	// A candidate cluster, the chosen one
    29  	Cluster string
    30  }
    31  
    32  // Interface is an interface over scheduling strategies
    33  type Interface interface {
    34  	Schedule(context.Context, *prowv1.ProwJob) (Result, error)
    35  }
    36  
    37  // Get gets a scheduling strategy in accordance to configuration. It defaults
    38  // to Passthrough stategy if none has been configured.
    39  func Get(cfg *config.Config) Interface {
    40  	if cfg.Scheduler.Failover != nil {
    41  		return NewFailover(*cfg.Scheduler.Failover)
    42  	}
    43  	return &Passthrough{}
    44  }
    45  
    46  // Passthrough is the backward compatible, transparent scheduling strategy, and in fact
    47  // it pretends a scheduler didn't exist at all. This strategy assumes a cluster has
    48  // been assigned to a ProwJob at the time it was defined.
    49  type Passthrough struct {
    50  }
    51  
    52  var _ Interface = &Passthrough{}
    53  
    54  func (p *Passthrough) Schedule(_ context.Context, pj *prowv1.ProwJob) (Result, error) {
    55  	return Result{Cluster: pj.Spec.Cluster}, nil
    56  }