Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 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 factory |
| 18 | |
| 19 | import ( |
| 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. |
| 27 | type DestroyFunc func() |
| 28 | |
| 29 | // Create creates a storage backend based on given config. |
| 30 | func 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 | } |