Skip to content

Commit

Permalink
noderesourcetopology: move TM config utils in subpkg
Browse files Browse the repository at this point in the history
A upcoming change in the overreserve cache wants to
consume nodeconfig utilities, so in order to enable both
packages to consume this code, we move it in its own
package. Trivial code movement and only necessary interface
changes (renames/public <-> private symbols).

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Jan 22, 2024
1 parent 93c518b commit 6f34682
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 160 deletions.
5 changes: 3 additions & 2 deletions pkg/noderesourcetopology/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework"

topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/nodeconfig"
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/resourcerequests"
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/stringify"
"sigs.k8s.io/scheduler-plugins/pkg/util"
Expand Down Expand Up @@ -215,7 +216,7 @@ func (tm *TopologyMatch) Filter(ctx context.Context, cycleState *framework.Cycle

klog.V(5).InfoS("Found NodeResourceTopology", "nodeTopology", klog.KObj(nodeTopology))

handler := filterHandlerFromTopologyManagerConfig(topologyManagerConfigFromNodeResourceTopology(nodeTopology))
handler := filterHandlerFromTopologyManager(nodeconfig.TopologyManagerFromNodeResourceTopology(nodeTopology))
if handler == nil {
return nil
}
Expand Down Expand Up @@ -248,7 +249,7 @@ func subtractFromNUMA(nodes NUMANodeList, numaID int, container v1.Container) {
}
}

func filterHandlerFromTopologyManagerConfig(conf TopologyManagerConfig) filterFn {
func filterHandlerFromTopologyManager(conf nodeconfig.TopologyManager) filterFn {
if conf.Policy != kubeletconfig.SingleNumaNodeTopologyManagerPolicy {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package noderesourcetopology
package nodeconfig

import (
"fmt"

"k8s.io/klog/v2"
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"

Expand Down Expand Up @@ -45,28 +47,43 @@ func IsValidPolicy(policy string) bool {
return false
}

type TopologyManagerConfig struct {
type TopologyManager struct {
Scope string
Policy string
}

func makeTopologyManagerConfigDefaults() TopologyManagerConfig {
return TopologyManagerConfig{
func TopologyManagerDefaults() TopologyManager {
return TopologyManager{
Scope: kubeletconfig.ContainerTopologyManagerScope,
Policy: kubeletconfig.NoneTopologyManagerPolicy,
}
}

func topologyManagerConfigFromNodeResourceTopology(nodeTopology *topologyv1alpha2.NodeResourceTopology) TopologyManagerConfig {
conf := makeTopologyManagerConfigDefaults()
func TopologyManagerFromNodeResourceTopology(nodeTopology *topologyv1alpha2.NodeResourceTopology) TopologyManager {
conf := TopologyManagerDefaults()
cfg := &conf // shortcut
// Backward compatibility (v1alpha2 and previous). Deprecated, will be removed when the NRT API moves to v1beta1.
updateTopologyManagerConfigFromTopologyPolicies(&conf, nodeTopology.Name, nodeTopology.TopologyPolicies)
cfg.updateFromPolicies(nodeTopology.Name, nodeTopology.TopologyPolicies)
// preferred new configuration source (v1alpha2 and onwards)
updateTopologyManagerConfigFromAttributes(&conf, nodeTopology.Attributes)
cfg.updateFromAttributes(nodeTopology.Attributes)
return conf
}

func updateTopologyManagerConfigFromAttributes(conf *TopologyManagerConfig, attrs topologyv1alpha2.AttributeList) {
func (conf TopologyManager) String() string {
return fmt.Sprintf("policy=%q scope=%q", conf.Policy, conf.Scope)
}

func (conf TopologyManager) Equal(other TopologyManager) bool {
if conf.Scope != other.Scope {
return false
}
if conf.Policy != other.Policy {
return false
}
return true
}

func (conf *TopologyManager) updateFromAttributes(attrs topologyv1alpha2.AttributeList) {
for _, attr := range attrs {
if attr.Name == AttributeScope && IsValidScope(attr.Value) {
conf.Scope = attr.Value
Expand All @@ -80,7 +97,7 @@ func updateTopologyManagerConfigFromAttributes(conf *TopologyManagerConfig, attr
}
}

func updateTopologyManagerConfigFromTopologyPolicies(conf *TopologyManagerConfig, nodeName string, topologyPolicies []string) {
func (conf *TopologyManager) updateFromPolicies(nodeName string, topologyPolicies []string) {
if len(topologyPolicies) == 0 {
klog.V(3).InfoS("Cannot determine policy", "node", nodeName)
return
Expand Down
Loading

0 comments on commit 6f34682

Please sign in to comment.