Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature pmks gcp 20221206 yhnoh #124

Merged
merged 32 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cf66105
PMKS for GCP
dogfootman Dec 12, 2022
f2bd1a6
Network use vpc iid systemID
dogfootman Dec 12, 2022
3d8085b
GCP Pmks create set.
dogfootman Dec 12, 2022
84d900c
set systemID after cluster creating call
dogfootman Dec 12, 2022
b0a2308
test log
dogfootman Dec 12, 2022
40fff0f
add firewall to Tag
dogfootman Dec 13, 2022
41ee571
cluster Tag maxlength issue solved
dogfootman Dec 13, 2022
6dacf81
node KeyPairIID
dogfootman Dec 13, 2022
a467672
gcp cluster add instance iid
dogfootman Dec 13, 2022
3436937
mappingNodeGroupInfo modified
dogfootman Dec 13, 2022
65a6080
get securityGroupTag
dogfootman Dec 13, 2022
1bc9386
securityGroup set by metadata
dogfootman Dec 13, 2022
8ad0097
function convertCluster added
dogfootman Dec 13, 2022
5843695
iid set
dogfootman Dec 13, 2022
4c4e57f
Set NodeGroup Info
dogfootman Dec 13, 2022
231e3a3
Set NodeGroup
dogfootman Dec 14, 2022
921559b
add Log
dogfootman Dec 14, 2022
45a1d8a
add Log
dogfootman Dec 14, 2022
88cd0e9
add Log
dogfootman Dec 14, 2022
95bee1c
add Log
dogfootman Dec 14, 2022
a862dab
add Logs
dogfootman Dec 14, 2022
62477a8
add Log
dogfootman Dec 14, 2022
1e4878b
set node keypair
dogfootman Dec 14, 2022
a421b49
Set keyPair
dogfootman Dec 14, 2022
cebafa7
add keypair
dogfootman Dec 14, 2022
6d5024d
add Log
dogfootman Dec 14, 2022
e7a1df9
add Log
dogfootman Dec 14, 2022
81776b5
add Log
dogfootman Dec 14, 2022
0163bf1
autoscaling check
dogfootman Dec 14, 2022
0608c19
set keypair
dogfootman Dec 14, 2022
653225a
set keypair
dogfootman Dec 14, 2022
08ef4c4
Merge branch 'master' into feature_pmks_gcp_20221206_yhnoh
dogfootman Dec 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions cloud-control-manager/cloud-driver/drivers/gcp/GCPDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
goo "golang.org/x/oauth2/google"

compute "google.golang.org/api/compute/v1"
"google.golang.org/api/container/v1"
)

type GCPDriver struct {
Expand All @@ -46,6 +47,9 @@ func (GCPDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.VPCHandler = true
drvCapabilityInfo.DiskHandler = false
drvCapabilityInfo.MyImageHandler = false
drvCapabilityInfo.ClusterHandler = true

return drvCapabilityInfo
}
Expand All @@ -66,6 +70,14 @@ func (driver *GCPDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
if err != nil {
return nil, err
}
//Ctx2, containerClient, err := getContainerClient(connectionInfo.CredentialInfo)
_, containerClient, err := getContainerClient(connectionInfo.CredentialInfo)
fmt.Println("################## getContainerClient ##################")
fmt.Println("getContainerClient")
fmt.Println("################## getContainerClient ##################")
if err != nil {
return nil, err
}

iConn := gcpcon.GCPCloudConnection{
Region: connectionInfo.RegionInfo,
Expand All @@ -77,9 +89,10 @@ func (driver *GCPDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
SecurityGroupClient: VMClient,
// VNetClient: VMClient,
// VNicClient: VMClient,
SubnetClient: VMClient,
VMSpecHandler: VMClient,
VPCHandler: VMClient,
SubnetClient: VMClient,
VMSpecHandler: VMClient,
VPCHandler: VMClient,
ContainerClient: containerClient,
}

//fmt.Println("################## resource ConnectionInfo ##################")
Expand All @@ -88,6 +101,11 @@ func (driver *GCPDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
return &iConn, nil
}

// authorization scopes : https://developers.google.com/identity/protocols/oauth2/scopes
// cloud-platform, cloud-platform.read-only, compute, compute.readonly

// auth scope : compute
// 아래에서 cloud-platform을 사용하는데 vmClient 대체가 되는지 확인 필요.
func getVMClient(credential idrv.CredentialInfo) (context.Context, *compute.Service, error) {

// GCP 는 ClientSecret에
Expand Down Expand Up @@ -121,3 +139,38 @@ func getVMClient(credential idrv.CredentialInfo) (context.Context, *compute.Serv

return ctx, vmClient, nil
}

// auth scope : cloud-platform
func getContainerClient(credential idrv.CredentialInfo) (context.Context, *container.Service, error) {

// GCP 는 ClientSecret에
gcpType := "service_account"
data := make(map[string]string)

data["type"] = gcpType
data["private_key"] = credential.PrivateKey
data["client_email"] = credential.ClientEmail

fmt.Println("################## data ##################")
//fmt.Println("data to json : ", data)
fmt.Println("################## data ##################")

res, _ := json.Marshal(data)
authURL := "https://www.googleapis.com/auth/cloud-platform"

conf, err := goo.JWTConfigFromJSON(res, authURL)

if err != nil {

return nil, nil, err
}

client := conf.Client(o2.NoContext)

containerClient, err := container.New(client)

ctx := context.Background()

return ctx, containerClient, nil
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
"github.com/sirupsen/logrus"
compute "google.golang.org/api/compute/v1"
"google.golang.org/api/container/v1"
)

var cblogger *logrus.Logger
Expand All @@ -42,6 +43,7 @@ type GCPCloudConnection struct {
SubnetClient *compute.Service
VMSpecHandler *compute.Service
VPCHandler *compute.Service
ContainerClient *container.Service
}

// func (cloudConn *GCPCloudConnection) CreateVNetworkHandler() (irs.VNetworkHandler, error) {
Expand Down Expand Up @@ -125,12 +127,11 @@ func (cloudConn *GCPCloudConnection) CreateMyImageHandler() (irs.MyImageHandler,
}

func (cloudConn *GCPCloudConnection) CreateClusterHandler() (irs.ClusterHandler, error) {
return nil, errors.New("GCP Driver: not implemented")
cblogger.Info("GCP Cloud Driver: called CreateClusterHandler()!")
clusterHandler := gcprs.GCPClusterHandler{Region: cloudConn.Region, Ctx: cloudConn.Ctx, Client: cloudConn.VMClient, ContainerClient: cloudConn.ContainerClient, Credential: cloudConn.Credential}
return &clusterHandler, nil
}



func (cloudConn *GCPCloudConnection) CreateAnyCallHandler() (irs.AnyCallHandler, error) {
return nil, errors.New("GCP Driver: not implemented")
}

Loading