...
1
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
27
28 type StatelessPreBindExample struct{}
29
30 var _ framework.PreBindPlugin = StatelessPreBindExample{}
31
32
33 const Name = "stateless-prebind-plugin-example"
34
35
36 func (sr StatelessPreBindExample) Name() string {
37 return Name
38 }
39
40
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
52 func New(_ context.Context, _ *runtime.Unknown, _ framework.Handle) (framework.Plugin, error) {
53 return &StatelessPreBindExample{}, nil
54 }
55
View as plain text