Skip to content

Commit

Permalink
Add test case with many buildpods
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed May 8, 2024
1 parent d7823ed commit 7c9400f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/build/buildkit/scaler/downscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func RunDownscaler(ctx context.Context, clientset kubernetes.Interface, podSelec
}

if usageAt == -1 {
maxEndtimeByNS[pod.Namespace] = usageAt
continue
}

Expand Down
60 changes: 60 additions & 0 deletions pkg/build/buildkit/scaler/downscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,63 @@ func TestRunDownscalerWithManyPods(t *testing.T) {
require.Len(t, rs.Items, 1)
assert.Equal(t, int32(0), *rs.Items[0].Spec.Replicas)
}

func TestRunDownscalerWithManyPods2(t *testing.T) {
ctx := context.Background()

lastBuild := time.Now().Add(-3 * time.Hour).Unix()

cli := fake.NewSimpleClientset(
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "buildkit-0",
Namespace: "default",
Labels: map[string]string{
"app": "buildkit",
},

Annotations: map[string]string{
metadata.DeployAgentLastBuildStartingLabelKey: strconv.Itoa(int(lastBuild)),
},
},
Spec: corev1.PodSpec{},
},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "buildkit-1",
Namespace: "default",
Labels: map[string]string{
"app": "buildkit",
},

Annotations: map[string]string{
metadata.DeployAgentLastBuildStartingLabelKey: strconv.Itoa(int(lastBuild)),
metadata.DeployAgentLastBuildEndingTimeLabelKey: strconv.Itoa(int(lastBuild)),
},
},
Spec: corev1.PodSpec{},
},
&appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "buildkit",
Namespace: "default",

Annotations: map[string]string{
metadata.DeployAgentLastReplicasAnnotationKey: "3",
},
},
Spec: appsv1.StatefulSetSpec{
Replicas: ptr.To(int32(2)),
},
},
)

err := RunDownscaler(ctx, cli, "app=buildkit", "buildkit", testGraceful)
assert.NoError(t, err)

rs, err := cli.AppsV1().StatefulSets("").List(ctx, metav1.ListOptions{})
assert.NoError(t, err)

require.Len(t, rs.Items, 1)
assert.Equal(t, int32(2), *rs.Items[0].Spec.Replicas)
}

0 comments on commit 7c9400f

Please sign in to comment.