diff --git a/pkg/kubelet/cm/BUILD b/pkg/kubelet/cm/BUILD index 51b892c222c..0b1e48698e5 100644 --- a/pkg/kubelet/cm/BUILD +++ b/pkg/kubelet/cm/BUILD @@ -1,10 +1,4 @@ -package(default_visibility = ["//visibility:public"]) - -load( - "@io_bazel_rules_go//go:def.bzl", - "go_library", - "go_test", -) +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", @@ -31,6 +25,7 @@ go_library( ], "//conditions:default": [], }), + visibility = ["//visibility:public"], deps = [ "//pkg/kubelet/apis/kubeletconfig:go_default_library", "//pkg/kubelet/cadvisor:go_default_library", @@ -108,8 +103,10 @@ filegroup( name = "all-srcs", srcs = [ ":package-srcs", + "//pkg/kubelet/cm/cpumanager:all-srcs", "//pkg/kubelet/cm/cpuset:all-srcs", "//pkg/kubelet/cm/util:all-srcs", ], tags = ["automanaged"], + visibility = ["//visibility:public"], ) diff --git a/pkg/kubelet/cm/cpumanager/BUILD b/pkg/kubelet/cm/cpumanager/BUILD new file mode 100644 index 00000000000..c496c8837d3 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/BUILD @@ -0,0 +1,34 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "cpu_manager.go", + "policy.go", + ], + visibility = ["//visibility:public"], + deps = [ + "//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library", + "//pkg/kubelet/cm/cpumanager/state:go_default_library", + "//pkg/kubelet/status:go_default_library", + "//vendor/k8s.io/api/core/v1:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//pkg/kubelet/cm/cpumanager/state:all-srcs", + "//pkg/kubelet/cm/cpumanager/topology:all-srcs", + ], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/kubelet/cm/cpumanager/OWNERS b/pkg/kubelet/cm/cpumanager/OWNERS new file mode 100644 index 00000000000..152ded29de0 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/OWNERS @@ -0,0 +1,6 @@ +approvers: +- derekwaynecarr +- vishh +- ConnorDoyle +- sjenning +- balajismaniam diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager.go b/pkg/kubelet/cm/cpumanager/cpu_manager.go new file mode 100644 index 00000000000..5da92348ffc --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/cpu_manager.go @@ -0,0 +1,53 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cpumanager + +import ( + "k8s.io/api/core/v1" + + runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" + "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state" + "k8s.io/kubernetes/pkg/kubelet/status" +) + +// ActivePodsFunc is a function that returns a list of pods to reconcile. +type ActivePodsFunc func() []*v1.Pod + +type runtimeService interface { + UpdateContainerResources(id string, resources *runtimeapi.LinuxContainerResources) error +} + +type policyName string + +// Manager interface provides methods for Kubelet to manage pod cpus. +type Manager interface { + // Start is called during Kubelet initialization. + Start(activePods ActivePodsFunc, podStatusProvider status.PodStatusProvider, containerRuntime runtimeService) + + // AddContainer is called between container create and container start + // so that initial CPU affinity settings can be written through to the + // container runtime before the first process begins to execute. + AddContainer(p *v1.Pod, c *v1.Container, containerID string) error + + // RemoveContainer is called after Kubelet decides to kill or delete a + // container. After this call, the CPU manager stops trying to reconcile + // that container and any CPUs dedicated to the container are freed. + RemoveContainer(containerID string) error + + // State returns a read-only interface to the internal CPU manager state. + State() state.Reader +} diff --git a/pkg/kubelet/cm/cpumanager/policy.go b/pkg/kubelet/cm/cpumanager/policy.go new file mode 100644 index 00000000000..39eb76316b1 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/policy.go @@ -0,0 +1,30 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cpumanager + +import ( + "k8s.io/api/core/v1" + "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state" +) + +// Policy implements logic for pod container to CPU assignment. +type Policy interface { + Name() string + Start(s state.State) + AddContainer(s state.State, pod *v1.Pod, container *v1.Container, containerID string) error + RemoveContainer(s state.State, containerID string) error +} diff --git a/pkg/kubelet/cm/cpumanager/state/BUILD b/pkg/kubelet/cm/cpumanager/state/BUILD new file mode 100644 index 00000000000..f90e24c96e5 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/state/BUILD @@ -0,0 +1,22 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["state.go"], + visibility = ["//visibility:public"], + deps = ["//pkg/kubelet/cm/cpuset:go_default_library"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/kubelet/cm/cpumanager/state/state.go b/pkg/kubelet/cm/cpumanager/state/state.go new file mode 100644 index 00000000000..98f7f7dc240 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/state/state.go @@ -0,0 +1,40 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package state + +import ( + "k8s.io/kubernetes/pkg/kubelet/cm/cpuset" +) + +// Reader interface used to read current cpu/pod assignment state +type Reader interface { + GetCPUSet(containerID string) (cpuset.CPUSet, bool) + GetDefaultCPUSet() cpuset.CPUSet + GetCPUSetOrDefault(containerID string) cpuset.CPUSet +} + +type writer interface { + SetCPUSet(containerID string, cpuset cpuset.CPUSet) + SetDefaultCPUSet(cpuset cpuset.CPUSet) + Delete(containerID string) +} + +// State interface provides methods for tracking and setting cpu/pod assignment +type State interface { + Reader + writer +} diff --git a/pkg/kubelet/cm/cpumanager/topology/BUILD b/pkg/kubelet/cm/cpumanager/topology/BUILD new file mode 100644 index 00000000000..df7277afab5 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/topology/BUILD @@ -0,0 +1,21 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["doc.go"], + visibility = ["//visibility:public"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/kubelet/cm/cpumanager/topology/doc.go b/pkg/kubelet/cm/cpumanager/topology/doc.go new file mode 100644 index 00000000000..76ff2299159 --- /dev/null +++ b/pkg/kubelet/cm/cpumanager/topology/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package topology contains helpers for the CPU manager. +package topology // import "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology"