1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package spacecloud
import (
"context"
"fmt"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/scheduler/framework"
)
const (
Name = "SpaceCloud"
stateKey = Name + "StateKey"
)
type SpaceCloud struct {
}
var (
_ framework.PreFilterPlugin = &SpaceCloud{}
_ framework.FilterPlugin = &SpaceCloud{}
)
// Name returns name of the plugin.
func (pl *SpaceCloud) Name() string {
return Name
}
type CloudState struct {
spaceWorkload bool
node string
satellite string
}
// 查看 pod 类型 ,是否是 spaceWorkload
func (pl *SpaceCloud) PreFilter(ctx context.Context, state *framework.CycleState, pod *v1.Pod) (*framework.PreFilterResult, *framework.Status) {
c := CloudState{
spaceWorkload: false,
node: "",
satellite: "",
}
if pod.Annotations["type"] == "space" {
c.spaceWorkload = true
}
klog.Info("=======pod.Annotations", pod.Annotations["type"])
klog.Info("=======spaceWorkload", c.spaceWorkload)
state.Write(stateKey, &c)
return nil, framework.NewStatus(framework.Success, "Check pod Annotations type , return")
}
func (pl *SpaceCloud) Filter(ctx context.Context, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
s, err := state.Read(stateKey)
if err != nil {
klog.Infof("Filter: pod %s/%s: read preFilter scheduling context failed: %v", pod.Namespace, pod.Name, err)
return framework.NewStatus(framework.Error, fmt.Sprintf("read preFilter state fail: %v", err))
}
r, ok := s.(*CloudState)
if !ok {
return framework.NewStatus(framework.Error, fmt.Sprintf("convert %+v to stickyState fail", s))
}
klog.Info("=====", r.spaceWorkload)
if nodeInfo.Node().Labels["kubernetes.io/role"] == "edge" {
klog.Infof("====", nodeInfo.Node().Labels["kubernetes.io/role"])
}
return nil
}
func (c *CloudState) Clone() framework.StateData {
return c
}
func New(_ runtime.Object, _ framework.Handle) (framework.Plugin, error) {
return &SpaceCloud{}, nil
}
// PreFilterExtensions returns prefilter extensions, pod add and remove.
func (pl *SpaceCloud) PreFilterExtensions() framework.PreFilterExtensions {
return pl
}
// AddPod from pre-computed data in cycleState.
// no current need for this method.
func (pl *SpaceCloud) AddPod(ctx context.Context, cycleState *framework.CycleState, podToSchedule *v1.Pod, podToAdd *framework.PodInfo, nodeInfo *framework.NodeInfo) *framework.Status {
return framework.NewStatus(framework.Success, "")
}
// RemovePod from pre-computed data in cycleState.
// no current need for this method.
func (pl *SpaceCloud) RemovePod(ctx context.Context, cycleState *framework.CycleState, podToSchedule *v1.Pod, podToRemove *framework.PodInfo, nodeInfo *framework.NodeInfo) *framework.Status {
return framework.NewStatus(framework.Success, "")
}
|