Skip to content

Commit 862667a

Browse files
authored
Merge pull request #655 from zwpaper/refactor-ctrl-runtime-capacity
migrate nrt to ctrl runtime client
2 parents 0ae911e + 0b5755d commit 862667a

File tree

83 files changed

+1053
-5154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1053
-5154
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/patrickmn/go-cache v2.1.0+incompatible
1414
github.com/paypal/load-watcher v0.2.3
1515
github.com/spf13/pflag v1.0.5
16-
github.com/stretchr/testify v1.8.1
16+
github.com/stretchr/testify v1.8.4
1717
gonum.org/v1/gonum v0.12.0
1818
k8s.io/api v0.27.7
1919
k8s.io/apimachinery v0.27.7

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
472472
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
473473
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
474474
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
475-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
476475
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
476+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
477+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
477478
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
478479
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE=
479480
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=

manifests/noderesourcetopology/crd.yaml

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -18,124 +18,6 @@ spec:
1818
singular: noderesourcetopology
1919
scope: Cluster
2020
versions:
21-
- name: v1alpha1
22-
schema:
23-
openAPIV3Schema:
24-
description: NodeResourceTopology describes node resources and their topology.
25-
properties:
26-
apiVersion:
27-
description: 'APIVersion defines the versioned schema of this representation
28-
of an object. Servers should convert recognized schemas to the latest
29-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
30-
type: string
31-
kind:
32-
description: 'Kind is a string value representing the REST resource this
33-
object represents. Servers may infer this from the endpoint the client
34-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
35-
type: string
36-
metadata:
37-
type: object
38-
topologyPolicies:
39-
items:
40-
type: string
41-
type: array
42-
zones:
43-
description: ZoneList contains an array of Zone objects.
44-
items:
45-
description: Zone represents a resource topology zone, e.g. socket,
46-
node, die or core.
47-
properties:
48-
attributes:
49-
description: AttributeList contains an array of AttributeInfo objects.
50-
items:
51-
description: AttributeInfo contains one attribute of a Zone.
52-
properties:
53-
name:
54-
type: string
55-
value:
56-
type: string
57-
required:
58-
- name
59-
- value
60-
type: object
61-
type: array
62-
costs:
63-
description: CostList contains an array of CostInfo objects.
64-
items:
65-
description: CostInfo describes the cost (or distance) between
66-
two Zones.
67-
properties:
68-
name:
69-
type: string
70-
value:
71-
format: int64
72-
type: integer
73-
required:
74-
- name
75-
- value
76-
type: object
77-
type: array
78-
name:
79-
type: string
80-
parent:
81-
type: string
82-
resources:
83-
description: ResourceInfoList contains an array of ResourceInfo
84-
objects.
85-
items:
86-
description: ResourceInfo contains information about one resource
87-
type.
88-
properties:
89-
allocatable:
90-
anyOf:
91-
- type: integer
92-
- type: string
93-
description: Allocatable quantity of the resource, corresponding
94-
to allocatable in node status, i.e. total amount of this
95-
resource available to be used by pods.
96-
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
97-
x-kubernetes-int-or-string: true
98-
available:
99-
anyOf:
100-
- type: integer
101-
- type: string
102-
description: Available is the amount of this resource currently
103-
available for new (to be scheduled) pods, i.e. Allocatable
104-
minus the resources reserved by currently running pods.
105-
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
106-
x-kubernetes-int-or-string: true
107-
capacity:
108-
anyOf:
109-
- type: integer
110-
- type: string
111-
description: Capacity of the resource, corresponding to capacity
112-
in node status, i.e. total amount of this resource that
113-
the node has.
114-
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
115-
x-kubernetes-int-or-string: true
116-
name:
117-
description: Name of the resource.
118-
type: string
119-
required:
120-
- allocatable
121-
- available
122-
- capacity
123-
- name
124-
type: object
125-
type: array
126-
type:
127-
type: string
128-
required:
129-
- name
130-
- type
131-
type: object
132-
type: array
133-
required:
134-
- topologyPolicies
135-
- zones
136-
type: object
137-
served: true
138-
storage: false
13921
- name: v1alpha2
14022
schema:
14123
openAPIV3Schema:

pkg/networkaware/networkoverhead/networkoverhead.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ const (
6161
preFilterStateKey = "PreFilter" + Name
6262
)
6363

64+
var scheme = runtime.NewScheme()
65+
66+
func init() {
67+
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
68+
69+
utilruntime.Must(agv1alpha1.AddToScheme(scheme))
70+
utilruntime.Must(ntv1alpha1.AddToScheme(scheme))
71+
}
72+
6473
// NetworkOverhead : Filter and Score nodes based on Pod's AppGroup requirements: MaxNetworkCosts requirements among Pods with dependencies
6574
type NetworkOverhead struct {
6675
client.Client
@@ -137,14 +146,6 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
137146
if err != nil {
138147
return nil, err
139148
}
140-
141-
scheme := runtime.NewScheme()
142-
143-
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
144-
145-
utilruntime.Must(agv1alpha1.AddToScheme(scheme))
146-
utilruntime.Must(ntv1alpha1.AddToScheme(scheme))
147-
148149
client, err := client.New(handle.KubeConfig(), client.Options{
149150
Scheme: scheme,
150151
})

pkg/networkaware/networkoverhead/networkoverhead_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/util/wait"
3333
"k8s.io/client-go/informers"
3434
testClientSet "k8s.io/client-go/kubernetes/fake"
35-
"k8s.io/client-go/kubernetes/scheme"
35+
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3636
"k8s.io/client-go/util/workqueue"
3737
"k8s.io/kubernetes/pkg/scheduler/framework"
3838
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
@@ -488,7 +488,7 @@ func BenchmarkNetworkOverheadPreFilter(b *testing.B) {
488488

489489
for _, tt := range tests {
490490
b.Run(tt.name, func(b *testing.B) {
491-
s := scheme.Scheme
491+
s := clientgoscheme.Scheme
492492
utilruntime.Must(agv1alpha1.AddToScheme(s))
493493
utilruntime.Must(ntv1alpha1.AddToScheme(s))
494494

@@ -716,7 +716,7 @@ func TestNetworkOverheadScore(t *testing.T) {
716716
}
717717
for _, tt := range tests {
718718
t.Run(tt.name, func(t *testing.T) {
719-
s := scheme.Scheme
719+
s := clientgoscheme.Scheme
720720
utilruntime.Must(agv1alpha1.AddToScheme(s))
721721
utilruntime.Must(ntv1alpha1.AddToScheme(s))
722722

@@ -956,7 +956,7 @@ func BenchmarkNetworkOverheadScore(b *testing.B) {
956956

957957
for _, tt := range tests {
958958
b.Run(tt.name, func(b *testing.B) {
959-
s := scheme.Scheme
959+
s := clientgoscheme.Scheme
960960
utilruntime.Must(agv1alpha1.AddToScheme(s))
961961
utilruntime.Must(ntv1alpha1.AddToScheme(s))
962962

@@ -1189,7 +1189,7 @@ func TestNetworkOverheadFilter(t *testing.T) {
11891189
}
11901190
for _, tt := range tests {
11911191
t.Run(tt.name, func(t *testing.T) {
1192-
s := scheme.Scheme
1192+
s := clientgoscheme.Scheme
11931193
utilruntime.Must(agv1alpha1.AddToScheme(s))
11941194
utilruntime.Must(ntv1alpha1.AddToScheme(s))
11951195

@@ -1413,7 +1413,7 @@ func BenchmarkNetworkOverheadFilter(b *testing.B) {
14131413

14141414
for _, tt := range tests {
14151415
b.Run(tt.name, func(b *testing.B) {
1416-
s := scheme.Scheme
1416+
s := clientgoscheme.Scheme
14171417
utilruntime.Must(agv1alpha1.AddToScheme(s))
14181418
utilruntime.Must(ntv1alpha1.AddToScheme(s))
14191419

pkg/networkaware/topologicalsort/topologicalsort.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ const (
4040
Name = "TopologicalSort"
4141
)
4242

43+
var scheme = runtime.NewScheme()
44+
45+
func init() {
46+
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
47+
utilruntime.Must(agv1alpha.AddToScheme(scheme))
48+
}
49+
4350
// TopologicalSort : Sort pods based on their AppGroup and corresponding microservice dependencies
4451
type TopologicalSort struct {
4552
client.Client
@@ -73,11 +80,6 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
7380
return nil, err
7481
}
7582

76-
scheme := runtime.NewScheme()
77-
78-
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
79-
utilruntime.Must(agv1alpha.AddToScheme(scheme))
80-
8183
client, err := client.New(handle.KubeConfig(), client.Options{
8284
Scheme: scheme,
8385
})

pkg/networkaware/topologicalsort/topologicalsort_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/apimachinery/pkg/runtime"
2929
"k8s.io/apimachinery/pkg/util/rand"
3030
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
31-
"k8s.io/client-go/kubernetes/scheme"
31+
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3232
"k8s.io/client-go/util/workqueue"
3333
"k8s.io/kubernetes/pkg/scheduler/framework"
3434
st "k8s.io/kubernetes/pkg/scheduler/testing"
@@ -249,7 +249,7 @@ func TestTopologicalSortLess(t *testing.T) {
249249
t.Run(tt.name, func(t *testing.T) {
250250
pods := makePodsAppGroup(tt.deploymentNames, tt.agName, tt.podPhase)
251251

252-
s := scheme.Scheme
252+
s := clientgoscheme.Scheme
253253
utilruntime.Must(agv1alpha1.AddToScheme(s))
254254
client := fake.NewClientBuilder().
255255
WithScheme(s).
@@ -429,7 +429,7 @@ func BenchmarkTopologicalSortPlugin(b *testing.B) {
429429

430430
pods := makePodsAppGroup(tt.deploymentNames, tt.agName, tt.podPhase)
431431

432-
s := scheme.Scheme
432+
s := clientgoscheme.Scheme
433433
utilruntime.Must(agv1alpha1.AddToScheme(s))
434434
client := fake.NewClientBuilder().
435435
WithScheme(s).

pkg/noderesourcetopology/cache/cache.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package cache
1818

1919
import (
20+
"context"
21+
2022
corev1 "k8s.io/api/core/v1"
2123

2224
topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
@@ -30,7 +32,7 @@ type Interface interface {
3032
// The pod argument is used only for logging purposes.
3133
// Returns a boolean to signal the caller if the NRT data is clean. If false, then the node has foreign
3234
// Pods detected - so it should be ignored or handled differently by the caller.
33-
GetCachedNRTCopy(nodeName string, pod *corev1.Pod) (*topologyv1alpha2.NodeResourceTopology, bool)
35+
GetCachedNRTCopy(ctx context.Context, nodeName string, pod *corev1.Pod) (*topologyv1alpha2.NodeResourceTopology, bool)
3436

3537
// NodeMaybeOverReserved declares a node was filtered out for not enough resources available.
3638
// This means this node is eligible for a resync. When a node is marked discarded (dirty), it matters not

pkg/noderesourcetopology/cache/discardreserved.go

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

1919
import (
20+
"context"
2021
"sync"
2122

23+
topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
24+
2225
corev1 "k8s.io/api/core/v1"
2326
"k8s.io/apimachinery/pkg/types"
2427
"k8s.io/klog/v2"
2528

26-
topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
27-
listerv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/listers/topology/v1alpha2"
29+
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
2830
)
2931

3032
// DiscardReserved is intended to solve similiar problem as Overreserve Cache,
@@ -42,17 +44,17 @@ import (
4244
type DiscardReserved struct {
4345
rMutex sync.RWMutex
4446
reservationMap map[string]map[types.UID]bool // Key is NodeName, value is Pod UID : reserved status
45-
lister listerv1alpha2.NodeResourceTopologyLister
47+
client ctrlclient.Client
4648
}
4749

48-
func NewDiscardReserved(lister listerv1alpha2.NodeResourceTopologyLister) Interface {
50+
func NewDiscardReserved(client ctrlclient.Client) Interface {
4951
return &DiscardReserved{
50-
lister: lister,
52+
client: client,
5153
reservationMap: make(map[string]map[types.UID]bool),
5254
}
5355
}
5456

55-
func (pt *DiscardReserved) GetCachedNRTCopy(nodeName string, _ *corev1.Pod) (*topologyv1alpha2.NodeResourceTopology, bool) {
57+
func (pt *DiscardReserved) GetCachedNRTCopy(ctx context.Context, nodeName string, _ *corev1.Pod) (*topologyv1alpha2.NodeResourceTopology, bool) {
5658
pt.rMutex.RLock()
5759
defer pt.rMutex.RUnlock()
5860
if t, ok := pt.reservationMap[nodeName]; ok {
@@ -61,8 +63,8 @@ func (pt *DiscardReserved) GetCachedNRTCopy(nodeName string, _ *corev1.Pod) (*to
6163
}
6264
}
6365

64-
nrt, err := pt.lister.Get(nodeName)
65-
if err != nil {
66+
nrt := &topologyv1alpha2.NodeResourceTopology{}
67+
if err := pt.client.Get(ctx, types.NamespacedName{Name: nodeName}, nrt); err != nil {
6668
return nil, false
6769
}
6870
return nrt, true

0 commit comments

Comments
 (0)