Merge pull request #100267 from Jeffwan/support_arbitratry_resources
Expose resources overrides and maxPods conf in kubemark
This commit is contained in:
commit
12f8466459
@ -29,6 +29,7 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
@ -67,6 +68,8 @@ type hollowNodeConfig struct {
|
|||||||
ProxierMinSyncPeriod time.Duration
|
ProxierMinSyncPeriod time.Duration
|
||||||
NodeLabels map[string]string
|
NodeLabels map[string]string
|
||||||
RegisterWithTaints []core.Taint
|
RegisterWithTaints []core.Taint
|
||||||
|
MaxPods int
|
||||||
|
ExtendedResources map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -92,6 +95,9 @@ func (c *hollowNodeConfig) addFlags(fs *pflag.FlagSet) {
|
|||||||
bindableNodeLabels := cliflag.ConfigurationMap(c.NodeLabels)
|
bindableNodeLabels := cliflag.ConfigurationMap(c.NodeLabels)
|
||||||
fs.Var(&bindableNodeLabels, "node-labels", "Additional node labels")
|
fs.Var(&bindableNodeLabels, "node-labels", "Additional node labels")
|
||||||
fs.Var(utiltaints.NewTaintsVar(&c.RegisterWithTaints), "register-with-taints", "Register the node with the given list of taints (comma separated \"<key>=<value>:<effect>\"). No-op if register-node is false.")
|
fs.Var(utiltaints.NewTaintsVar(&c.RegisterWithTaints), "register-with-taints", "Register the node with the given list of taints (comma separated \"<key>=<value>:<effect>\"). No-op if register-node is false.")
|
||||||
|
fs.IntVar(&c.MaxPods, "max-pods", maxPods, "Number of pods that can run on this Kubelet.")
|
||||||
|
bindableExtendedResources := cliflag.ConfigurationMap(c.ExtendedResources)
|
||||||
|
fs.Var(&bindableExtendedResources, "extended-resources", "Register the node with extended resources (comma separated \"<name>=<quantity>\")")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *hollowNodeConfig) createClientConfigFromFile() (*restclient.Config, error) {
|
func (c *hollowNodeConfig) createClientConfigFromFile() (*restclient.Config, error) {
|
||||||
@ -114,7 +120,7 @@ func (c *hollowNodeConfig) createHollowKubeletOptions() *kubemark.HollowKubletOp
|
|||||||
NodeName: c.NodeName,
|
NodeName: c.NodeName,
|
||||||
KubeletPort: c.KubeletPort,
|
KubeletPort: c.KubeletPort,
|
||||||
KubeletReadOnlyPort: c.KubeletReadOnlyPort,
|
KubeletReadOnlyPort: c.KubeletReadOnlyPort,
|
||||||
MaxPods: maxPods,
|
MaxPods: c.MaxPods,
|
||||||
PodsPerCore: podsPerCore,
|
PodsPerCore: podsPerCore,
|
||||||
NodeLabels: c.NodeLabels,
|
NodeLabels: c.NodeLabels,
|
||||||
RegisterWithTaints: c.RegisterWithTaints,
|
RegisterWithTaints: c.RegisterWithTaints,
|
||||||
@ -143,7 +149,8 @@ func main() {
|
|||||||
// newControllerManagerCommand creates a *cobra.Command object with default parameters
|
// newControllerManagerCommand creates a *cobra.Command object with default parameters
|
||||||
func newHollowNodeCommand() *cobra.Command {
|
func newHollowNodeCommand() *cobra.Command {
|
||||||
s := &hollowNodeConfig{
|
s := &hollowNodeConfig{
|
||||||
NodeLabels: make(map[string]string),
|
NodeLabels: make(map[string]string),
|
||||||
|
ExtendedResources: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -206,7 +213,18 @@ func run(config *hollowNodeConfig) {
|
|||||||
cadvisorInterface := &cadvisortest.Fake{
|
cadvisorInterface := &cadvisortest.Fake{
|
||||||
NodeName: config.NodeName,
|
NodeName: config.NodeName,
|
||||||
}
|
}
|
||||||
containerManager := cm.NewStubContainerManager()
|
|
||||||
|
var containerManager cm.ContainerManager
|
||||||
|
if config.ExtendedResources != nil {
|
||||||
|
extendedResources := v1.ResourceList{}
|
||||||
|
for k, v := range config.ExtendedResources {
|
||||||
|
extendedResources[v1.ResourceName(k)] = resource.MustParse(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
containerManager = cm.NewStubContainerManagerWithDevicePluginResource(extendedResources)
|
||||||
|
} else {
|
||||||
|
containerManager = cm.NewStubContainerManager()
|
||||||
|
}
|
||||||
|
|
||||||
endpoint, err := fakeremote.GenerateEndpoint()
|
endpoint, err := fakeremote.GenerateEndpoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
|
|
||||||
type containerManagerStub struct {
|
type containerManagerStub struct {
|
||||||
shouldResetExtendedResourceCapacity bool
|
shouldResetExtendedResourceCapacity bool
|
||||||
|
extendedPluginResources v1.ResourceList
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ ContainerManager = &containerManagerStub{}
|
var _ ContainerManager = &containerManagerStub{}
|
||||||
@ -87,7 +88,7 @@ func (cm *containerManagerStub) GetPluginRegistrationHandler() cache.PluginHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cm *containerManagerStub) GetDevicePluginResourceCapacity() (v1.ResourceList, v1.ResourceList, []string) {
|
func (cm *containerManagerStub) GetDevicePluginResourceCapacity() (v1.ResourceList, v1.ResourceList, []string) {
|
||||||
return nil, nil, []string{}
|
return cm.extendedPluginResources, cm.extendedPluginResources, []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *containerManagerStub) NewPodContainerManager() PodContainerManager {
|
func (cm *containerManagerStub) NewPodContainerManager() PodContainerManager {
|
||||||
@ -145,3 +146,10 @@ func NewStubContainerManager() ContainerManager {
|
|||||||
func NewStubContainerManagerWithExtendedResource(shouldResetExtendedResourceCapacity bool) ContainerManager {
|
func NewStubContainerManagerWithExtendedResource(shouldResetExtendedResourceCapacity bool) ContainerManager {
|
||||||
return &containerManagerStub{shouldResetExtendedResourceCapacity: shouldResetExtendedResourceCapacity}
|
return &containerManagerStub{shouldResetExtendedResourceCapacity: shouldResetExtendedResourceCapacity}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewStubContainerManagerWithDevicePluginResource(extendedPluginResources v1.ResourceList) ContainerManager {
|
||||||
|
return &containerManagerStub{
|
||||||
|
shouldResetExtendedResourceCapacity: false,
|
||||||
|
extendedPluginResources: extendedPluginResources,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user