Skip to content

Commit

Permalink
Advertise TopologyManger policy and scope as Attributes
Browse files Browse the repository at this point in the history
Signed-off-by: pprokop <[email protected]>
  • Loading branch information
PiotrProkop committed Feb 9, 2023
1 parent 1084ce8 commit 3c38cec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cmd/nfd-topology-updater/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

topology "sigs.k8s.io/node-feature-discovery/pkg/nfd-topology-updater"
"sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor"
"sigs.k8s.io/node-feature-discovery/pkg/topologypolicy"
"sigs.k8s.io/node-feature-discovery/pkg/utils"
"sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath"
"sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf"
Expand Down Expand Up @@ -88,11 +87,13 @@ func main() {
klog.Exitf("unsupported URI scheme: %v", u.Scheme)
}

tmPolicy := string(topologypolicy.DetectTopologyPolicy(klConfig.TopologyManagerPolicy, klConfig.TopologyManagerScope))
tmPolicy := string(klConfig.TopologyManagerPolicy)
klog.Infof("detected kubelet Topology Manager policy %q", tmPolicy)
tmScope := string(klConfig.TopologyManagerScope)
klog.Infof("detected kubelet Topology Manager scope %q", tmScope)

// Get new TopologyUpdater instance
instance := topology.NewTopologyUpdater(*args, *resourcemonitorArgs, tmPolicy)
instance := topology.NewTopologyUpdater(*args, *resourcemonitorArgs, tmPolicy, tmScope)

if err = instance.Run(); err != nil {
klog.Exit(err)
Expand Down
8 changes: 6 additions & 2 deletions pkg/nfd-topology-updater/nfd-topology-updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/node-feature-discovery/pkg/apihelper"
"sigs.k8s.io/node-feature-discovery/pkg/podres"
"sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor"
"sigs.k8s.io/node-feature-discovery/pkg/topologypolicy"
"sigs.k8s.io/node-feature-discovery/pkg/utils"
"sigs.k8s.io/node-feature-discovery/pkg/version"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -60,6 +61,7 @@ type NfdTopologyUpdater interface {
type staticNodeInfo struct {
nodeName string
tmPolicy string
tmScope string
}

type nfdTopologyUpdater struct {
Expand All @@ -73,13 +75,14 @@ type nfdTopologyUpdater struct {
}

// NewTopologyUpdater creates a new NfdTopologyUpdater instance.
func NewTopologyUpdater(args Args, resourcemonitorArgs resourcemonitor.Args, policy string) NfdTopologyUpdater {
func NewTopologyUpdater(args Args, resourcemonitorArgs resourcemonitor.Args, policy, scope string) NfdTopologyUpdater {
nfd := &nfdTopologyUpdater{
args: args,
resourcemonitorArgs: resourcemonitorArgs,
nodeInfo: &staticNodeInfo{
nodeName: utils.NodeName(),
tmPolicy: policy,
tmScope: scope,
},
stop: make(chan struct{}, 1),
config: &NFDConfig{},
Expand Down Expand Up @@ -185,7 +188,8 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
Name: w.nodeInfo.nodeName,
},
Zones: zoneInfo,
TopologyPolicies: []string{w.nodeInfo.tmPolicy},
TopologyPolicies: []string{string(topologypolicy.DetectTopologyPolicy(w.nodeInfo.tmPolicy, w.nodeInfo.tmScope))},
Attributes: topologypolicy.DetectTopologyAttributes(w.nodeInfo.tmPolicy, w.nodeInfo.tmScope),
}

_, err := cli.TopologyV1alpha2().NodeResourceTopologies().Create(context.TODO(), &nrtNew, metav1.CreateOptions{})
Expand Down
20 changes: 20 additions & 0 deletions pkg/topologypolicy/topology-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import (
"k8s.io/kubernetes/pkg/kubelet/apis/config"
)

type AttributeName string

const (
TopologyManagerPolicyAttributeName = "topologyManagerPolicy"
TopologyManagerScopeAttributeName = "topologyManagerScope"
)

// DetectTopologyPolicy returns string type which present
// both Topology manager policy and scope
func DetectTopologyPolicy(policy string, scope string) v1alpha2.TopologyManagerPolicy {
Expand Down Expand Up @@ -63,3 +70,16 @@ func detectPolicyContainerScope(policy string) v1alpha2.TopologyManagerPolicy {
return v1alpha2.None
}
}

func DetectTopologyAttributes(policy string, scope string) v1alpha2.AttributeList {
return v1alpha2.AttributeList{
{
Name: TopologyManagerPolicyAttributeName,
Value: policy,
},
{
Name: TopologyManagerScopeAttributeName,
Value: scope,
},
}
}

0 comments on commit 3c38cec

Please sign in to comment.