Skip to content

Commit

Permalink
Scheduler: log expected vreplicas by vpod (#8449)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi authored Feb 13, 2025
1 parent 36d681e commit d9498eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
30 changes: 16 additions & 14 deletions pkg/scheduler/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,25 @@ func isPodUnschedulable(pod *v1.Pod) bool {
func (s *State) MarshalJSON() ([]byte, error) {

type S struct {
FreeCap []int32 `json:"freeCap"`
SchedulablePods []int32 `json:"schedulablePods"`
Capacity int32 `json:"capacity"`
Replicas int32 `json:"replicas"`
StatefulSetName string `json:"statefulSetName"`
PodSpread map[string]map[string]int32 `json:"podSpread"`
Pending map[string]int32 `json:"pending"`
FreeCap []int32 `json:"freeCap"`
SchedulablePods []int32 `json:"schedulablePods"`
Capacity int32 `json:"capacity"`
Replicas int32 `json:"replicas"`
StatefulSetName string `json:"statefulSetName"`
PodSpread map[string]map[string]int32 `json:"podSpread"`
Pending map[string]int32 `json:"pending"`
ExpectedVReplicaByVPod map[string]int32 `json:"expectedVReplicaByVPod"`
}

sj := S{
FreeCap: s.FreeCap,
SchedulablePods: s.SchedulablePods,
Capacity: s.Capacity,
Replicas: s.Replicas,
StatefulSetName: s.StatefulSetName,
PodSpread: ToJSONable(s.PodSpread),
Pending: toJSONablePending(s.Pending),
FreeCap: s.FreeCap,
SchedulablePods: s.SchedulablePods,
Capacity: s.Capacity,
Replicas: s.Replicas,
StatefulSetName: s.StatefulSetName,
PodSpread: ToJSONable(s.PodSpread),
Pending: toJSONablePending(s.Pending),
ExpectedVReplicaByVPod: toJSONablePending(s.ExpectedVReplicaByVPod),
}

return json.Marshal(sj)
Expand Down
10 changes: 6 additions & 4 deletions pkg/scheduler/statefulset/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,19 @@ func (a *autoscaler) doautoscale(ctx context.Context, attemptScaleDown bool) err
return err
}

logger.Debugw("checking adapter capacity",
zap.Int32("replicas", scale.Spec.Replicas),
zap.Any("state", state))

newReplicas := integer.Int32Max(int32(math.Ceil(float64(state.TotalExpectedVReplicas())/float64(state.Capacity))), a.minReplicas)

// Only scale down if permitted
if !attemptScaleDown && newReplicas < scale.Spec.Replicas {
newReplicas = scale.Spec.Replicas
}

logger.Debugw("checking adapter capacity",
zap.Bool("attemptScaleDown", attemptScaleDown),
zap.Int32("replicas", scale.Spec.Replicas),
zap.Int32("newReplicas", newReplicas),
zap.Any("state", state))

if newReplicas != scale.Spec.Replicas {
scale.Spec.Replicas = newReplicas
logger.Infow("updating adapter replicas", zap.Int32("replicas", scale.Spec.Replicas))
Expand Down

0 comments on commit d9498eb

Please sign in to comment.