Skip to content

Commit b383d11

Browse files
committed
WIP GCP
1 parent 7e8826d commit b383d11

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

cli/cmd/gcp_cluster.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,22 @@ func upGCP(gcpPath string) {
8383
}
8484

8585
GCP := &gcp.Client{}
86-
err = GCP.CreateBucket(gcpConfig.Bucket, gcpConfig.Project, true)
87-
if err != nil {
86+
if exists, err := GCP.BucketExists(gcpConfig.Bucket); err != nil {
8887
exit.Error(err)
88+
} else if !exists {
89+
err = GCP.CreateBucket(gcpConfig.Bucket, gcpConfig.Project)
90+
if err != nil {
91+
exit.Error(err)
92+
}
8993
}
9094

9195
fmt.Print("○ spinning up a cluster .")
9296

9397
parent := fmt.Sprintf("projects/%s/locations/%s", gcpConfig.Project, gcpConfig.Zone)
94-
clusterName := gcpConfig.ClusterName
9598
request := containerpb.CreateClusterRequest{
9699
Parent: parent,
97100
Cluster: &containerpb.Cluster{
98-
Name: clusterName,
101+
Name: gcpConfig.ClusterName,
99102
NodePools: []*containerpb.NodePool{
100103
{
101104
Name: "ng-cortex-operator",
@@ -159,14 +162,22 @@ func upGCP(gcpPath string) {
159162
for {
160163
time.Sleep(10 * time.Second)
161164
req := &containerpb.GetClusterRequest{
162-
Name: fmt.Sprintf("%s/clusters/%s", parent, clusterName),
165+
Name: fmt.Sprintf("%s/clusters/%s", parent, gcpConfig.ClusterName),
163166
}
164167

165168
resp, err := c.GetCluster(ctx, req)
166169
if err != nil {
167170
exit.Error(err)
168171
}
169172

173+
if resp.Status == containerpb.Cluster_ERROR {
174+
fmt.Println(" ✗")
175+
helpStr := fmt.Sprintf("\nyour cluster couldn't be spun up; here is the error that was encountered: %s", resp.StatusMessage)
176+
helpStr += fmt.Sprintf("\nadditional error information may be found on the cluster's page in the GCP console: https://console.cloud.google.com/kubernetes/clusters/details/%s/%s?project=%s", gcpConfig.Zone, gcpConfig.ClusterName, gcpConfig.Project)
177+
fmt.Println(helpStr)
178+
exit.Error(ErrorClusterUp(resp.StatusMessage))
179+
}
180+
170181
if resp.Status != containerpb.Cluster_PROVISIONING {
171182
fmt.Println(" ✓")
172183
break

pkg/lib/gcp/gcs.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,31 @@ import (
2525
"cloud.google.com/go/storage"
2626
"github.com/cortexlabs/cortex/pkg/lib/errors"
2727
s "github.com/cortexlabs/cortex/pkg/lib/strings"
28-
"google.golang.org/api/googleapi"
2928
"google.golang.org/api/iterator"
3029
)
3130

3231
func GCSPath(bucket string, key string) string {
3332
return "gs://" + filepath.Join(bucket, key)
3433
}
3534

36-
func (c *Client) CreateBucket(bucket, projectID string, ignoreErrorIfBucketExists bool) error {
35+
func (c *Client) BucketExists(bucket string) (bool, error) {
36+
gcsClient, err := c.GCS()
37+
if err != nil {
38+
return false, err
39+
}
40+
_, err = gcsClient.Bucket(bucket).Attrs(context.Background())
41+
// TODO fix this
42+
return err == nil, nil
43+
}
44+
45+
func (c *Client) CreateBucket(bucket, projectID string) error {
3746
gcsClient, err := c.GCS()
3847
if err != nil {
3948
return err
4049
}
4150
err = gcsClient.Bucket(bucket).Create(context.Background(), projectID, nil)
4251
if err != nil {
43-
if e, ok := err.(*googleapi.Error); ok && e.Code == 409 && !ignoreErrorIfBucketExists {
44-
return err
45-
} else if !ok || (ok && e.Code != 409) {
46-
return err
47-
}
52+
return err
4853
}
4954
return nil
5055
}

pkg/types/spec/validations.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,10 +1421,6 @@ func validateCompute(api *userconfig.API, providerType types.ProviderType) error
14211421
return ErrorUnsupportedComputeResourceForProvider(userconfig.InfKey, providerType)
14221422
}
14231423

1424-
if compute.GPU > 0 && providerType == types.GCPProviderType {
1425-
return ErrorUnsupportedComputeResourceForProvider(userconfig.GPUKey, providerType)
1426-
}
1427-
14281424
if compute.Inf > 0 && api.Predictor.Type == userconfig.ONNXPredictorType {
14291425
return ErrorFieldNotSupportedByPredictorType(userconfig.InfKey, api.Predictor.Type)
14301426
}

0 commit comments

Comments
 (0)