k8s.io/perf-tests/clusterloader2@v0.0.0-20240304094227-64bdb12da87e/pkg/test/interface.go (about)

     1  /*
     2  Copyright 2018 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 test
    18  
    19  import (
    20  	"time"
    21  
    22  	"k8s.io/perf-tests/clusterloader2/api"
    23  	"k8s.io/perf-tests/clusterloader2/pkg/chaos"
    24  	"k8s.io/perf-tests/clusterloader2/pkg/config"
    25  	"k8s.io/perf-tests/clusterloader2/pkg/errors"
    26  	"k8s.io/perf-tests/clusterloader2/pkg/framework"
    27  	"k8s.io/perf-tests/clusterloader2/pkg/measurement"
    28  	"k8s.io/perf-tests/clusterloader2/pkg/state"
    29  	"k8s.io/perf-tests/clusterloader2/pkg/tuningset"
    30  )
    31  
    32  // CreatContextFunc a type for function that creates Context based on given framework client and state.
    33  type CreatContextFunc func(c *config.ClusterLoaderConfig, f *framework.Framework, s *state.State) Context
    34  
    35  // OperationType is a type of operation to be performed on an object.
    36  type OperationType int
    37  
    38  const (
    39  	// createObject is create object operation.
    40  	createObject = OperationType(0)
    41  	// patchObject is update object (using patch) operation.
    42  	// TODO(krzysied): Figure out how to implement UPDATE_OBJECT operation.
    43  	patchObject = OperationType(1)
    44  	// deleteObject is delete object operation.
    45  	deleteObject = OperationType(2)
    46  )
    47  
    48  // Context is an interface for test context.
    49  // Test context provides framework client and cluster state.
    50  type Context interface {
    51  	GetClusterLoaderConfig() *config.ClusterLoaderConfig
    52  	GetClusterFramework() *framework.Framework
    53  	GetPrometheusFramework() *framework.Framework
    54  	GetTestReporter() Reporter
    55  	GetState() *state.State
    56  	GetTemplateMappingCopy() map[string]interface{}
    57  	GetTemplateProvider() *config.TemplateProvider
    58  	GetFactory() tuningset.Factory
    59  	GetManager() measurement.Manager
    60  	GetChaosMonkey() *chaos.Monkey
    61  	GetTestScenario() *api.TestScenario
    62  	GetTestConfig() *api.Config
    63  	SetTestConfig(*api.Config)
    64  }
    65  
    66  // Executor is an interface for test executing object.
    67  type Executor interface {
    68  	ExecuteTest(ctx Context, conf *api.Config) *errors.ErrorList
    69  	ExecuteStep(ctx Context, step *api.Step) *errors.ErrorList
    70  	ExecutePhase(ctx Context, phase *api.Phase) *errors.ErrorList
    71  	ExecuteObject(ctx Context, object *api.Object, namespace string, replicaIndex int32, operation OperationType) *errors.ErrorList
    72  }
    73  
    74  // Reporter is an interface for reporting tests results.
    75  type Reporter interface {
    76  	SetTestName(name string)
    77  	GetNumberOfFailedTestItems() int
    78  	BeginTestSuite()
    79  	EndTestSuite()
    80  	ReportTestStepFinish(duration time.Duration, stepName string, errList *errors.ErrorList)
    81  	ReportTestStep(result *StepResult)
    82  	ReportTestFinish(duration time.Duration, testConfigPath string, errList *errors.ErrorList)
    83  }