From ad4992d282647c0c9253618959b66235ec63261d Mon Sep 17 00:00:00 2001 From: Jason-ZW Date: Thu, 3 Sep 2020 23:06:05 +0800 Subject: [PATCH] fix(alibaba): fix accessKey & accessSecret bug Signed-off-by: Jason-ZW --- pkg/cluster/cluster.go | 8 +++++++- pkg/cluster/template.go | 1 + pkg/providers/alibaba/alibaba.go | 11 +++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 97fdcac1..20e1e597 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -149,7 +149,13 @@ func InitK3sCluster(cluster *types.Cluster) error { // deploy additional Alibaba cloud-controller-manager manifests. if aliCCM != nil { - tmpl := fmt.Sprintf(alibabaCCMTmpl, aliCCM.AccessKey, aliCCM.AccessSecret) + var tmpl string + if cluster.ClusterCIDR == "" { + tmpl = fmt.Sprintf(alibabaCCMTmpl, aliCCM.AccessKey, aliCCM.AccessSecret, "10.42.0.0/16") + } else { + tmpl = fmt.Sprintf(alibabaCCMTmpl, aliCCM.AccessKey, aliCCM.AccessSecret, cluster.ClusterCIDR) + } + if _, err := execute(&hosts.Host{Node: cluster.MasterNodes[0]}, fmt.Sprintf(deployCCMCommand, tmpl, common.K3sManifestsDir), false); err != nil { return err diff --git a/pkg/cluster/template.go b/pkg/cluster/template.go index 170a3aee..88fe784e 100644 --- a/pkg/cluster/template.go +++ b/pkg/cluster/template.go @@ -46,6 +46,7 @@ spec: valuesContent: |- accessKey: %s accessSecret: %s + clusterCIDR: %s rbac: create: true serviceAccount: diff --git a/pkg/providers/alibaba/alibaba.go b/pkg/providers/alibaba/alibaba.go index dab45ee1..1dd40aac 100644 --- a/pkg/providers/alibaba/alibaba.go +++ b/pkg/providers/alibaba/alibaba.go @@ -224,8 +224,15 @@ func (p *Alibaba) Rollback() error { } func (p *Alibaba) generateClientSDK() error { - client, err := ecs.NewClientWithAccessKey(p.Region, viper.GetString(p.GetProviderName(), accessKeyID), - viper.GetString(p.GetProviderName(), accessKeySecret)) + if p.AccessKey == "" { + p.AccessKey = viper.GetString(p.GetProviderName(), accessKeyID) + } + + if p.AccessSecret == "" { + p.AccessSecret = viper.GetString(p.GetProviderName(), accessKeySecret) + } + + client, err := ecs.NewClientWithAccessKey(p.Region, p.AccessKey, p.AccessSecret) if err != nil { return err }