...

Source file src/k8s.io/kubernetes/pkg/scheduler/framework/plugins/examples/prebind/prebind.go

Documentation: k8s.io/kubernetes/pkg/scheduler/framework/plugins/examples/prebind

     1  /*
     2  Copyright 2019 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 prebind
    18  
    19  import (
    20  	"context"
    21  	v1 "k8s.io/api/core/v1"
    22  	"k8s.io/apimachinery/pkg/runtime"
    23  	"k8s.io/kubernetes/pkg/scheduler/framework"
    24  )
    25  
    26  // StatelessPreBindExample is an example of a simple plugin that has no state
    27  // and implements only one hook for prebind.
    28  type StatelessPreBindExample struct{}
    29  
    30  var _ framework.PreBindPlugin = StatelessPreBindExample{}
    31  
    32  // Name is the name of the plugin used in Registry and configurations.
    33  const Name = "stateless-prebind-plugin-example"
    34  
    35  // Name returns name of the plugin. It is used in logs, etc.
    36  func (sr StatelessPreBindExample) Name() string {
    37  	return Name
    38  }
    39  
    40  // PreBind is the functions invoked by the framework at "prebind" extension point.
    41  func (sr StatelessPreBindExample) PreBind(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeName string) *framework.Status {
    42  	if pod == nil {
    43  		return framework.NewStatus(framework.Error, "pod cannot be nil")
    44  	}
    45  	if pod.Namespace != "foo" {
    46  		return framework.NewStatus(framework.Unschedulable, "only pods from 'foo' namespace are allowed")
    47  	}
    48  	return nil
    49  }
    50  
    51  // New initializes a new plugin and returns it.
    52  func New(_ context.Context, _ *runtime.Unknown, _ framework.Handle) (framework.Plugin, error) {
    53  	return &StatelessPreBindExample{}, nil
    54  }
    55  

View as plain text