...

Source file src/k8s.io/kubernetes/pkg/registry/registrytest/etcd.go

Documentation: k8s.io/kubernetes/pkg/registry/registrytest

     1  /*
     2  Copyright 2015 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 registrytest
    18  
    19  import (
    20  	"testing"
    21  
    22  	"k8s.io/apimachinery/pkg/runtime/schema"
    23  	"k8s.io/apiserver/pkg/server/options"
    24  	serverstorage "k8s.io/apiserver/pkg/server/storage"
    25  	etcd3testing "k8s.io/apiserver/pkg/storage/etcd3/testing"
    26  	"k8s.io/apiserver/pkg/storage/storagebackend"
    27  	"k8s.io/kubernetes/pkg/kubeapiserver"
    28  )
    29  
    30  // NewEtcdStorage is for testing.  It configures the etcd storage for a bogus resource; the test must not care.
    31  func NewEtcdStorage(t *testing.T, group string) (*storagebackend.ConfigForResource, *etcd3testing.EtcdTestServer) {
    32  	return NewEtcdStorageForResource(t, schema.GroupResource{Group: group, Resource: "any"})
    33  }
    34  
    35  func NewEtcdStorageForResource(t *testing.T, resource schema.GroupResource) (*storagebackend.ConfigForResource, *etcd3testing.EtcdTestServer) {
    36  	t.Helper()
    37  
    38  	server, config := etcd3testing.NewUnsecuredEtcd3TestClientServer(t)
    39  
    40  	options := options.NewEtcdOptions(config)
    41  	completedConfig := kubeapiserver.NewStorageFactoryConfig().Complete(options)
    42  	completedConfig.APIResourceConfig = serverstorage.NewResourceConfig()
    43  	factory, err := completedConfig.New()
    44  	if err != nil {
    45  		t.Fatalf("Error while making storage factory: %v", err)
    46  	}
    47  	resourceConfig, err := factory.NewConfig(resource)
    48  	if err != nil {
    49  		t.Fatalf("Error while finding storage destination: %v", err)
    50  	}
    51  	return resourceConfig, server
    52  }
    53  

View as plain text