added loadbalancer
This commit is contained in:
parent
90c5f8e98e
commit
bd94056453
9 changed files with 371 additions and 113 deletions
|
|
@ -18,6 +18,8 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
lb "git.giftfish.de/ston1th/haproxy-lb/pkg/api/client"
|
||||
lbclient "git.giftfish.de/ston1th/haproxy-lb/pkg/api/v1/client"
|
||||
pve "git.giftfish.de/ston1th/pve-go"
|
||||
cloudprovider "k8s.io/cloud-provider"
|
||||
)
|
||||
|
|
@ -28,40 +30,66 @@ const (
|
|||
)
|
||||
|
||||
type cloud struct {
|
||||
client *pve.Client
|
||||
instances cloudprovider.Instances
|
||||
instancesV2 cloudprovider.InstancesV2
|
||||
pveClient *pve.Client
|
||||
lbClient *lbclient.Client
|
||||
instances cloudprovider.Instances
|
||||
instancesV2 cloudprovider.InstancesV2
|
||||
loadbalancer cloudprovider.LoadBalancer
|
||||
}
|
||||
|
||||
func newCloud(config io.Reader) (c cloudprovider.Interface, err error) {
|
||||
var opts []pve.ClientOption
|
||||
buf, _ := ioutil.ReadAll(config)
|
||||
type config struct {
|
||||
PVE pve.Config `json:"pve"`
|
||||
LB lb.Config `json:"lb"`
|
||||
}
|
||||
|
||||
func newCloud(cr io.Reader) (c cloudprovider.Interface, err error) {
|
||||
var (
|
||||
pveOpts []pve.ClientOption
|
||||
lbOpts []lb.ClientOption
|
||||
)
|
||||
buf, _ := ioutil.ReadAll(cr)
|
||||
if len(buf) != 0 {
|
||||
var cfg pve.Config
|
||||
var cfg config
|
||||
err = json.Unmarshal(buf, &cfg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
opts, err = pve.ClientOptionsFromConfig(cfg)
|
||||
pveOpts, err = pve.ClientOptionsFromConfig(cfg.PVE)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
lbOpts, err = lb.ClientOptionsFromConfig(cfg.LB)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
opts, err = pve.ClientOptionsFromEnv()
|
||||
pveOpts, err = pve.ClientOptionsFromEnv()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
lbOpts, err = lb.ClientOptionsFromEnv()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if len(opts) == 0 {
|
||||
if len(pveOpts) == 0 {
|
||||
err = errors.New("missing pve config")
|
||||
return
|
||||
}
|
||||
if len(lbOpts) == 0 {
|
||||
err = errors.New("missing lb config")
|
||||
return
|
||||
}
|
||||
|
||||
pveClient := pve.NewClient(pveOpts...)
|
||||
lbClient, err := lbclient.NewClient(lb.NewClient(lbOpts...))
|
||||
|
||||
client := pve.NewClient(opts...)
|
||||
c = &cloud{
|
||||
client: client,
|
||||
instances: newInstances(client),
|
||||
instancesV2: newInstancesV2(client),
|
||||
pveClient: pveClient,
|
||||
lbClient: lbClient,
|
||||
instances: newInstances(pveClient),
|
||||
instancesV2: newInstancesV2(pveClient),
|
||||
loadbalancer: newLoadbalancer(lbClient),
|
||||
//zones: newZones(client, nodeName),
|
||||
//routes: nil,
|
||||
//network: network,
|
||||
|
|
@ -85,7 +113,7 @@ func (c *cloud) Zones() (cloudprovider.Zones, bool) {
|
|||
}
|
||||
|
||||
func (c *cloud) LoadBalancer() (cloudprovider.LoadBalancer, bool) {
|
||||
return nil, false
|
||||
return c.loadbalancer, true
|
||||
}
|
||||
|
||||
func (c *cloud) Clusters() (cloudprovider.Clusters, bool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue