-
Notifications
You must be signed in to change notification settings - Fork 90
/
kubelet_plugin.go
75 lines (63 loc) · 2.74 KB
/
kubelet_plugin.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
/*
Copyright 2022 The Katalyst 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 reporter
import (
v1 "k8s.io/api/core/v1"
cliflag "k8s.io/component-base/cli/flag"
pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1"
"github.com/kubewharf/katalyst-core/pkg/config/agent/reporter"
)
type KubeletPluginOptions struct {
PodResourcesServerEndpoints []string
KubeletResourcePluginPaths []string
EnableReportTopologyPolicy bool
ResourceNameToZoneTypeMap map[string]string
NeedValidationResources []string
}
func NewKubeletPluginOptions() *KubeletPluginOptions {
return &KubeletPluginOptions{
PodResourcesServerEndpoints: []string{
pluginapi.KubeletSocket,
},
KubeletResourcePluginPaths: []string{
pluginapi.ResourcePluginPath,
},
EnableReportTopologyPolicy: false,
ResourceNameToZoneTypeMap: make(map[string]string),
NeedValidationResources: []string{
string(v1.ResourceCPU),
string(v1.ResourceMemory),
},
}
}
func (o *KubeletPluginOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("reporter-kubelet")
fs.StringSliceVar(&o.PodResourcesServerEndpoints, "pod-resources-server-endpoint", o.PodResourcesServerEndpoints,
"the endpoint of pod resource api server")
fs.StringSliceVar(&o.KubeletResourcePluginPaths, "kubelet-resource-plugin-path", o.KubeletResourcePluginPaths,
"the path of kubelet resource plugin")
fs.BoolVar(&o.EnableReportTopologyPolicy, "enable-report-topology-policy", o.EnableReportTopologyPolicy,
"whether to report topology policy")
fs.StringToStringVar(&o.ResourceNameToZoneTypeMap, "resource-name-to-zone-type-map", o.ResourceNameToZoneTypeMap,
"a map that stores the mapping relationship between resource names to zone types in KCNR (e.g. nvidia.com/gpu=GPU,...)")
fs.StringSliceVar(&o.NeedValidationResources, "need-validation-resources", o.NeedValidationResources,
"resources need to be validated")
}
func (o *KubeletPluginOptions) ApplyTo(c *reporter.KubeletPluginConfiguration) error {
c.PodResourcesServerEndpoints = o.PodResourcesServerEndpoints
c.KubeletResourcePluginPaths = o.KubeletResourcePluginPaths
c.EnableReportTopologyPolicy = o.EnableReportTopologyPolicy
c.ResourceNameToZoneTypeMap = o.ResourceNameToZoneTypeMap
c.NeedValidationResources = o.NeedValidationResources
return nil
}