Skip to content

Commit

Permalink
Log reserved
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Oct 25, 2024
1 parent 8936898 commit 143aa04
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/scheduler/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ func (s *State) MarshalJSON() ([]byte, error) {
Capacity: s.Capacity,
Replicas: s.Replicas,
StatefulSetName: s.StatefulSetName,
PodSpread: toJSONable(s.PodSpread),
PodSpread: ToJSONable(s.PodSpread),
Pending: toJSONablePending(s.Pending),
}

return json.Marshal(sj)
}

func toJSONable(ps map[types.NamespacedName]map[string]int32) map[string]map[string]int32 {
func ToJSONable(ps map[types.NamespacedName]map[string]int32) map[string]map[string]int32 {
r := make(map[string]map[string]int32, len(ps))
for k, v := range ps {
r[k.String()] = v
Expand Down
11 changes: 8 additions & 3 deletions pkg/scheduler/statefulset/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ func (s *StatefulSetScheduler) scheduleVPod(ctx context.Context, vpod scheduler.
return nil, err
}

logger.Debugw("scheduling", zap.Any("state", state))

existingPlacements := vpod.GetPlacements()

reservedByPodName := make(map[string]int32, 2)
Expand All @@ -231,6 +229,13 @@ func (s *StatefulSetScheduler) scheduleVPod(ctx context.Context, vpod scheduler.
}
}

logger.Debugw("scheduling",
zap.Any("state", state),
zap.Any("reservedByPodName", reservedByPodName),
zap.Any("reserved", st.ToJSONable(s.reserved)),
zap.Any("vpod", vpod),
)

// Remove unschedulable or adjust overcommitted pods from placements
var placements []duckv1alpha1.Placement
if len(existingPlacements) > 0 {
Expand Down Expand Up @@ -505,4 +510,4 @@ func upsertPlacements(placements []duckv1alpha1.Placement, placement duckv1alpha
placements = append(placements, placement)
}
return placements
}
}

Check failure on line 513 in pkg/scheduler/statefulset/scheduler.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[EOF Newline] reported by reviewdog 🐶 Missing newline Raw Output: pkg/scheduler/statefulset/scheduler.go:513: Missing newline
74 changes: 73 additions & 1 deletion pkg/scheduler/statefulset/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func TestStatefulsetScheduler(t *testing.T) {
pending map[types.NamespacedName]int32
initialReserved map[types.NamespacedName]map[string]int32
expectedReserved map[types.NamespacedName]map[string]int32
capacity int32
}{
{
name: "no replicas, no vreplicas",
Expand Down Expand Up @@ -460,6 +461,72 @@ func TestStatefulsetScheduler(t *testing.T) {
},
},
},
{
name: "issue",
vreplicas: 32,
replicas: int32(2),
placements: []duckv1alpha1.Placement{
{PodName: "statefulset-name-0", VReplicas: 1},
},
expected: []duckv1alpha1.Placement{
{PodName: "statefulset-name-0", VReplicas: 13},
{PodName: "statefulset-name-1", VReplicas: 19},
},
initialReserved: map[types.NamespacedName]map[string]int32{
types.NamespacedName{Namespace: vpodNamespace + "-a", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-b", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-c", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-d", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-e", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-f", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-g", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace, Name: vpodName}: {
"statefulset-name-0": 1,
},
},
expectedReserved: map[types.NamespacedName]map[string]int32{
types.NamespacedName{Namespace: vpodNamespace + "-a", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-b", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-c", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-d", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-e", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-f", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace + "-g", Name: vpodName}: {
"statefulset-name-0": 1,
},
types.NamespacedName{Namespace: vpodNamespace, Name: vpodName}: {
"statefulset-name-0": 13,
"statefulset-name-1": 19,
},
},
capacity: 20,
},
}

for _, tc := range testCases {
Expand All @@ -480,13 +547,18 @@ func TestStatefulsetScheduler(t *testing.T) {
podlist = append(podlist, pod)
}

capacity := int32(0)
if tc.capacity > 0 {
capacity = tc.capacity
}

_, err := kubeclient.Get(ctx).AppsV1().StatefulSets(testNs).Create(ctx, tscheduler.MakeStatefulset(testNs, sfsName, tc.replicas), metav1.CreateOptions{})
if err != nil {
t.Fatal("unexpected error", err)
}
lsp := listers.NewListers(podlist)
scaleCache := scheduler.NewScaleCache(ctx, testNs, kubeclient.Get(ctx).AppsV1().StatefulSets(testNs), scheduler.ScaleCacheConfig{RefreshPeriod: time.Minute * 5})
sa := state.NewStateBuilder(sfsName, vpodClient.List, 10, lsp.GetPodLister().Pods(testNs), scaleCache)
sa := state.NewStateBuilder(sfsName, vpodClient.List, capacity, lsp.GetPodLister().Pods(testNs), scaleCache)
cfg := &Config{
StatefulSetNamespace: testNs,
StatefulSetName: sfsName,
Expand Down

0 comments on commit 143aa04

Please sign in to comment.