...

Source file src/k8s.io/kubernetes/pkg/scheduler/framework/plugins/schedulinggates/scheduling_gates.go

Documentation: k8s.io/kubernetes/pkg/scheduler/framework/plugins/schedulinggates

     1  /*
     2  Copyright 2022 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 schedulinggates
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  
    23  	v1 "k8s.io/api/core/v1"
    24  	"k8s.io/apimachinery/pkg/runtime"
    25  	"k8s.io/kubernetes/pkg/scheduler/framework"
    26  	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/names"
    27  )
    28  
    29  // Name of the plugin used in the plugin registry and configurations.
    30  const Name = names.SchedulingGates
    31  
    32  // SchedulingGates checks if a Pod carries .spec.schedulingGates.
    33  type SchedulingGates struct{}
    34  
    35  var _ framework.PreEnqueuePlugin = &SchedulingGates{}
    36  var _ framework.EnqueueExtensions = &SchedulingGates{}
    37  
    38  func (pl *SchedulingGates) Name() string {
    39  	return Name
    40  }
    41  
    42  func (pl *SchedulingGates) PreEnqueue(ctx context.Context, p *v1.Pod) *framework.Status {
    43  	if len(p.Spec.SchedulingGates) == 0 {
    44  		return nil
    45  	}
    46  	gates := make([]string, 0, len(p.Spec.SchedulingGates))
    47  	for _, gate := range p.Spec.SchedulingGates {
    48  		gates = append(gates, gate.Name)
    49  	}
    50  	return framework.NewStatus(framework.UnschedulableAndUnresolvable, fmt.Sprintf("waiting for scheduling gates: %v", gates))
    51  }
    52  
    53  // EventsToRegister returns nil here to indicate that schedulingGates plugin is not
    54  // interested in any event but its own update.
    55  func (pl *SchedulingGates) EventsToRegister() []framework.ClusterEventWithHint {
    56  	return nil
    57  }
    58  
    59  // New initializes a new plugin and returns it.
    60  func New(_ context.Context, _ runtime.Object, _ framework.Handle) (framework.Plugin, error) {
    61  	return &SchedulingGates{}, nil
    62  }
    63  

View as plain text