Skip to content

Commit

Permalink
PANDARIA: update aliyun cloud credential
Browse files Browse the repository at this point in the history
  • Loading branch information
JacieChao committed Sep 26, 2024
1 parent 306650b commit 27db041
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
43 changes: 29 additions & 14 deletions extensions/cloudcredentials/ecs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,41 @@ package ecs

import (
"github.com/rancher/shepherd/clients/rancher"
management "github.com/rancher/shepherd/clients/rancher/generated/management/v3"
v1 "github.com/rancher/shepherd/clients/rancher/v1"
"github.com/rancher/shepherd/extensions/cloudcredentials"
"github.com/rancher/shepherd/pkg/config"
"github.com/rancher/shepherd/extensions/defaults"
"github.com/rancher/shepherd/extensions/defaults/namespaces"
"github.com/rancher/shepherd/extensions/defaults/providers"
"github.com/rancher/shepherd/extensions/defaults/stevetypes"
"github.com/rancher/shepherd/extensions/steve"
"github.com/rancher/shepherd/pkg/namegenerator"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const ecsCloudCredNameBase = "ecsCloudCredential"

func CreateECSCloudCredentials(rancherClient *rancher.Client) (*cloudcredentials.CloudCredential, error) {
var aliyunECSCredentialConfig cloudcredentials.AliyunECSCredentialConfig
config.LoadConfig(cloudcredentials.AliyunECSCredentialConfigurationFileKey, &aliyunECSCredentialConfig)

cloudCredential := cloudcredentials.CloudCredential{
Name: ecsCloudCredNameBase,
AliyunECSCredentialConfig: &aliyunECSCredentialConfig,
func CreateECSCloudCredentials(client *rancher.Client, credentials cloudcredentials.CloudCredential) (*v1.SteveAPIObject, error) {
secretName := namegenerator.AppendRandomString(providers.Aliyun)
spec := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
GenerateName: cloudcredentials.GeneratedName,
Namespace: namespaces.CattleData,
Annotations: map[string]string{
"provisioning.cattle.io/driver": providers.Aliyun,
"field.cattle.io/name": secretName,
"field.cattle.io/creatorId": client.UserID,
},
},
Data: map[string][]byte{
"aliyunecscredentialConfig-accessKeyId": []byte(credentials.AliyunECSCredentialConfig.AccessKeyID),
"aliyunecscredentialConfig-accessKeySecret": []byte(credentials.AliyunECSCredentialConfig.AccessKeySecret),
},
Type: corev1.SecretTypeOpaque,
}

resp := &cloudcredentials.CloudCredential{}
err := rancherClient.Management.APIBaseClient.Ops.DoCreate(management.CloudCredentialType, cloudCredential, resp)
ecsCloudCredentials, err := steve.CreateAndWaitForResource(client, stevetypes.Secret, spec, true, defaults.FiveSecondTimeout, defaults.FiveMinuteTimeout)
if err != nil {
return nil, err
}
return resp, nil

return ecsCloudCredentials, nil
}
1 change: 1 addition & 0 deletions extensions/defaults/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ const (
Linode = "linode"
Google = "google"
Vsphere = "vsphere"
Aliyun = "aliyun"
)

0 comments on commit 27db041

Please sign in to comment.