diff --git a/cmd/nfd-topology-updater/main.go b/cmd/nfd-topology-updater/main.go index 514c985530..c79bfc9dbe 100644 --- a/cmd/nfd-topology-updater/main.go +++ b/cmd/nfd-topology-updater/main.go @@ -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" @@ -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) diff --git a/pkg/nfd-topology-updater/nfd-topology-updater.go b/pkg/nfd-topology-updater/nfd-topology-updater.go index 7826a514e5..03ed03a268 100644 --- a/pkg/nfd-topology-updater/nfd-topology-updater.go +++ b/pkg/nfd-topology-updater/nfd-topology-updater.go @@ -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" @@ -60,6 +61,7 @@ type NfdTopologyUpdater interface { type staticNodeInfo struct { nodeName string tmPolicy string + tmScope string } type nfdTopologyUpdater struct { @@ -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{}, @@ -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{}) diff --git a/pkg/topologypolicy/topology-policy.go b/pkg/topologypolicy/topology-policy.go index aa723d8310..75b4fd6cf8 100644 --- a/pkg/topologypolicy/topology-policy.go +++ b/pkg/topologypolicy/topology-policy.go @@ -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 { @@ -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, + }, + } +}