Skip to content

Commit

Permalink
Added CPU pinning to Docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
hedibouattour committed Mar 17, 2023
1 parent 7a5ce5b commit 15a813b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/config/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ type Node struct {
// binded to a host Port
ExtraPortMappings []PortMapping `yaml:"extraPortMappings,omitempty"`

// Limit the specific CPUs or cores a container can use.
// A comma-separated list or hyphen-separated range of CPUs a container can use, if you have more than one CPU.
CpuSet string `yaml:"cpuSet,omitempty"`

// KubeadmConfigPatches are applied to the generated kubeadm config as
// merge patches. The `kind` field must match the target object, and
// if `apiVersion` is specified it will only be applied to matching objects.
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/internal/providers/docker/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func commonArgs(cluster string, cfg *config.Cluster, networkName string, nodeNam

func runArgsForNode(node *config.Node, clusterIPFamily config.ClusterIPFamily, name string, args []string) ([]string, error) {
args = append([]string{
"--cpuset-cpus", node.CpuSet,
"--hostname", name, // make hostname match container name
// label the node with the role ID
"--label", fmt.Sprintf("%s=%s", nodeRoleLabelKey, node.Role),
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/apis/config/convert_v1alpha4.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func convertv1alpha4Node(in *v1alpha4.Node, out *Node) {

out.Labels = in.Labels
out.KubeadmConfigPatches = in.KubeadmConfigPatches
out.CpuSet = in.CpuSet
out.ExtraMounts = make([]Mount, len(in.ExtraMounts))
out.ExtraPortMappings = make([]PortMapping, len(in.ExtraPortMappings))
out.KubeadmConfigPatchesJSON6902 = make([]PatchJSON6902, len(in.KubeadmConfigPatchesJSON6902))
Expand Down
4 changes: 4 additions & 0 deletions pkg/internal/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ type Node struct {
// This should be an inline yaml blob-string
KubeadmConfigPatches []string

// Limit the specific CPUs or cores a container can use.
// A comma-separated list or hyphen-separated range of CPUs a container can use, if you have more than one CPU.
CpuSet string

// KubeadmConfigPatchesJSON6902 are applied to the generated kubeadm config
// as patchesJson6902 to `kustomize build`
KubeadmConfigPatchesJSON6902 []PatchJSON6902
Expand Down

0 comments on commit 15a813b

Please sign in to comment.