diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller_test.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller_test.go index fd91d7a0ada..030768829fe 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller_test.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_controller_test.go @@ -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) @@ -492,7 +492,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 { diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_provider_test.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_provider_test.go index 5c6fbb44bbb..79fa6534a56 100644 --- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_provider_test.go +++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_provider_test.go @@ -101,3 +101,30 @@ 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() + // Test #2: add 5 machineset-based nodegroups + machineSetConfigs := createMachineSetTestConfigs("namespace", "", RandomString(6), 5, 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() + } + }) +}