Merge pull request #112789 from enj/enj/r/kms_load_once_v2
Load encryption config once (second approach)
This commit is contained in:
@@ -89,6 +89,9 @@ func setUp(t *testing.T) (*etcd3testing.EtcdTestServer, Config, *assert.Assertio
|
||||
etcdOptions := options.NewEtcdOptions(storageConfig)
|
||||
// unit tests don't need watch cache and it leaks lots of goroutines with etcd testing functions during unit tests
|
||||
etcdOptions.EnableWatchCache = false
|
||||
if err := etcdOptions.Complete(config.GenericConfig.StorageObjectCountTracker, config.GenericConfig.DrainedNotify()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := etcdOptions.ApplyWithStorageFactoryTo(storageFactory, config.GenericConfig)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@@ -22,7 +22,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
serveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
"k8s.io/apiserver/pkg/server/options/encryptionconfig"
|
||||
"k8s.io/apiserver/pkg/server/resourceconfig"
|
||||
serverstorage "k8s.io/apiserver/pkg/server/storage"
|
||||
"k8s.io/apiserver/pkg/storage/storagebackend"
|
||||
@@ -58,7 +57,6 @@ func DefaultWatchCacheSizes() map[schema.GroupResource]int {
|
||||
|
||||
// NewStorageFactoryConfig returns a new StorageFactoryConfig set up with necessary resource overrides.
|
||||
func NewStorageFactoryConfig() *StorageFactoryConfig {
|
||||
|
||||
resources := []schema.GroupVersionResource{
|
||||
// If a resource has to be stored in a version that is not the
|
||||
// latest, then it can be listed here. Usually this is the case
|
||||
@@ -83,23 +81,22 @@ func NewStorageFactoryConfig() *StorageFactoryConfig {
|
||||
|
||||
// StorageFactoryConfig is a configuration for creating storage factory.
|
||||
type StorageFactoryConfig struct {
|
||||
StorageConfig storagebackend.Config
|
||||
APIResourceConfig *serverstorage.ResourceConfig
|
||||
DefaultResourceEncoding *serverstorage.DefaultResourceEncodingConfig
|
||||
DefaultStorageMediaType string
|
||||
Serializer runtime.StorageSerializer
|
||||
ResourceEncodingOverrides []schema.GroupVersionResource
|
||||
EtcdServersOverrides []string
|
||||
EncryptionProviderConfigFilepath string
|
||||
StorageConfig storagebackend.Config
|
||||
APIResourceConfig *serverstorage.ResourceConfig
|
||||
DefaultResourceEncoding *serverstorage.DefaultResourceEncodingConfig
|
||||
DefaultStorageMediaType string
|
||||
Serializer runtime.StorageSerializer
|
||||
ResourceEncodingOverrides []schema.GroupVersionResource
|
||||
EtcdServersOverrides []string
|
||||
}
|
||||
|
||||
// Complete completes the StorageFactoryConfig with provided etcdOptions returning completedStorageFactoryConfig.
|
||||
func (c *StorageFactoryConfig) Complete(etcdOptions *serveroptions.EtcdOptions) (*completedStorageFactoryConfig, error) {
|
||||
// This method mutates the receiver (StorageFactoryConfig). It must never mutate the inputs.
|
||||
func (c *StorageFactoryConfig) Complete(etcdOptions *serveroptions.EtcdOptions) *completedStorageFactoryConfig {
|
||||
c.StorageConfig = etcdOptions.StorageConfig
|
||||
c.DefaultStorageMediaType = etcdOptions.DefaultStorageMediaType
|
||||
c.EtcdServersOverrides = etcdOptions.EtcdServersOverrides
|
||||
c.EncryptionProviderConfigFilepath = etcdOptions.EncryptionProviderConfigFilepath
|
||||
return &completedStorageFactoryConfig{c}, nil
|
||||
return &completedStorageFactoryConfig{c}
|
||||
}
|
||||
|
||||
// completedStorageFactoryConfig is a wrapper around StorageFactoryConfig completed with etcd options.
|
||||
@@ -111,7 +108,7 @@ type completedStorageFactoryConfig struct {
|
||||
}
|
||||
|
||||
// New returns a new storage factory created from the completed storage factory configuration.
|
||||
func (c *completedStorageFactoryConfig) New(stopCh <-chan struct{}) (*serverstorage.DefaultStorageFactory, error) {
|
||||
func (c *completedStorageFactoryConfig) New() (*serverstorage.DefaultStorageFactory, error) {
|
||||
resourceEncodingConfig := resourceconfig.MergeResourceEncodingConfigs(c.DefaultResourceEncoding, c.ResourceEncodingOverrides)
|
||||
storageFactory := serverstorage.NewDefaultStorageFactory(
|
||||
c.StorageConfig,
|
||||
@@ -141,14 +138,5 @@ func (c *completedStorageFactoryConfig) New(stopCh <-chan struct{}) (*serverstor
|
||||
servers := strings.Split(tokens[1], ";")
|
||||
storageFactory.SetEtcdLocation(groupResource, servers)
|
||||
}
|
||||
if len(c.EncryptionProviderConfigFilepath) != 0 {
|
||||
transformerOverrides, err := encryptionconfig.GetTransformerOverrides(c.EncryptionProviderConfigFilepath, stopCh)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for groupResource, transformer := range transformerOverrides {
|
||||
storageFactory.SetTransformer(groupResource, transformer)
|
||||
}
|
||||
}
|
||||
return storageFactory, nil
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ limitations under the License.
|
||||
package registrytest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
@@ -36,18 +35,12 @@ func NewEtcdStorage(t *testing.T, group string) (*storagebackend.ConfigForResour
|
||||
func NewEtcdStorageForResource(t *testing.T, resource schema.GroupResource) (*storagebackend.ConfigForResource, *etcd3testing.EtcdTestServer) {
|
||||
t.Helper()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
t.Cleanup(cancel)
|
||||
|
||||
server, config := etcd3testing.NewUnsecuredEtcd3TestClientServer(t)
|
||||
|
||||
options := options.NewEtcdOptions(config)
|
||||
completedConfig, err := kubeapiserver.NewStorageFactoryConfig().Complete(options)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
completedConfig := kubeapiserver.NewStorageFactoryConfig().Complete(options)
|
||||
completedConfig.APIResourceConfig = serverstorage.NewResourceConfig()
|
||||
factory, err := completedConfig.New(ctx.Done())
|
||||
factory, err := completedConfig.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user