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() { 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.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.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.") flag.StringVar(&cfg.TLSConfig.KeyFile, "key-file", "", "- NOT RECOMMENDED FOR PRODUCTION - Path to private TLS certificate file.")

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

@ -3,6 +3,7 @@ package controller
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"net/http" "net/http"
"time" "time"
@ -20,36 +21,59 @@ const (
tprName = "etcd-cluster.coreos.com" tprName = "etcd-cluster.coreos.com"
) )
var (
supportedPVProvisioners = map[string]struct{}{
"kubernetes.io/gce-pd": {},
"kubernetes.io/aws-ebs": {},
}
)
type Event struct { type Event struct {
Type string Type string
Object cluster.EtcdCluster Object cluster.EtcdCluster
} }
type Controller struct { type Controller struct {
masterHost string masterHost string
namespace string namespace string
kclient *unversioned.Client kclient *unversioned.Client
clusters map[string]*cluster.Cluster clusters map[string]*cluster.Cluster
pvProvisioner string
} }
type Config struct { type Config struct {
Namespace string Namespace string
MasterHost string MasterHost string
TLSInsecure bool TLSInsecure bool
TLSConfig restclient.TLSClientConfig 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 { func New(cfg Config) *Controller {
if err := cfg.validate(); err != nil {
panic(err)
}
kclient := k8sutil.MustCreateClient(cfg.MasterHost, cfg.TLSInsecure, &cfg.TLSConfig) kclient := k8sutil.MustCreateClient(cfg.MasterHost, cfg.TLSInsecure, &cfg.TLSConfig)
host := cfg.MasterHost host := cfg.MasterHost
if len(host) == 0 { if len(host) == 0 {
host = k8sutil.MustGetInClusterMasterHost() host = k8sutil.MustGetInClusterMasterHost()
} }
return &Controller{ return &Controller{
masterHost: host, masterHost: host,
kclient: kclient, kclient: kclient,
clusters: make(map[string]*cluster.Cluster), clusters: make(map[string]*cluster.Cluster),
namespace: cfg.Namespace, namespace: cfg.Namespace,
pvProvisioner: cfg.PVProvisioner,
} }
} }
@ -133,7 +157,7 @@ func (c *Controller) initResource() (string, error) {
return "", err return "", err
} }
} }
err = k8sutil.CreateStorageClass(c.kclient) err = k8sutil.CreateStorageClass(c.kclient, c.pvProvisioner)
if err != nil { if err != nil {
log.Errorf("fail to create storage class: %v", err) log.Errorf("fail to create storage class: %v", err)
return "", err return "", err

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

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