/
types.go
93 lines (77 loc) · 3.03 KB
/
types.go
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
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package types
import (
"context"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
"sigs.k8s.io/descheduler/pkg/descheduler/evictions"
podutil "sigs.k8s.io/descheduler/pkg/descheduler/pod"
)
// Handle provides handles used by plugins to retrieve a kubernetes client set,
// evictor interface, shared informer factory and other instruments shared
// across plugins.
type Handle interface {
// ClientSet returns a kubernetes clientSet.
ClientSet() clientset.Interface
Evictor() Evictor
GetPodsAssignedToNodeFunc() podutil.GetPodsAssignedToNodeFunc
SharedInformerFactory() informers.SharedInformerFactory
}
// Evictor defines an interface for filtering and evicting pods
// while abstracting away the specific pod evictor/evictor filter.
type Evictor interface {
// Filter checks if a pod can be evicted
Filter(*v1.Pod) bool
// PreEvictionFilter checks if pod can be evicted right before eviction
PreEvictionFilter(*v1.Pod) bool
// Evict evicts a pod (no pre-check performed)
Evict(context.Context, *v1.Pod, evictions.EvictOptions) bool
// NodeLimitExceeded checks if the number of evictions for a node was exceeded
NodeLimitExceeded(node *v1.Node) bool
}
// Status describes result of an extension point invocation
type Status struct {
Err error
}
// Plugin is the parent type for all the descheduling framework plugins.
type Plugin interface {
Name() string
}
// DeschedulePlugin defines an extension point for a general descheduling operation
type DeschedulePlugin interface {
Plugin
Deschedule(ctx context.Context, nodes []*v1.Node) *Status
}
// BalancePlugin defines an extension point for balancing pods across a cluster
type BalancePlugin interface {
Plugin
Balance(ctx context.Context, nodes []*v1.Node) *Status
}
// EvictorPlugin defines extension points for a general evictor behavior
// Even though we name this plugin interface EvictorPlugin, it does not actually evict anything,
// This plugin is only meant to customize other actions (extension points) of the evictor,
// like filtering, sorting, and other ones that might be relevant in the future
type EvictorPlugin interface {
Plugin
Filter(pod *v1.Pod) bool
PreEvictionFilter(pod *v1.Pod) bool
}
type ExtensionPoint string
const (
DescheduleExtensionPoint ExtensionPoint = "Deschedule"
BalanceExtensionPoint ExtensionPoint = "Balance"
FilterExtensionPoint ExtensionPoint = "Filter"
PreEvictionFilterExtensionPoint ExtensionPoint = "PreEvictionFilter"
)