add controller flag for pd provisioner type

This commit is contained in:
Colin Hom 2016-10-04 16:56:37 -07:00
Родитель 10617be061
Коммит e484ca7c44
3 изменённых файлов: 40 добавлений и 16 удалений

Просмотреть файл

@ -12,6 +12,7 @@ var (
)
func init() {
flag.StringVar(&cfg.PVProvisioner, "pv-provisioner", "kubernetes.io/gce-pd", "persistent volume provisioner type")
flag.StringVar(&cfg.MasterHost, "master", "", "API Server addr, e.g. ' - NOT RECOMMENDED FOR PRODUCTION - http://127.0.0.1:8080'. Omit parameter to run in on-cluster mode and utilize the service account token.")
flag.StringVar(&cfg.TLSConfig.CertFile, "cert-file", "", " - NOT RECOMMENDED FOR PRODUCTION - Path to public TLS certificate file.")
flag.StringVar(&cfg.TLSConfig.KeyFile, "key-file", "", "- NOT RECOMMENDED FOR PRODUCTION - Path to private TLS certificate file.")

Просмотреть файл

@ -3,6 +3,7 @@ package controller
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"time"
@ -20,6 +21,13 @@ const (
tprName = "etcd-cluster.coreos.com"
)
var (
supportedPVProvisioners = map[string]struct{}{
"kubernetes.io/gce-pd": {},
"kubernetes.io/aws-ebs": {},
}
)
type Event struct {
Type string
Object cluster.EtcdCluster
@ -30,6 +38,7 @@ type Controller struct {
namespace string
kclient *unversioned.Client
clusters map[string]*cluster.Cluster
pvProvisioner string
}
type Config struct {
@ -37,9 +46,23 @@ type Config struct {
MasterHost string
TLSInsecure bool
TLSConfig restclient.TLSClientConfig
PVProvisioner string
}
func (c *Config) validate() error {
if _, ok := supportedPVProvisioners[c.PVProvisioner]; !ok {
return fmt.Errorf(
"persistent volume provisioner %s is not supported: options = %v",
c.PVProvisioner, supportedPVProvisioners,
)
}
return nil
}
func New(cfg Config) *Controller {
if err := cfg.validate(); err != nil {
panic(err)
}
kclient := k8sutil.MustCreateClient(cfg.MasterHost, cfg.TLSInsecure, &cfg.TLSConfig)
host := cfg.MasterHost
if len(host) == 0 {
@ -50,6 +73,7 @@ func New(cfg Config) *Controller {
kclient: kclient,
clusters: make(map[string]*cluster.Cluster),
namespace: cfg.Namespace,
pvProvisioner: cfg.PVProvisioner,
}
}
@ -133,7 +157,7 @@ func (c *Controller) initResource() (string, error) {
return "", err
}
}
err = k8sutil.CreateStorageClass(c.kclient)
err = k8sutil.CreateStorageClass(c.kclient, c.pvProvisioner)
if err != nil {
log.Errorf("fail to create storage class: %v", err)
return "", err

Просмотреть файл

@ -158,13 +158,12 @@ func GetNodePortString(srv *api.Service) string {
return fmt.Sprint(srv.Spec.Ports[0].NodePort)
}
func CreateStorageClass(kubecli *unversioned.Client) error {
func CreateStorageClass(kubecli *unversioned.Client, pvProvisioner string) error {
class := &storage.StorageClass{
ObjectMeta: api.ObjectMeta{
Name: storageClassName,
},
// TODO: add aws
Provisioner: "kubernetes.io/gce-pd",
Provisioner: pvProvisioner,
}
_, err := kubecli.StorageClasses().Create(class)
return err