Skip to content

Commit

Permalink
PANDARIA: move back provisioning providers from shepherd and update c…
Browse files Browse the repository at this point in the history
…loud credential
  • Loading branch information
JacieChao committed Sep 27, 2024
1 parent c2b74fb commit ef75d74
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 726 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
}
45 changes: 31 additions & 14 deletions extensions/cloudcredentials/huawei/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,45 @@ package huawei

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 huaweiCloudCredNameBase = "huaweiCloudCredential"

// CreateHuaweiCloudCredentials is a helper function that takes the rancher Client as a parameter and creates
// an Huawei cloud credential, and returns the CloudCredential response
func CreateHuaweiCloudCredentials(rancherClient *rancher.Client) (*cloudcredentials.CloudCredential, error) {
var huaweiCredentialConfig cloudcredentials.HuaweiCredentialConfig
config.LoadConfig(cloudcredentials.HuaweiCredentialConfigurationFileKey, &huaweiCredentialConfig)

cloudCredential := cloudcredentials.CloudCredential{
Name: huaweiCloudCredNameBase,
HuaweiCredentialConfig: &huaweiCredentialConfig,
func CreateHuaweiCloudCredentials(client *rancher.Client, credentials cloudcredentials.CloudCredential) (*v1.SteveAPIObject, error) {
secretName := namegenerator.AppendRandomString(providers.Huawei)
spec := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
GenerateName: cloudcredentials.GeneratedName,
Namespace: namespaces.CattleData,
Annotations: map[string]string{
"provisioning.cattle.io/driver": providers.Huawei,
"field.cattle.io/name": secretName,
"field.cattle.io/creatorId": client.UserID,
},
},
Data: map[string][]byte{
"huaweicredentialConfig-accessKey": []byte(credentials.HuaweiCredentialConfig.AccessKey),
"huaweicredentialConfig-secretKey": []byte(credentials.HuaweiCredentialConfig.SecretKey),
"huaweicredentialConfig-regionID": []byte(credentials.HuaweiCredentialConfig.RegionID),
"huaweicredentialConfig-projectID": []byte(credentials.HuaweiCredentialConfig.ProjectID),
},
Type: corev1.SecretTypeOpaque,
}

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

return huaweiCloudCredentials, nil
}
43 changes: 29 additions & 14 deletions extensions/cloudcredentials/tencent/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,43 @@ package tencent

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 tencentCloudCredNameBase = "tencentCloudCredential"

// CreateTencentCloudCredentials is a helper function that takes the rancher Client as a parameter and creates
// an Tencent cloud credential, and returns the CloudCredential response
func CreateTencentCloudCredentials(rancherClient *rancher.Client) (*cloudcredentials.CloudCredential, error) {
var tencentCredentialConfig cloudcredentials.TencentCredentialConfig
config.LoadConfig(cloudcredentials.TencentCredentialConfigurationFileKey, &tencentCredentialConfig)

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

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

return tkeCloudCredentials, nil
}
3 changes: 3 additions & 0 deletions extensions/defaults/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ const (
Linode = "linode"
Google = "google"
Vsphere = "vsphere"
Aliyun = "aliyun"
Huawei = "huawei"
Tencent = "tke"
)
86 changes: 0 additions & 86 deletions extensions/machinepools/aliyunecs_machine_config.go

This file was deleted.

Loading

0 comments on commit ef75d74

Please sign in to comment.