container_manager_windows.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. "k8s.io/klog"
  20. "k8s.io/utils/mount"
  21. v1 "k8s.io/api/core/v1"
  22. "k8s.io/apimachinery/pkg/api/resource"
  23. utilfeature "k8s.io/apiserver/pkg/util/feature"
  24. "k8s.io/client-go/tools/record"
  25. internalapi "k8s.io/cri-api/pkg/apis"
  26. kubefeatures "k8s.io/kubernetes/pkg/features"
  27. podresourcesapi "k8s.io/kubernetes/pkg/kubelet/apis/podresources/v1alpha1"
  28. "k8s.io/kubernetes/pkg/kubelet/cadvisor"
  29. "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
  30. "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
  31. "k8s.io/kubernetes/pkg/kubelet/config"
  32. kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
  33. "k8s.io/kubernetes/pkg/kubelet/lifecycle"
  34. "k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache"
  35. "k8s.io/kubernetes/pkg/kubelet/status"
  36. schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
  37. )
  38. type containerManagerImpl struct {
  39. // Capacity of this node.
  40. capacity v1.ResourceList
  41. // Interface for cadvisor.
  42. cadvisorInterface cadvisor.Interface
  43. // Config of this node.
  44. nodeConfig NodeConfig
  45. }
  46. func (cm *containerManagerImpl) Start(node *v1.Node,
  47. activePods ActivePodsFunc,
  48. sourcesReady config.SourcesReady,
  49. podStatusProvider status.PodStatusProvider,
  50. runtimeService internalapi.RuntimeService) error {
  51. klog.V(2).Infof("Starting Windows container manager")
  52. if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.LocalStorageCapacityIsolation) {
  53. rootfs, err := cm.cadvisorInterface.RootFsInfo()
  54. if err != nil {
  55. return fmt.Errorf("failed to get rootfs info: %v", err)
  56. }
  57. for rName, rCap := range cadvisor.EphemeralStorageCapacityFromFsInfo(rootfs) {
  58. cm.capacity[rName] = rCap
  59. }
  60. }
  61. return nil
  62. }
  63. // NewContainerManager creates windows container manager.
  64. func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.Interface, nodeConfig NodeConfig, failSwapOn bool, devicePluginEnabled bool, recorder record.EventRecorder) (ContainerManager, error) {
  65. var capacity = v1.ResourceList{}
  66. // It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because
  67. // machine info is computed and cached once as part of cAdvisor object creation.
  68. // But `RootFsInfo` and `ImagesFsInfo` are not available at this moment so they will be called later during manager starts
  69. machineInfo, err := cadvisorInterface.MachineInfo()
  70. if err != nil {
  71. return nil, err
  72. }
  73. capacity = cadvisor.CapacityFromMachineInfo(machineInfo)
  74. return &containerManagerImpl{
  75. capacity: capacity,
  76. nodeConfig: nodeConfig,
  77. cadvisorInterface: cadvisorInterface,
  78. }, nil
  79. }
  80. func (cm *containerManagerImpl) SystemCgroupsLimit() v1.ResourceList {
  81. return v1.ResourceList{}
  82. }
  83. func (cm *containerManagerImpl) GetNodeConfig() NodeConfig {
  84. return NodeConfig{}
  85. }
  86. func (cm *containerManagerImpl) GetMountedSubsystems() *CgroupSubsystems {
  87. return &CgroupSubsystems{}
  88. }
  89. func (cm *containerManagerImpl) GetQOSContainersInfo() QOSContainersInfo {
  90. return QOSContainersInfo{}
  91. }
  92. func (cm *containerManagerImpl) UpdateQOSCgroups() error {
  93. return nil
  94. }
  95. func (cm *containerManagerImpl) Status() Status {
  96. return Status{}
  97. }
  98. func (cm *containerManagerImpl) GetNodeAllocatableReservation() v1.ResourceList {
  99. evictionReservation := hardEvictionReservation(cm.nodeConfig.HardEvictionThresholds, cm.capacity)
  100. result := make(v1.ResourceList)
  101. for k := range cm.capacity {
  102. value := resource.NewQuantity(0, resource.DecimalSI)
  103. if cm.nodeConfig.SystemReserved != nil {
  104. value.Add(cm.nodeConfig.SystemReserved[k])
  105. }
  106. if cm.nodeConfig.KubeReserved != nil {
  107. value.Add(cm.nodeConfig.KubeReserved[k])
  108. }
  109. if evictionReservation != nil {
  110. value.Add(evictionReservation[k])
  111. }
  112. if !value.IsZero() {
  113. result[k] = *value
  114. }
  115. }
  116. return result
  117. }
  118. func (cm *containerManagerImpl) GetCapacity() v1.ResourceList {
  119. return cm.capacity
  120. }
  121. func (cm *containerManagerImpl) GetPluginRegistrationHandler() cache.PluginHandler {
  122. return nil
  123. }
  124. func (cm *containerManagerImpl) GetDevicePluginResourceCapacity() (v1.ResourceList, v1.ResourceList, []string) {
  125. return nil, nil, []string{}
  126. }
  127. func (cm *containerManagerImpl) NewPodContainerManager() PodContainerManager {
  128. return &podContainerManagerStub{}
  129. }
  130. func (cm *containerManagerImpl) GetResources(pod *v1.Pod, container *v1.Container) (*kubecontainer.RunContainerOptions, error) {
  131. return &kubecontainer.RunContainerOptions{}, nil
  132. }
  133. func (cm *containerManagerImpl) UpdatePluginResources(*schedulernodeinfo.NodeInfo, *lifecycle.PodAdmitAttributes) error {
  134. return nil
  135. }
  136. func (cm *containerManagerImpl) InternalContainerLifecycle() InternalContainerLifecycle {
  137. return &internalContainerLifecycleImpl{cpumanager.NewFakeManager(), topologymanager.NewFakeManager()}
  138. }
  139. func (cm *containerManagerImpl) GetPodCgroupRoot() string {
  140. return ""
  141. }
  142. func (cm *containerManagerImpl) GetDevices(_, _ string) []*podresourcesapi.ContainerDevices {
  143. return nil
  144. }
  145. func (cm *containerManagerImpl) ShouldResetExtendedResourceCapacity() bool {
  146. return false
  147. }
  148. func (cm *containerManagerImpl) GetTopologyPodAdmitHandler() topologymanager.Manager {
  149. return nil
  150. }
  151. func (cm *containerManagerImpl) UpdateAllocatedDevices() {
  152. return
  153. }