k8s.io/kubernetes@v1.29.3/test/integration/scheduler_perf/main_test.go (about)

     1  /*
     2  Copyright 2017 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  	"flag"
    21  	"fmt"
    22  	"os"
    23  	"strings"
    24  	"testing"
    25  
    26  	"k8s.io/apimachinery/pkg/util/runtime"
    27  	"k8s.io/component-base/featuregate"
    28  	"k8s.io/component-base/logs"
    29  	logsapi "k8s.io/component-base/logs/api/v1"
    30  	_ "k8s.io/component-base/logs/json/register"
    31  	"k8s.io/kubernetes/test/utils/ktesting"
    32  )
    33  
    34  func TestMain(m *testing.M) {
    35  	// Run with -v=2, this is the default log level in production.
    36  	ktesting.SetDefaultVerbosity(2)
    37  
    38  	// test/integration/framework/flags.go unconditionally initializes the
    39  	// logging flags. That's correct for most tests, but in the
    40  	// scheduler_perf test we want more control over the flags, therefore
    41  	// here strip them out.
    42  	var fs flag.FlagSet
    43  	flag.CommandLine.VisitAll(func(f *flag.Flag) {
    44  		switch f.Name {
    45  		case "log-flush-frequency", "v", "vmodule":
    46  			// These will be added below ourselves, don't copy.
    47  		default:
    48  			fs.Var(f.Value, f.Name, f.Usage)
    49  		}
    50  	})
    51  	flag.CommandLine = &fs
    52  
    53  	featureGate := featuregate.NewFeatureGate()
    54  	runtime.Must(logsapi.AddFeatureGates(featureGate))
    55  	flag.Var(featureGate, "feature-gate",
    56  		"A set of key=value pairs that describe feature gates for alpha/experimental features. "+
    57  			"Options are:\n"+strings.Join(featureGate.KnownFeatures(), "\n"))
    58  	c := logsapi.NewLoggingConfiguration()
    59  
    60  	// This would fail if we hadn't removed the logging flags above.
    61  	logsapi.AddGoFlags(c, flag.CommandLine)
    62  
    63  	flag.Parse()
    64  
    65  	logs.InitLogs()
    66  	if err := logsapi.ValidateAndApply(c, featureGate); err != nil {
    67  		fmt.Fprintf(os.Stderr, "%v\n", err)
    68  		os.Exit(1)
    69  	}
    70  
    71  	m.Run()
    72  }