Skip to content

Commit

Permalink
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 31fdc39 commit 761fd1e
Show file tree
Hide file tree
Showing 2 changed files with 29 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 @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
})
}

0 comments on commit 761fd1e

Please sign in to comment.