/
interfaces.go
62 lines (50 loc) · 2.08 KB
/
interfaces.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
/*
Copyright 2021 The OpenYurt 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 filter
import (
"io"
"net/http"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
)
type NodesInPoolGetter func(poolName string) ([]string, error)
type Initializer interface {
Initialize(filter ObjectFilter) error
}
// Approver check the response of specified request need to go through filter or not.
// and get all filters' names for the specified request.
type Approver interface {
Approve(req *http.Request) (bool, []string)
}
// ResponseFilter is used for filtering response for get/list/watch requests.
// it only prepares the common framework for ObjectFilter and don't cover
// the filter logic.
type ResponseFilter interface {
Name() string
// Filter is used to filter data returned from the cloud.
Filter(req *http.Request, rc io.ReadCloser, stopCh <-chan struct{}) (int, io.ReadCloser, error)
}
// ObjectFilter is used for filtering runtime object.
// runtime object is only a standalone object(like Service).
// Every Filter need to implement ObjectFilter interface.
type ObjectFilter interface {
Name() string
// SupportedResourceAndVerbs is used to specify which resource and request verb is supported by the filter.
// Because each filter can make sure what requests with resource and verb can be handled.
SupportedResourceAndVerbs() map[string]sets.String
// Filter is used for filtering runtime object
// all filter logic should be located in it.
Filter(obj runtime.Object, stopCh <-chan struct{}) runtime.Object
}
type NodeGetter func(name string) (*v1.Node, error)