Skip to content

Commit 51d27b6

Browse files
authored
Merge pull request #710 from ffromani/nrt-klog-to-logr
[noderesourcetopology] move logging to the logr interface
2 parents 2d20310 + 045a43d commit 51d27b6

32 files changed

+475
-407
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/dustin/go-humanize v1.0.1
1010
github.com/go-logr/logr v1.3.0
1111
github.com/google/go-cmp v0.6.0
12-
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1
12+
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2
1313
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2
1414
github.com/patrickmn/go-cache v2.1.0+incompatible
1515
github.com/paypal/load-watcher v0.2.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,8 +1497,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
14971497
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
14981498
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
14991499
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
1500-
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1 h1:BI3L7hNqRvXtB42FO4NI/0ZjDDVRPOMBDFLShhFtf28=
1501-
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.1/go.mod h1:AkACMQGiTgCt0lQw3m7TTU8PLH9lYKNK5e9DqFf5VuM=
1500+
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2 h1:uAwqOtyrFYggq3pVf3hs1XKkBxrQ8dkgjWz3LCLJsiY=
1501+
github.com/k8stopologyawareschedwg/noderesourcetopology-api v0.1.2/go.mod h1:LBzS4n6GX1C69tzSd5EibZ9cGOXFuHP7GxEMDYVe1sM=
15021502
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2 h1:iFHPfZInM9pz2neye5RdmORMp1hPmte1EGJYpOOzZVg=
15031503
github.com/k8stopologyawareschedwg/podfingerprint v0.2.2/go.mod h1:C23pM15t06dXg/OihGlqBvnYzLr+MXDXJ7zMfbNAyXI=
15041504
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=

pkg/noderesourcetopology/cache/discardreserved.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ import (
2020
"context"
2121
"sync"
2222

23+
"github.com/go-logr/logr"
2324
topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
2425

2526
corev1 "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/types"
2728
"k8s.io/klog/v2"
2829

2930
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
31+
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/logging"
3032
)
3133

3234
// DiscardReserved is intended to solve similiar problem as Overreserve Cache,
@@ -45,12 +47,14 @@ type DiscardReserved struct {
4547
rMutex sync.RWMutex
4648
reservationMap map[string]map[types.UID]bool // Key is NodeName, value is Pod UID : reserved status
4749
client ctrlclient.Client
50+
lh logr.Logger
4851
}
4952

50-
func NewDiscardReserved(client ctrlclient.Client) Interface {
53+
func NewDiscardReserved(lh logr.Logger, client ctrlclient.Client) Interface {
5154
return &DiscardReserved{
5255
client: client,
5356
reservationMap: make(map[string]map[types.UID]bool),
57+
lh: lh,
5458
}
5559
}
5660

@@ -74,7 +78,7 @@ func (pt *DiscardReserved) NodeMaybeOverReserved(nodeName string, pod *corev1.Po
7478
func (pt *DiscardReserved) NodeHasForeignPods(nodeName string, pod *corev1.Pod) {}
7579

7680
func (pt *DiscardReserved) ReserveNodeResources(nodeName string, pod *corev1.Pod) {
77-
klog.V(5).InfoS("nrtcache NRT Reserve", "logID", klog.KObj(pod), "UID", pod.GetUID(), "node", nodeName)
81+
pt.lh.V(5).Info("NRT Reserve", "logID", logging.PodLogID(pod), "podUID", pod.GetUID(), "node", nodeName)
7882
pt.rMutex.Lock()
7983
defer pt.rMutex.Unlock()
8084

@@ -85,14 +89,14 @@ func (pt *DiscardReserved) ReserveNodeResources(nodeName string, pod *corev1.Pod
8589
}
8690

8791
func (pt *DiscardReserved) UnreserveNodeResources(nodeName string, pod *corev1.Pod) {
88-
klog.V(5).InfoS("nrtcache NRT Unreserve", "logID", klog.KObj(pod), "UID", pod.GetUID(), "node", nodeName)
92+
pt.lh.V(5).Info("NRT Unreserve", "logID", klog.KObj(pod), "podUID", pod.GetUID(), "node", nodeName)
8993

9094
pt.removeReservationForNode(nodeName, pod)
9195
}
9296

9397
// PostBind is invoked to cleanup reservationMap
9498
func (pt *DiscardReserved) PostBind(nodeName string, pod *corev1.Pod) {
95-
klog.V(5).InfoS("nrtcache NRT PostBind", "logID", klog.KObj(pod), "UID", pod.GetUID(), "node", nodeName)
99+
pt.lh.V(5).Info("NRT PostBind", "logID", klog.KObj(pod), "podUID", pod.GetUID(), "node", nodeName)
96100

97101
pt.removeReservationForNode(nodeName, pod)
98102
}

pkg/noderesourcetopology/cache/discardreserved_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/types"
2828
podlisterv1 "k8s.io/client-go/listers/core/v1"
29+
"k8s.io/klog/v2"
2930

3031
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3132
)
@@ -50,7 +51,7 @@ func TestDiscardReservedNodesGetCachedNRTCopy(t *testing.T) {
5051
checkGetCachedNRTCopy(
5152
t,
5253
func(client ctrlclient.Client, _ podlisterv1.PodLister) (Interface, error) {
53-
return NewDiscardReserved(client), nil
54+
return NewDiscardReserved(klog.Background(), client), nil
5455
},
5556
testCases...,
5657
)

pkg/noderesourcetopology/cache/foreign_pods.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ limitations under the License.
1717
package cache
1818

1919
import (
20+
"fmt"
21+
22+
"github.com/go-logr/logr"
2023
corev1 "k8s.io/api/core/v1"
2124
"k8s.io/apimachinery/pkg/util/sets"
2225
k8scache "k8s.io/client-go/tools/cache"
23-
"k8s.io/klog/v2"
2426

27+
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/logging"
2528
"sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/resourcerequests"
2629
)
2730

@@ -35,19 +38,19 @@ var (
3538
onlyExclusiveResources = false
3639
)
3740

38-
func SetupForeignPodsDetector(schedProfileName string, podInformer k8scache.SharedInformer, cc Interface) {
41+
func SetupForeignPodsDetector(lh logr.Logger, schedProfileName string, podInformer k8scache.SharedInformer, cc Interface) {
3942
foreignCache := func(obj interface{}) {
4043
pod, ok := obj.(*corev1.Pod)
4144
if !ok {
42-
klog.V(3).InfoS("nrtcache: foreign: unsupported object %T", obj)
45+
lh.V(3).Info("unsupported object", "kind", fmt.Sprintf("%T", obj))
4346
return
4447
}
4548
if !IsForeignPod(pod) {
4649
return
4750
}
4851

4952
cc.NodeHasForeignPods(pod.Spec.NodeName, pod)
50-
klog.V(6).InfoS("nrtcache: has foreign pods", "logID", klog.KObj(pod), "node", pod.Spec.NodeName, "podUID", pod.UID)
53+
lh.V(6).Info("detected foreign pods", "logID", logging.PodLogID(pod), "podUID", pod.GetUID(), "node", pod.Spec.NodeName)
5154
}
5255

5356
podInformer.AddEventHandler(k8scache.ResourceEventHandlerFuncs{
@@ -67,11 +70,11 @@ func TrackAllForeignPods() {
6770
onlyExclusiveResources = false
6871
}
6972

70-
func RegisterSchedulerProfileName(schedProfileName string) {
71-
klog.InfoS("nrtcache: setting up foreign pod detection", "profile", schedProfileName)
73+
func RegisterSchedulerProfileName(lh logr.Logger, schedProfileName string) {
74+
lh.Info("setting up detection", "profile", schedProfileName)
7275
schedProfileNames.Insert(schedProfileName)
7376

74-
klog.V(5).InfoS("nrtcache: registered scheduler profiles", "names", schedProfileNames.List())
77+
lh.V(5).Info("registered scheduler profiles", "names", schedProfileNames.List())
7578
}
7679

7780
func IsForeignPod(pod *corev1.Pod) bool {

pkg/noderesourcetopology/cache/foreign_pods_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
"k8s.io/apimachinery/pkg/api/resource"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/klog/v2"
2526
)
2627

2728
func TestIsForeignPod(t *testing.T) {
@@ -195,7 +196,7 @@ func TestIsForeignPod(t *testing.T) {
195196
for _, tt := range tests {
196197
t.Run(tt.name, func(t *testing.T) {
197198
for _, profileName := range tt.profileNames {
198-
RegisterSchedulerProfileName(profileName)
199+
RegisterSchedulerProfileName(klog.Background(), profileName)
199200
}
200201
defer CleanRegisteredSchedulerProfileNames()
201202

0 commit comments

Comments
 (0)