Skip to content

Commit 6226acb

Browse files
committed
fixes based on feedback
1 parent 64c02f2 commit 6226acb

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

gcp/gcp.go

+17-23
Original file line numberDiff line numberDiff line change
@@ -1211,27 +1211,23 @@ func newCluster(cluster *dataprocpb.Cluster, region string) *types.Cluster {
12111211

12121212
func getClusterState(s dataprocpb.ClusterStatus_State) types.State {
12131213
// convert ClusterSTatus_State to types.State
1214-
1215-
// This array must match the const ordering from here:
1216-
// https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/dataproc/v1#ClusterStatus_State
1217-
statuses := []types.State{
1218-
types.Unknown,
1219-
types.Creating,
1220-
types.Running,
1221-
types.Error,
1222-
types.Deleting,
1223-
types.Updating,
1224-
types.Stopping,
1225-
types.Stopped,
1226-
types.Starting,
1227-
}
1228-
1229-
for i, status := range statuses {
1230-
if i == int(s) {
1231-
return status
1232-
}
1214+
statuses := map[int32]types.State{
1215+
0: types.Unknown,
1216+
1: types.Creating,
1217+
2: types.Running,
1218+
3: types.Error,
1219+
4: types.Deleting,
1220+
5: types.Updating,
1221+
6: types.Stopping,
1222+
7: types.Stopped,
1223+
8: types.Starting,
1224+
}
1225+
1226+
status, ok := statuses[s]
1227+
if !ok {
1228+
return types.Unknown
12331229
}
1234-
return types.Unknown
1230+
return status
12351231
}
12361232

12371233
func (p gcpProvider) GetClusters() ([]*types.Cluster, error) {
@@ -1274,9 +1270,7 @@ func (p gcpProvider) GetClusters() ([]*types.Cluster, error) {
12741270
}
12751271
if len(clist) > 0 {
12761272
log.Debugf("[GET_CLUSTERS] Found %d clusters in %s", len(clist), r)
1277-
for _, c := range clist {
1278-
clusters = append(clusters, c)
1279-
}
1273+
clusters = append(clusters, clist...)
12801274
}
12811275
}
12821276
return clusters, nil

types/cluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Cluster struct {
3333
Region string `json:"Region"`
3434
Tags map[string]string `json:"Tags"`
3535
Config *dataprocpb.ClusterConfig `json:"ClusterConfig"`
36-
State State `json:"State"`
36+
State State `json:"State"`
3737
}
3838

3939
// GetName returns the name of the cluster

0 commit comments

Comments
 (0)