container_manager_windows.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // +build windows
  2. /*
  3. Copyright 2015 The Kubernetes Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. // containerManagerImpl implements container manager on Windows.
  15. // Only GetNodeAllocatableReservation() and GetCapacity() are implemented now.
  16. package cm
  17. import (
  18. "fmt"
  19. v1 "k8s.io/api/core/v1"
  20. "k8s.io/apimachinery/pkg/api/resource"
  21. utilfeature "k8s.io/apiserver/pkg/util/feature"
  22. "k8s.io/client-go/tools/record"
  23. internalapi "k8s.io/cri-api/pkg/apis"
  24. "k8s.io/klog"
  25. kubefeatures "k8s.io/kubernetes/pkg/features"
  26. podresourcesapi "k8s.io/kubernetes/pkg/kubelet/apis/podresources/v1alpha1"
  27. "k8s.io/kubernetes/pkg/kubelet/cadvisor"
  28. "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
  29. "k8s.io/kubernetes/pkg/kubelet/config"
  30. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  31. "k8s.io/kubernetes/pkg/kubelet/lifecycle"
  32. "k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache"
  33. "k8s.io/kubernetes/pkg/kubelet/status"
  34. schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
  35. "k8s.io/kubernetes/pkg/util/mount"
  36. )
  37. type containerManagerImpl struct {
  38. // Capacity of this node.
  39. capacity v1.ResourceList
  40. // Interface for cadvisor.
  41. cadvisorInterface cadvisor.Interface
  42. // Config of this node.
  43. nodeConfig NodeConfig
  44. }
  45. func (cm *containerManagerImpl) Start(node *v1.Node,
  46. activePods ActivePodsFunc,
  47. sourcesReady config.SourcesReady,
  48. podStatusProvider status.PodStatusProvider,
  49. runtimeService internalapi.RuntimeService) error {
  50. klog.V(2).Infof("Starting Windows container manager")
  51. if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.LocalStorageCapacityIsolation) {
  52. rootfs, err := cm.cadvisorInterface.RootFsInfo()
  53. if err != nil {
  54. return fmt.Errorf("failed to get rootfs info: %v", err)
  55. }
  56. for rName, rCap := range cadvisor.EphemeralStorageCapacityFromFsInfo(rootfs) {
  57. cm.capacity[rName] = rCap
  58. }
  59. }
  60. return nil
  61. }
  62. // NewContainerManager creates windows container manager.
  63. func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, devicePluginEnabled bool, recorder record.EventRecorder) (ContainerManager, error) {
  64. var capacity = v1.ResourceList{}
  65. // It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because
  66. // machine info is computed and cached once as part of cAdvisor object creation.
  67. // But `RootFsInfo` and `ImagesFsInfo` are not available at this moment so they will be called later during manager starts
  68. machineInfo, err := cadvisorInterface.MachineInfo()
  69. if err != nil {
  70. return nil, err
  71. }
  72. capacity = cadvisor.CapacityFromMachineInfo(machineInfo)
  73. return &containerManagerImpl{
  74. capacity: capacity,
  75. nodeConfig: nodeConfig,
  76. cadvisorInterface: cadvisorInterface,
  77. }, nil
  78. }
  79. func (cm *containerManagerImpl) SystemCgroupsLimit() v1.ResourceList {
  80. return v1.ResourceList{}
  81. }
  82. func (cm *containerManagerImpl) GetNodeConfig() NodeConfig {
  83. return NodeConfig{}
  84. }
  85. func (cm *containerManagerImpl) GetMountedSubsystems() *CgroupSubsystems {
  86. return &CgroupSubsystems{}
  87. }
  88. func (cm *containerManagerImpl) GetQOSContainersInfo() QOSContainersInfo {
  89. return QOSContainersInfo{}
  90. }
  91. func (cm *containerManagerImpl) UpdateQOSCgroups() error {
  92. return nil
  93. }
  94. func (cm *containerManagerImpl) Status() Status {
  95. return Status{}
  96. }
  97. func (cm *containerManagerImpl) GetNodeAllocatableReservation() v1.ResourceList {
  98. evictionReservation := hardEvictionReservation(cm.nodeConfig.HardEvictionThresholds, cm.capacity)
  99. result := make(v1.ResourceList)
  100. for k := range cm.capacity {
  101. value := resource.NewQuantity(0, resource.DecimalSI)
  102. if cm.nodeConfig.SystemReserved != nil {
  103. value.Add(cm.nodeConfig.SystemReserved[k])
  104. }
  105. if cm.nodeConfig.KubeReserved != nil {
  106. value.Add(cm.nodeConfig.KubeReserved[k])
  107. }
  108. if evictionReservation != nil {
  109. value.Add(evictionReservation[k])
  110. }
  111. if !value.IsZero() {
  112. result[k] = *value
  113. }
  114. }
  115. return result
  116. }
  117. func (cm *containerManagerImpl) GetCapacity() v1.ResourceList {
  118. return cm.capacity
  119. }
  120. func (cm *containerManagerImpl) GetPluginRegistrationHandler() cache.PluginHandler {
  121. return nil
  122. }
  123. func (cm *containerManagerImpl) GetDevicePluginResourceCapacity() (v1.ResourceList, v1.ResourceList, []string) {
  124. return nil, nil, []string{}
  125. }
  126. func (cm *containerManagerImpl) NewPodContainerManager() PodContainerManager {
  127. return &podContainerManagerStub{}
  128. }
  129. func (cm *containerManagerImpl) GetResources(pod *v1.Pod, container *v1.Container) (*kubecontainer.RunContainerOptions, error) {
  130. return &kubecontainer.RunContainerOptions{}, nil
  131. }
  132. func (cm *containerManagerImpl) UpdatePluginResources(*schedulernodeinfo.NodeInfo, *lifecycle.PodAdmitAttributes) error {
  133. return nil
  134. }
  135. func (cm *containerManagerImpl) InternalContainerLifecycle() InternalContainerLifecycle {
  136. return &internalContainerLifecycleImpl{cpumanager.NewFakeManager()}
  137. }
  138. func (cm *containerManagerImpl) GetPodCgroupRoot() string {
  139. return ""
  140. }
  141. func (cm *containerManagerImpl) GetDevices(_, _ string) []*podresourcesapi.ContainerDevices {
  142. return nil
  143. }
  144. func (cm *containerManagerImpl) ShouldResetExtendedResourceCapacity() bool {
  145. return false
  146. }