...

Source file src/k8s.io/kubernetes/pkg/kubelet/cm/internal_container_lifecycle_linux.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cm

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5  Copyright 2021 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package cm
    21  
    22  import (
    23  	"strconv"
    24  	"strings"
    25  
    26  	v1 "k8s.io/api/core/v1"
    27  	"k8s.io/apimachinery/pkg/util/sets"
    28  	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
    29  )
    30  
    31  func (i *internalContainerLifecycleImpl) PreCreateContainer(pod *v1.Pod, container *v1.Container, containerConfig *runtimeapi.ContainerConfig) error {
    32  	if i.cpuManager != nil {
    33  		allocatedCPUs := i.cpuManager.GetCPUAffinity(string(pod.UID), container.Name)
    34  		if !allocatedCPUs.IsEmpty() {
    35  			containerConfig.Linux.Resources.CpusetCpus = allocatedCPUs.String()
    36  		}
    37  	}
    38  
    39  	if i.memoryManager != nil {
    40  		numaNodes := i.memoryManager.GetMemoryNUMANodes(pod, container)
    41  		if numaNodes.Len() > 0 {
    42  			var affinity []string
    43  			for _, numaNode := range sets.List(numaNodes) {
    44  				affinity = append(affinity, strconv.Itoa(numaNode))
    45  			}
    46  			containerConfig.Linux.Resources.CpusetMems = strings.Join(affinity, ",")
    47  		}
    48  	}
    49  
    50  	return nil
    51  }
    52  

View as plain text