2016-04-20 04:11:39 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-04-20 04:11:39 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-05-06 15:15:36 +00:00
|
|
|
package factory
|
2016-04-20 04:11:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"k8s.io/kubernetes/pkg/storage"
|
|
|
|
"k8s.io/kubernetes/pkg/storage/etcd3"
|
2016-05-06 15:15:36 +00:00
|
|
|
"k8s.io/kubernetes/pkg/storage/storagebackend"
|
2016-08-18 03:07:47 +00:00
|
|
|
|
|
|
|
"github.com/coreos/etcd/clientv3"
|
|
|
|
"github.com/coreos/etcd/pkg/transport"
|
|
|
|
"golang.org/x/net/context"
|
2016-04-20 04:11:39 +00:00
|
|
|
)
|
|
|
|
|
2016-08-08 22:12:54 +00:00
|
|
|
func newETCD3Storage(c storagebackend.Config) (storage.Interface, error) {
|
2016-08-18 18:36:25 +00:00
|
|
|
tlsInfo := transport.TLSInfo{
|
2016-08-18 03:07:47 +00:00
|
|
|
CertFile: c.CertFile,
|
|
|
|
KeyFile: c.KeyFile,
|
|
|
|
CAFile: c.CAFile,
|
|
|
|
}
|
2016-08-18 18:36:25 +00:00
|
|
|
tlsConfig, err := tlsInfo.ClientConfig()
|
2016-08-18 03:07:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-08-24 20:16:40 +00:00
|
|
|
|
2016-04-20 04:11:39 +00:00
|
|
|
cfg := clientv3.Config{
|
2016-08-22 04:08:16 +00:00
|
|
|
Endpoints: c.ServerList,
|
2016-08-18 03:07:47 +00:00
|
|
|
TLS: tlsConfig,
|
2016-04-20 04:11:39 +00:00
|
|
|
}
|
|
|
|
client, err := clientv3.New(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-04-29 23:57:09 +00:00
|
|
|
etcd3.StartCompactor(context.Background(), client)
|
2016-08-08 22:12:54 +00:00
|
|
|
return etcd3.New(client, c.Codec, c.Prefix), nil
|
2016-04-20 04:11:39 +00:00
|
|
|
}
|