Skip to content

Commit

Permalink
Merge pull request #875 from MZC-CSC/master
Browse files Browse the repository at this point in the history
GCP PMKS 기능 구현
  • Loading branch information
powerkimhub authored Dec 16, 2022
2 parents 1b2daa1 + 7de908d commit d422de3
Show file tree
Hide file tree
Showing 9 changed files with 2,799 additions and 20 deletions.
93 changes: 93 additions & 0 deletions cloud-control-manager/cloud-driver/drivers/aws/AwsDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/aws/aws-sdk-go/service/iam"
)

type AwsDriver struct {
Expand Down Expand Up @@ -112,6 +115,89 @@ func getNLBClient(connectionInfo idrv.ConnectionInfo) (*elbv2.ELBV2, error) {
return svc, nil
}

// EKS 처리를 위한 EKS 클라이언트 획득
func getEKSClient(connectionInfo idrv.ConnectionInfo) (*eks.EKS, error) {

// setup Region
fmt.Println("AwsDriver : getEKSClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
fmt.Println("AwsDriver : getEKSClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]")
//fmt.Println("전달 받은 커넥션 정보")
//spew.Dump(connectionInfo)

sess, err := session.NewSession(&aws.Config{
Region: aws.String(connectionInfo.RegionInfo.Region),
//Region: aws.String("ap-northeast-2"),
Credentials: credentials.NewStaticCredentials(connectionInfo.CredentialInfo.ClientId, connectionInfo.CredentialInfo.ClientSecret, "")},
)
if err != nil {
fmt.Println("Could not create aws New Session", err)
return nil, err
}

svc := eks.New(sess)
if err != nil {
fmt.Println("Could not create eks service client", err)
return nil, err
}

return svc, nil
}

// Iam 처리를 위한 iam 클라이언트 획득
func getIamClient(connectionInfo idrv.ConnectionInfo) (*iam.IAM, error) {
// setup Region
fmt.Println("AwsDriver : getIamClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
fmt.Println("AwsDriver : getIamClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]")
//fmt.Println("전달 받은 커넥션 정보")
//spew.Dump(connectionInfo)

sess, err := session.NewSession(&aws.Config{
Region: aws.String(connectionInfo.RegionInfo.Region),
//Region: aws.String("ap-northeast-2"),
Credentials: credentials.NewStaticCredentials(connectionInfo.CredentialInfo.ClientId, connectionInfo.CredentialInfo.ClientSecret, "")},
)
if err != nil {
fmt.Println("Could not create aws New Session", err)
return nil, err
}

svc := iam.New(sess)
if err != nil {
fmt.Println("Could not create iam service client", err)
return nil, err
}

return svc, nil
}

// AutoScaling 처리를 위한 autoScaling 클라이언트 획득
func getAutoScalingClient(connectionInfo idrv.ConnectionInfo) (*autoscaling.AutoScaling, error) {

// setup Region
fmt.Println("AwsDriver : getAutoScalingClient() - Region : [" + connectionInfo.RegionInfo.Region + "]")
fmt.Println("AwsDriver : getAutoScalingClient() - Zone : [" + connectionInfo.RegionInfo.Zone + "]")
//fmt.Println("전달 받은 커넥션 정보")
//spew.Dump(connectionInfo)

sess, err := session.NewSession(&aws.Config{
Region: aws.String(connectionInfo.RegionInfo.Region),
Credentials: credentials.NewStaticCredentials(connectionInfo.CredentialInfo.ClientId, connectionInfo.CredentialInfo.ClientSecret, "")},
)
if err != nil {
fmt.Println("Could not create aws New Session", err)
return nil, err
}

//svc := elb.New(sess)
// Create ELBv2 service client
svc := autoscaling.New(sess)
if err != nil {
fmt.Println("Could not create autoscaling service client", err)
return nil, err
}

return svc, nil
}
func (driver *AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) {
// 1. get info of credential and region for Test A Cloud from connectionInfo.
// 2. create a client object(or service object) of Test A Cloud with credential info.
Expand All @@ -128,6 +214,9 @@ func (driver *AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
//var iConn icon.CloudConnection
vmClient, err := getVMClient(connectionInfo)
nlbClient, err := getNLBClient(connectionInfo)
eksClient, err := getEKSClient(connectionInfo)
iamClient, err := getIamClient(connectionInfo)
autoScalingClient, err := getAutoScalingClient(connectionInfo)
//vmClient, err := getVMClient(connectionInfo.RegionInfo)
if err != nil {
return nil, err
Expand All @@ -150,6 +239,10 @@ func (driver *AwsDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
DiskClient: vmClient,
MyImageClient: vmClient,

EKSClient: eksClient,
IamClient: iamClient,
AutoScalingClient: autoScalingClient,

// Connection for AnyCall
AnyCallClient: vmClient,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elbv2"

"errors"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/aws/aws-sdk-go/service/iam"
)

//type AwsCloudConnection struct{}
// type AwsCloudConnection struct{}
type AwsCloudConnection struct {
CredentialInfo idrv.CredentialInfo
Region idrv.RegionInfo
Expand All @@ -47,6 +49,10 @@ type AwsCloudConnection struct {
DiskClient *ec2.EC2
MyImageClient *ec2.EC2

EKSClient *eks.EKS
IamClient *iam.IAM
AutoScalingClient *autoscaling.AutoScaling

AnyCallClient *ec2.EC2
}

Expand Down Expand Up @@ -83,7 +89,7 @@ func (cloudConn *AwsCloudConnection) CreateVPCHandler() (irs.VPCHandler, error)
return &handler, nil
}

//func (cloudConn *AwsCloudConnection) CreateImageHandler() (irs2.ImageHandler, error) {
// func (cloudConn *AwsCloudConnection) CreateImageHandler() (irs2.ImageHandler, error) {
func (cloudConn *AwsCloudConnection) CreateImageHandler() (irs.ImageHandler, error) {
handler := ars.AwsImageHandler{cloudConn.Region, cloudConn.ImageClient}

Expand Down Expand Up @@ -127,18 +133,30 @@ func (cloudConn *AwsCloudConnection) CreateDiskHandler() (irs.DiskHandler, error
return &handler, nil
}


func (cloudConn *AwsCloudConnection) CreateMyImageHandler() (irs.MyImageHandler, error) {
handler := ars.AwsMyImageHandler{cloudConn.Region, cloudConn.MyImageClient}
return &handler, nil
}

func (cloudConn *AwsCloudConnection) CreateClusterHandler() (irs.ClusterHandler, error) {
return nil, errors.New("AWS Driver: not implemented")
cblogger.Info("CreateClusterHandler through")
if cloudConn.MyImageClient == nil {
cblogger.Info("cloudConn.MyImageClient is nil")
}
if cloudConn.EKSClient == nil {
cblogger.Info("cloudConn.EKSClient is nil")
}
if cloudConn.IamClient == nil {
cblogger.Info("cloudConn.IamClient is nil")
}
if cloudConn.AutoScalingClient == nil {
cblogger.Info("cloudConn.AutoScalingClient is nil")
}
handler := ars.AwsClusterHandler{cloudConn.Region, cloudConn.EKSClient, cloudConn.IamClient, cloudConn.AutoScalingClient}
return &handler, nil
}

func (cloudConn *AwsCloudConnection) CreateAnyCallHandler() (irs.AnyCallHandler, error) {
handler := ars.AwsAnyCallHandler{cloudConn.Region, cloudConn.CredentialInfo, cloudConn.AnyCallClient}
return &handler, nil
return &handler, nil
}

Loading

0 comments on commit d422de3

Please sign in to comment.