github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/scheduler/strategy/failover.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  // Failover is a scheduling strategy that handles clusters known to be
    27  // in a faulty state. It holds a list of mapping from a broken cluster to an
    28  // healthy one. This strategy get the cluster from a ProwJob and replaces it
    29  // with another one if it was found on the mapping list.
    30  type Failover struct {
    31  	cfg config.FailoverScheduling
    32  }
    33  
    34  var _ Interface = &Failover{}
    35  
    36  func (f *Failover) Schedule(_ context.Context, pj *prowv1.ProwJob) (Result, error) {
    37  	if cluster, exists := f.cfg.ClusterMappings[pj.Spec.Cluster]; exists {
    38  		return Result{Cluster: cluster}, nil
    39  	}
    40  	return Result{Cluster: pj.Spec.Cluster}, nil
    41  }
    42  
    43  func NewFailover(cfg config.FailoverScheduling) *Failover {
    44  	return &Failover{cfg: cfg}
    45  }