mirror of
https://github.com/rancher/rke.git
synced 2025-09-16 06:59:25 +00:00
Add AWS cloudprovider config
This commit is contained in:
committed by
Alena Prokharchyk
parent
1938b88023
commit
23aebac488
@@ -1,28 +1,53 @@
|
||||
package aws
|
||||
|
||||
import "github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
type CloudProvider struct {
|
||||
Name string
|
||||
}
|
||||
"github.com/go-ini/ini"
|
||||
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
)
|
||||
|
||||
const (
|
||||
AWSCloudProviderName = "aws"
|
||||
AWSConfig = "AWSConfig"
|
||||
)
|
||||
|
||||
type CloudProvider struct {
|
||||
Config *v3.AWSCloudProvider
|
||||
Name string
|
||||
}
|
||||
|
||||
func GetInstance() *CloudProvider {
|
||||
return &CloudProvider{}
|
||||
}
|
||||
|
||||
func (p *CloudProvider) Init(cloudProviderConfig v3.CloudProvider) error {
|
||||
p.Name = AWSCloudProviderName
|
||||
if cloudProviderConfig.AWSCloudProvider == nil {
|
||||
return nil
|
||||
}
|
||||
p.Config = cloudProviderConfig.AWSCloudProvider
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *CloudProvider) GetName() string {
|
||||
return p.Name
|
||||
}
|
||||
|
||||
func (p *CloudProvider) GenerateCloudConfigFile() (string, error) {
|
||||
if p.Config == nil {
|
||||
return "", nil
|
||||
}
|
||||
// Generate INI style configuration
|
||||
buf := new(bytes.Buffer)
|
||||
cloudConfig := ini.Empty()
|
||||
if err := ini.ReflectFrom(cloudConfig, p.Config); err != nil {
|
||||
return "", fmt.Errorf("Failed to parse Openstack cloud config")
|
||||
}
|
||||
if _, err := cloudConfig.WriteTo(buf); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ type CloudProvider interface {
|
||||
|
||||
func InitCloudProvider(cloudProviderConfig v3.CloudProvider) (CloudProvider, error) {
|
||||
var p CloudProvider
|
||||
if cloudProviderConfig.Name == aws.AWSCloudProviderName {
|
||||
if cloudProviderConfig.AWSCloudProvider != nil || cloudProviderConfig.Name == aws.AWSCloudProviderName {
|
||||
p = aws.GetInstance()
|
||||
}
|
||||
if cloudProviderConfig.AzureCloudProvider != nil || cloudProviderConfig.Name == azure.AzureCloudProviderName {
|
||||
|
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
ref "github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/rancher/rke/cloudprovider/aws"
|
||||
"github.com/rancher/rke/docker"
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/rke/k8s"
|
||||
@@ -161,7 +160,7 @@ func (c *Cluster) BuildKubeAPIProcess(host *hosts.Host, prefixPath string) v3.Pr
|
||||
"tls-cert-file": pki.GetCertPath(pki.KubeAPICertName),
|
||||
"tls-private-key-file": pki.GetKeyPath(pki.KubeAPICertName),
|
||||
}
|
||||
if len(c.CloudProvider.Name) > 0 && c.CloudProvider.Name != aws.AWSCloudProviderName {
|
||||
if len(c.CloudProvider.Name) > 0 {
|
||||
CommandArgs["cloud-config"] = cloudConfigFileName
|
||||
}
|
||||
if c.Authentication.Webhook != nil {
|
||||
@@ -306,7 +305,7 @@ func (c *Cluster) BuildKubeControllerProcess(prefixPath string) v3.Process {
|
||||
if c.DinD {
|
||||
CommandArgs["address"] = "0.0.0.0"
|
||||
}
|
||||
if len(c.CloudProvider.Name) > 0 && c.CloudProvider.Name != aws.AWSCloudProviderName {
|
||||
if len(c.CloudProvider.Name) > 0 {
|
||||
CommandArgs["cloud-config"] = cloudConfigFileName
|
||||
}
|
||||
if len(c.CloudProvider.Name) > 0 {
|
||||
@@ -414,7 +413,7 @@ func (c *Cluster) BuildKubeletProcess(host *hosts.Host, prefixPath string) v3.Pr
|
||||
if host.Address != host.InternalAddress {
|
||||
CommandArgs["node-ip"] = host.InternalAddress
|
||||
}
|
||||
if len(c.CloudProvider.Name) > 0 && c.CloudProvider.Name != aws.AWSCloudProviderName {
|
||||
if len(c.CloudProvider.Name) > 0 {
|
||||
CommandArgs["cloud-config"] = cloudConfigFileName
|
||||
}
|
||||
if len(c.CloudProvider.Name) > 0 {
|
||||
|
Reference in New Issue
Block a user