From 23aebac48809c1a00de6354515a370e01006b923 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Steenis Date: Tue, 12 Feb 2019 00:21:29 +0100 Subject: [PATCH] Add AWS cloudprovider config --- cloudprovider/aws/aws.go | 37 ++++++++++++++++++++++++++++------ cloudprovider/cloudprovider.go | 2 +- cluster/plan.go | 7 +++---- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/cloudprovider/aws/aws.go b/cloudprovider/aws/aws.go index 8b49b84e..b9ef6ac8 100644 --- a/cloudprovider/aws/aws.go +++ b/cloudprovider/aws/aws.go @@ -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) { - return "", nil + 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 } diff --git a/cloudprovider/cloudprovider.go b/cloudprovider/cloudprovider.go index 151bc6e4..c0731123 100644 --- a/cloudprovider/cloudprovider.go +++ b/cloudprovider/cloudprovider.go @@ -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 { diff --git a/cluster/plan.go b/cluster/plan.go index 9195ac19..6154d244 100644 --- a/cluster/plan.go +++ b/cluster/plan.go @@ -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 {