Skip to content

Commit

Permalink
fix(alibaba): fix accessKey & accessSecret bug
Browse files Browse the repository at this point in the history
Signed-off-by: Jason-ZW <zhenyang@rancher.com>
  • Loading branch information
rancher-sy-bot committed Sep 4, 2020
1 parent f2889ee commit ad4992d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/cluster/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ spec:
valuesContent: |-
accessKey: %s
accessSecret: %s
clusterCIDR: %s
rbac:
create: true
serviceAccount:
Expand Down
11 changes: 9 additions & 2 deletions pkg/providers/alibaba/alibaba.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit ad4992d

Please # to comment.