Skip to content

Commit 7ad96fc

Browse files
committed
fix: unit test
1 parent 40df300 commit 7ad96fc

File tree

10 files changed

+32
-16
lines changed

10 files changed

+32
-16
lines changed

cmd/main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ func main() {
235235

236236
metricsRecorder := startMetricsRecorder(enableLeaderElection, mgr, gpuPricingMap)
237237

238-
// Initialize GPU allocator and set up watches
239-
allocator, portAllocator := startTensorFusionAllocators(ctx, mgr)
240-
241238
// Initialize Index allocator for Device Plugin communication
242239
indexAllocator, err := indexallocator.NewIndexAllocator(ctx, mgr.GetClient())
243240
if err != nil {
@@ -246,6 +243,9 @@ func main() {
246243
}
247244
_ = indexAllocator.SetupWithManager(ctx, mgr)
248245

246+
// Initialize GPU allocator and set up watches
247+
allocator, portAllocator := startTensorFusionAllocators(ctx, mgr, indexAllocator)
248+
249249
ensureLeaderInfoConfigMap(mgr)
250250

251251
startAutoScaler(mgr, allocator)
@@ -286,8 +286,9 @@ func addHealthCheckAPI(mgr manager.Manager) {
286286
func startTensorFusionAllocators(
287287
ctx context.Context,
288288
mgr manager.Manager,
289+
indexAllocator *indexallocator.IndexAllocator,
289290
) (*gpuallocator.GpuAllocator, *portallocator.PortAllocator) {
290-
allocator := gpuallocator.NewGpuAllocator(ctx, mgr.GetClient(), 10*time.Second)
291+
allocator := gpuallocator.NewGpuAllocator(ctx, indexAllocator, mgr.GetClient(), 10*time.Second)
291292
if err := allocator.SetupWithManager(ctx, mgr); err != nil {
292293
setupLog.Error(err, "unable to set up GPU allocator watches")
293294
os.Exit(1)

internal/autoscaler/autoscaler_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ var _ = BeforeSuite(func() {
155155
WorkerUnitPriceMap: make(map[string]map[string]metrics.RawBillingPricing),
156156
}
157157

158-
allocator = gpuallocator.NewGpuAllocator(ctx, mgr.GetClient(), 150*time.Millisecond)
158+
allocator = gpuallocator.NewGpuAllocator(ctx, nil, mgr.GetClient(), 150*time.Millisecond)
159159
err = allocator.SetupWithManager(ctx, mgr)
160160
Expect(err).ToNot(HaveOccurred())
161161

internal/controller/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ var _ = BeforeSuite(func() {
156156
WorkerUnitPriceMap: make(map[string]map[string]metrics.RawBillingPricing),
157157
}
158158

159-
allocator = gpuallocator.NewGpuAllocator(ctx, mgr.GetClient(), 150*time.Millisecond)
159+
allocator = gpuallocator.NewGpuAllocator(ctx, nil, mgr.GetClient(), 150*time.Millisecond)
160160
err = allocator.SetupWithManager(ctx, mgr)
161161
Expect(err).ToNot(HaveOccurred())
162162

internal/gpuallocator/gpuallocator.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ type GpuAllocator struct {
150150
indexAllocator *indexallocator.IndexAllocator
151151
}
152152

153-
func NewGpuAllocator(ctx context.Context, client client.Client, syncInterval time.Duration) *GpuAllocator {
153+
func NewGpuAllocator(
154+
ctx context.Context,
155+
indexAllocator *indexallocator.IndexAllocator,
156+
client client.Client,
157+
syncInterval time.Duration,
158+
) *GpuAllocator {
154159
log := log.FromContext(ctx)
155160

156161
if client == nil {
@@ -166,6 +171,15 @@ func NewGpuAllocator(ctx context.Context, client client.Client, syncInterval tim
166171
// Create quota store
167172
quotaStore := quota.NewQuotaStore(client, ctx)
168173

174+
if indexAllocator == nil {
175+
newIndexAllocator, err := indexallocator.NewIndexAllocator(ctx, client)
176+
if err != nil {
177+
log.Error(err, "Failed to create index allocator")
178+
return nil
179+
}
180+
indexAllocator = newIndexAllocator
181+
}
182+
169183
allocator := &GpuAllocator{
170184
Client: client,
171185
filterRegistry: baseRegistry,
@@ -178,6 +192,7 @@ func NewGpuAllocator(ctx context.Context, client client.Client, syncInterval tim
178192
dirtyQueue: make(map[types.NamespacedName]struct{}),
179193
ctx: ctx,
180194

195+
indexAllocator: indexAllocator,
181196
uniqueAllocation: make(map[string]*tfv1.AllocRequest, 512),
182197
uniqueDeallocation: make(map[string]struct{}, 512),
183198
podNamespaceNsToPodUID: make(map[string]string, 512),

internal/gpuallocator/gpuallocator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var _ = Describe("GPU Allocator", func() {
6666
}
6767

6868
BeforeEach(func() {
69-
allocator = NewGpuAllocator(ctx, k8sClient, 150*time.Millisecond)
69+
allocator = NewGpuAllocator(ctx, nil, k8sClient, 150*time.Millisecond)
7070
err := allocator.SetupWithManager(ctx, mgr)
7171
Expect(err).NotTo(HaveOccurred())
7272
<-allocator.initializedCh

internal/gpuallocator/quota_consolidated_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ var _ = Describe("GPUAllocator Quota Integration", func() {
377377
Build()
378378

379379
ctx := context.Background()
380-
allocator := NewGpuAllocator(ctx, client, 0)
380+
allocator := NewGpuAllocator(ctx, nil, client, 0)
381381

382382
initAllocator(allocator)
383383

@@ -415,7 +415,7 @@ var _ = Describe("GPUAllocator Quota Integration", func() {
415415
Build()
416416

417417
ctx := context.Background()
418-
allocator := NewGpuAllocator(ctx, client, 0)
418+
allocator := NewGpuAllocator(ctx, nil, client, 0)
419419

420420
initAllocator(allocator)
421421

@@ -451,7 +451,7 @@ var _ = Describe("GPUAllocator Concurrent Quota Enforcement", func() {
451451
Build()
452452

453453
ctx := context.Background()
454-
allocator := NewGpuAllocator(ctx, client, 0)
454+
allocator := NewGpuAllocator(ctx, nil, client, 0)
455455

456456
initAllocator(allocator)
457457

@@ -539,7 +539,7 @@ var _ = Describe("GPUAllocator Quota Reconciliation", func() {
539539
Build()
540540

541541
ctx := context.Background()
542-
allocator := NewGpuAllocator(ctx, client, 0)
542+
allocator := NewGpuAllocator(ctx, nil, client, 0)
543543

544544
initAllocator(allocator)
545545

internal/scheduler/expander/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (suite *NodeExpanderTestSuite) SetupSuite() {
5656
Expect(suite.k8sClient.Create(ctx, ns)).To(Succeed())
5757

5858
// Setup proper allocator for testing
59-
suite.allocator = gpuallocator.NewGpuAllocator(ctx, suite.k8sClient, time.Second)
59+
suite.allocator = gpuallocator.NewGpuAllocator(ctx, nil, suite.k8sClient, time.Second)
6060
err := suite.allocator.InitGPUAndQuotaStore()
6161
if err != nil {
6262
// For test environments, we can ignore some initialization errors

internal/scheduler/gpuresources/gpuresources_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (s *GPUResourcesSuite) SetupTest() {
259259
s.NoError(err)
260260
s.fwk = fwk
261261

262-
s.allocator = gpuallocator.NewGpuAllocator(s.ctx, s.client, time.Second)
262+
s.allocator = gpuallocator.NewGpuAllocator(s.ctx, nil, s.client, time.Second)
263263
err = s.allocator.InitGPUAndQuotaStore()
264264
s.NoError(err)
265265
s.allocator.ReconcileAllocationState()

internal/webhook/v1/pod_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (m *TensorFusionPodMutator) createOrUpdateWorkload(
310310
}
311311

312312
func (m *TensorFusionPodMutator) patchTFClient(
313-
_ctx context.Context,
313+
ctx context.Context,
314314
pod *corev1.Pod,
315315
pool *tfv1.GPUPool,
316316
isLocalGPU bool,

test/sched/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func setupFrameworkAndPlugin(
387387
func setupAllocator(
388388
b *testing.B, ctx context.Context, client client.Client,
389389
) *gpuallocator.GpuAllocator {
390-
allocator := gpuallocator.NewGpuAllocator(ctx, client, time.Second)
390+
allocator := gpuallocator.NewGpuAllocator(ctx, nil, client, time.Second)
391391
require.NoError(b, allocator.InitGPUAndQuotaStore())
392392
allocator.ReconcileAllocationState()
393393
allocator.SetAllocatorReady()

0 commit comments

Comments
 (0)