Skip to content

Commit

Permalink
UPSTREAM: 6796: Add benchmark for capi nodeGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed May 9, 2024
1 parent 6df103c commit 2797a0a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type testSpec struct {
const customCAPIGroup = "custom.x-k8s.io"
const fifteenSecondDuration = time.Second * 15

func mustCreateTestController(t *testing.T, testConfigs ...*testConfig) (*machineController, testControllerShutdownFunc) {
func mustCreateTestController(t testing.TB, testConfigs ...*testConfig) (*machineController, testControllerShutdownFunc) {
t.Helper()

nodeObjects := make([]runtime.Object, 0)
Expand Down Expand Up @@ -514,7 +514,7 @@ func makeLinkedNodeAndMachine(i int, namespace, clusterName string, owner metav1
return node, machine
}

func addTestConfigs(t *testing.T, controller *machineController, testConfigs ...*testConfig) error {
func addTestConfigs(t testing.TB, controller *machineController, testConfigs ...*testConfig) error {
t.Helper()

for _, config := range testConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,29 @@ func TestProviderConstructorProperties(t *testing.T) {
t.Fatalf("expected 0 GPU types, got %d", got)
}
}
func BenchmarkNodeGroups(b *testing.B) {
resourceLimits := cloudprovider.ResourceLimiter{}
annotations := map[string]string{
nodeGroupMinSizeAnnotationKey: "1",
nodeGroupMaxSizeAnnotationKey: "2",
}

controller, stop := mustCreateTestController(b)
defer stop()
machineSetConfigs := createMachineSetTestConfigs("namespace", "", RandomString(6), 100, 1, annotations, nil)
if err := addTestConfigs(b, controller, machineSetConfigs...); err != nil {
b.Fatalf("unexpected error: %v", err)
}

provider := newProvider(cloudprovider.ClusterAPIProviderName, &resourceLimits, controller)
if actual := provider.Name(); actual != cloudprovider.ClusterAPIProviderName {
b.Errorf("expected %q, got %q", cloudprovider.ClusterAPIProviderName, actual)
}

b.ResetTimer()
b.Run("NodeGroups", func(b *testing.B) {
for i := 0; i < b.N; i++ {
provider.NodeGroups()
}
})
}

0 comments on commit 2797a0a

Please sign in to comment.