blob: 101207b9fa4146bd83fa5c99abb1bcc01b0d2e6f [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package factory
18
19import (
20 "fmt"
21
22 "k8s.io/apiserver/pkg/storage"
23 "k8s.io/apiserver/pkg/storage/storagebackend"
24)
25
26// DestroyFunc is to destroy any resources used by the storage returned in Create() together.
27type DestroyFunc func()
28
29// Create creates a storage backend based on given config.
30func Create(c storagebackend.Config) (storage.Interface, DestroyFunc, error) {
31 switch c.Type {
32 case storagebackend.StorageTypeETCD2:
33 return newETCD2Storage(c)
34 case storagebackend.StorageTypeUnset, storagebackend.StorageTypeETCD3:
35 // TODO: We have the following features to implement:
36 // - Support secure connection by using key, cert, and CA files.
37 // - Honor "https" scheme to support secure connection in gRPC.
38 // - Support non-quorum read.
39 return newETCD3Storage(c)
40 default:
41 return nil, nil, fmt.Errorf("unknown storage type: %s", c.Type)
42 }
43}