k8s.io/apiserver@v0.29.3/pkg/storage/storagebackend/config.go (about) 1 /* 2 Copyright 2016 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 storagebackend 18 19 import ( 20 "time" 21 22 oteltrace "go.opentelemetry.io/otel/trace" 23 24 "k8s.io/apimachinery/pkg/runtime" 25 "k8s.io/apimachinery/pkg/runtime/schema" 26 "k8s.io/apiserver/pkg/server/egressselector" 27 "k8s.io/apiserver/pkg/storage/etcd3" 28 "k8s.io/apiserver/pkg/storage/value" 29 flowcontrolrequest "k8s.io/apiserver/pkg/util/flowcontrol/request" 30 ) 31 32 const ( 33 StorageTypeUnset = "" 34 StorageTypeETCD2 = "etcd2" 35 StorageTypeETCD3 = "etcd3" 36 37 DefaultCompactInterval = 5 * time.Minute 38 DefaultDBMetricPollInterval = 30 * time.Second 39 DefaultHealthcheckTimeout = 2 * time.Second 40 DefaultReadinessTimeout = 2 * time.Second 41 ) 42 43 // TransportConfig holds all connection related info, i.e. equal TransportConfig means equal servers we talk to. 44 type TransportConfig struct { 45 // ServerList is the list of storage servers to connect with. 46 ServerList []string 47 // TLS credentials 48 KeyFile string 49 CertFile string 50 TrustedCAFile string 51 // function to determine the egress dialer. (i.e. konnectivity server dialer) 52 EgressLookup egressselector.Lookup 53 // The TracerProvider can add tracing the connection 54 TracerProvider oteltrace.TracerProvider 55 } 56 57 // Config is configuration for creating a storage backend. 58 type Config struct { 59 // Type defines the type of storage backend. Default ("") is "etcd3". 60 Type string 61 // Prefix is the prefix to all keys passed to storage.Interface methods. 62 Prefix string 63 // Transport holds all connection related info, i.e. equal TransportConfig means equal servers we talk to. 64 Transport TransportConfig 65 66 Codec runtime.Codec 67 // EncodeVersioner is the same groupVersioner used to build the 68 // storage encoder. Given a list of kinds the input object might belong 69 // to, the EncodeVersioner outputs the gvk the object will be 70 // converted to before persisted in etcd. 71 EncodeVersioner runtime.GroupVersioner 72 // Transformer allows the value to be transformed prior to persisting into etcd. 73 Transformer value.Transformer 74 75 // CompactionInterval is an interval of requesting compaction from apiserver. 76 // If the value is 0, no compaction will be issued. 77 CompactionInterval time.Duration 78 // CountMetricPollPeriod specifies how often should count metric be updated 79 CountMetricPollPeriod time.Duration 80 // DBMetricPollInterval specifies how often should storage backend metric be updated. 81 DBMetricPollInterval time.Duration 82 // HealthcheckTimeout specifies the timeout used when checking health 83 HealthcheckTimeout time.Duration 84 // ReadycheckTimeout specifies the timeout used when checking readiness 85 ReadycheckTimeout time.Duration 86 87 LeaseManagerConfig etcd3.LeaseManagerConfig 88 89 // StorageObjectCountTracker is used to keep track of the total 90 // number of objects in the storage per resource. 91 StorageObjectCountTracker flowcontrolrequest.StorageObjectCountTracker 92 } 93 94 // ConfigForResource is a Config specialized to a particular `schema.GroupResource` 95 type ConfigForResource struct { 96 // Config is the resource-independent configuration 97 Config 98 99 // GroupResource is the relevant one 100 GroupResource schema.GroupResource 101 } 102 103 // ForResource specializes to the given resource 104 func (config *Config) ForResource(resource schema.GroupResource) *ConfigForResource { 105 return &ConfigForResource{ 106 Config: *config, 107 GroupResource: resource, 108 } 109 } 110 111 func NewDefaultConfig(prefix string, codec runtime.Codec) *Config { 112 return &Config{ 113 Prefix: prefix, 114 Codec: codec, 115 CompactionInterval: DefaultCompactInterval, 116 DBMetricPollInterval: DefaultDBMetricPollInterval, 117 HealthcheckTimeout: DefaultHealthcheckTimeout, 118 ReadycheckTimeout: DefaultReadinessTimeout, 119 LeaseManagerConfig: etcd3.NewDefaultLeaseManagerConfig(), 120 Transport: TransportConfig{TracerProvider: oteltrace.NewNoopTracerProvider()}, 121 } 122 }