From 27db0414d572472212c6c924722475a2ff7be156 Mon Sep 17 00:00:00 2001 From: Jacie Date: Thu, 26 Sep 2024 14:52:23 +0800 Subject: [PATCH] PANDARIA: update aliyun cloud credential --- extensions/cloudcredentials/ecs/create.go | 43 +++++++++++++++------- extensions/defaults/providers/providers.go | 1 + 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/extensions/cloudcredentials/ecs/create.go b/extensions/cloudcredentials/ecs/create.go index 961076d2..74a08562 100644 --- a/extensions/cloudcredentials/ecs/create.go +++ b/extensions/cloudcredentials/ecs/create.go @@ -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 } diff --git a/extensions/defaults/providers/providers.go b/extensions/defaults/providers/providers.go index 70d9e4f8..69670129 100644 --- a/extensions/defaults/providers/providers.go +++ b/extensions/defaults/providers/providers.go @@ -8,4 +8,5 @@ const ( Linode = "linode" Google = "google" Vsphere = "vsphere" + Aliyun = "aliyun" )