k8s.io/kubernetes@v1.29.3/test/integration/framework/controlplane_utils.go (about) 1 /* 2 Copyright 2014 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 framework 18 19 import ( 20 "path" 21 22 "github.com/google/uuid" 23 24 openapinamer "k8s.io/apiserver/pkg/endpoints/openapi" 25 genericapiserver "k8s.io/apiserver/pkg/server" 26 "k8s.io/apiserver/pkg/server/options" 27 "k8s.io/apiserver/pkg/storage/storagebackend" 28 utilopenapi "k8s.io/apiserver/pkg/util/openapi" 29 openapicommon "k8s.io/kube-openapi/pkg/common" 30 "k8s.io/kube-openapi/pkg/spec3" 31 "k8s.io/kube-openapi/pkg/validation/spec" 32 "k8s.io/kubernetes/pkg/api/legacyscheme" 33 "k8s.io/kubernetes/pkg/generated/openapi" 34 ) 35 36 const ( 37 UnprivilegedUserToken = "unprivileged-user" 38 ) 39 40 // MinVerbosity determines the minimum klog verbosity when running tests that 41 // involve the apiserver. This overrides the -v value from the command line, 42 // i.e. -v=0 has no effect when MinVerbosity is 4 (the default). Tests can opt 43 // out of this by setting MinVerbosity to zero before starting the control 44 // plane or choose some different minimum verbosity. 45 var MinVerbosity = 4 46 47 // DefaultOpenAPIConfig returns an openapicommon.Config initialized to default values. 48 func DefaultOpenAPIConfig() *openapicommon.Config { 49 openAPIConfig := genericapiserver.DefaultOpenAPIConfig(openapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(legacyscheme.Scheme)) 50 openAPIConfig.Info = &spec.Info{ 51 InfoProps: spec.InfoProps{ 52 Title: "Kubernetes", 53 Version: "unversioned", 54 }, 55 } 56 openAPIConfig.DefaultResponse = &spec.Response{ 57 ResponseProps: spec.ResponseProps{ 58 Description: "Default Response.", 59 }, 60 } 61 openAPIConfig.GetDefinitions = utilopenapi.GetOpenAPIDefinitionsWithoutDisabledFeatures(openapi.GetOpenAPIDefinitions) 62 63 return openAPIConfig 64 } 65 66 // DefaultOpenAPIV3Config returns an openapicommon.Config initialized to default values. 67 func DefaultOpenAPIV3Config() *openapicommon.OpenAPIV3Config { 68 openAPIConfig := genericapiserver.DefaultOpenAPIV3Config(openapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(legacyscheme.Scheme)) 69 openAPIConfig.Info = &spec.Info{ 70 InfoProps: spec.InfoProps{ 71 Title: "Kubernetes", 72 Version: "unversioned", 73 }, 74 } 75 openAPIConfig.DefaultResponse = &spec3.Response{ 76 ResponseProps: spec3.ResponseProps{ 77 Description: "Default Response.", 78 }, 79 } 80 openAPIConfig.GetDefinitions = utilopenapi.GetOpenAPIDefinitionsWithoutDisabledFeatures(openapi.GetOpenAPIDefinitions) 81 82 return openAPIConfig 83 } 84 85 // DefaultEtcdOptions are the default EtcdOptions for use with integration tests. 86 func DefaultEtcdOptions() *options.EtcdOptions { 87 // This causes the integration tests to exercise the etcd 88 // prefix code, so please don't change without ensuring 89 // sufficient coverage in other ways. 90 etcdOptions := options.NewEtcdOptions(storagebackend.NewDefaultConfig(uuid.New().String(), nil)) 91 etcdOptions.StorageConfig.Transport.ServerList = []string{GetEtcdURL()} 92 return etcdOptions 93 } 94 95 // SharedEtcd creates a storage config for a shared etcd instance, with a unique prefix. 96 func SharedEtcd() *storagebackend.Config { 97 cfg := storagebackend.NewDefaultConfig(path.Join(uuid.New().String(), "registry"), nil) 98 cfg.Transport.ServerList = []string{GetEtcdURL()} 99 return cfg 100 }