...

Source file src/k8s.io/kubernetes/test/integration/scheduler_perf/scheduler_test.go

Documentation: k8s.io/kubernetes/test/integration/scheduler_perf

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package benchmark
    18  
    19  import (
    20  	"testing"
    21  
    22  	utilfeature "k8s.io/apiserver/pkg/util/feature"
    23  	featuregatetesting "k8s.io/component-base/featuregate/testing"
    24  	"k8s.io/kubernetes/test/integration/framework"
    25  	"k8s.io/kubernetes/test/utils/ktesting"
    26  )
    27  
    28  func TestScheduling(t *testing.T) {
    29  	testCases, err := getTestCases(configFile)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	if err = validateTestCases(testCases); err != nil {
    34  		t.Fatal(err)
    35  	}
    36  
    37  	// Check for leaks at the very end.
    38  	framework.GoleakCheck(t)
    39  
    40  	// All integration test cases share the same etcd, similar to
    41  	// https://github.com/kubernetes/kubernetes/blob/18d05b646d09b2971dc5400bc288062b0414e8cf/test/integration/framework/etcd.go#L186-L222.
    42  	framework.StartEtcd(t, nil)
    43  
    44  	// Workloads with the same configuration share the same apiserver. For that
    45  	// we first need to determine what those different configs are.
    46  	var configs []schedulerConfig
    47  	for _, tc := range testCases {
    48  		tcEnabled := false
    49  		for _, w := range tc.Workloads {
    50  			if enabled(*testSchedulingLabelFilter, append(tc.Labels, w.Labels...)...) {
    51  				tcEnabled = true
    52  				break
    53  			}
    54  		}
    55  		if !tcEnabled {
    56  			continue
    57  		}
    58  		exists := false
    59  		for _, config := range configs {
    60  			if config.equals(tc) {
    61  				exists = true
    62  				break
    63  			}
    64  		}
    65  		if !exists {
    66  			configs = append(configs, schedulerConfig{schedulerConfigPath: tc.SchedulerConfigPath, featureGates: tc.FeatureGates})
    67  		}
    68  	}
    69  	for _, config := range configs {
    70  		// Not a sub test because we don't have a good name for it.
    71  		func() {
    72  			tCtx := ktesting.Init(t)
    73  
    74  			// No timeout here because the `go test -timeout` will ensure that
    75  			// the test doesn't get stuck forever.
    76  
    77  			for feature, flag := range config.featureGates {
    78  				defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, feature, flag)()
    79  			}
    80  			informerFactory, tCtx := setupClusterForWorkload(tCtx, config.schedulerConfigPath, config.featureGates, nil)
    81  
    82  			for _, tc := range testCases {
    83  				if !config.equals(tc) {
    84  					// Runs with some other config.
    85  					continue
    86  				}
    87  
    88  				t.Run(tc.Name, func(t *testing.T) {
    89  					for _, w := range tc.Workloads {
    90  						t.Run(w.Name, func(t *testing.T) {
    91  							if !enabled(*testSchedulingLabelFilter, append(tc.Labels, w.Labels...)...) {
    92  								t.Skipf("disabled by label filter %q", *testSchedulingLabelFilter)
    93  							}
    94  							tCtx := ktesting.WithTB(tCtx, t)
    95  							runWorkload(tCtx, tc, w, informerFactory)
    96  						})
    97  					}
    98  				})
    99  			}
   100  		}()
   101  	}
   102  }
   103  

View as plain text