Skip to content

Commit 9d00999

Browse files
authored
fix: detect used by bug (#284)
1 parent aeaeca2 commit 9d00999

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

internal/constants/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const (
119119
HypervisorListenAddrEnv = "API_LISTEN_ADDR"
120120
HypervisorMetricsFormatEnv = "TF_HYPERVISOR_METRICS_FORMAT"
121121
HypervisorMetricsExtraLabelsEnv = "TF_HYPERVISOR_METRICS_EXTRA_LABELS"
122-
HypervisorDetectUsedGPUEnv = "DETECT_IN_USED_GPU"
122+
HypervisorDetectUsedGPUEnv = "DETECT_IN_USED_GPUS"
123123

124124
HypervisorDefaultPortNumber int32 = 8000
125125
HypervisorPortName string = "http"

internal/controller/gpu_controller.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ func (r *GPUReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
8888
return ctrl.Result{}, fmt.Errorf("node %s is not assigned to any pool", gpunode.Name)
8989
}
9090

91+
if gpu.Status.UsedBy == "" {
92+
patch := client.MergeFrom(gpu.DeepCopy())
93+
gpu.Status.UsedBy = tfv1.UsedByTensorFusion
94+
if err := r.Status().Patch(ctx, gpu, patch); err != nil {
95+
return ctrl.Result{}, fmt.Errorf("patch gpu %s: %w", gpu.Name, err)
96+
}
97+
return ctrl.Result{}, nil
98+
}
99+
91100
// No need to calculate patch since GPU's owner pool not changed
92101
if gpu.Labels != nil && gpu.Labels[constants.GpuPoolKey] == poolName {
93102
return ctrl.Result{}, nil
@@ -98,13 +107,10 @@ func (r *GPUReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
98107
gpu.Labels = make(map[string]string)
99108
}
100109
gpu.Labels[constants.GpuPoolKey] = poolName
101-
if gpu.Status.UsedBy == "" {
102-
gpu.Status.UsedBy = tfv1.UsedByTensorFusion
103-
}
104-
105110
if err := r.Patch(ctx, gpu, patch); err != nil {
106111
return ctrl.Result{}, fmt.Errorf("patch gpu %s: %w", gpu.Name, err)
107112
}
113+
108114
return ctrl.Result{}, nil
109115
}
110116

0 commit comments

Comments
 (0)