Skip to content

Commit 8159869

Browse files
committed
cleanups
1 parent 06e1975 commit 8159869

14 files changed

+217
-99
lines changed

action/termination_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ func (p *mockProvider) GetClusters() ([]*types.Cluster, error) {
8787
return nil, nil
8888
}
8989

90-
func (p *mockProvider) GetStorages() ([]*types.Storage, error) {
91-
return nil, nil
92-
}
93-
94-
func (p *mockProvider) CleanupStorages(storageContainer *types.StorageContainer, retentionDays int) []error {
95-
return nil
96-
}
97-
9890
type terminationSuite struct {
9991
suite.Suite
10092
providers map[types.CloudType]func() types.CloudProvider

aws/aws.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -1913,17 +1913,18 @@ func newStack(stack *cloudformation.Stack, region string) *types.Stack {
19131913

19141914
// The low byte represents the state. The high byte is an opaque internal value
19151915
// and should be ignored.
1916-
// * 0 : pending
19171916
//
1918-
// * 16 : running
1917+
// - 0 : pending
19191918
//
1920-
// * 32 : shutting-down
1919+
// - 16 : running
19211920
//
1922-
// * 48 : terminated
1921+
// - 32 : shutting-down
19231922
//
1924-
// * 64 : stopping
1923+
// - 48 : terminated
19251924
//
1926-
// * 80 : stopped
1925+
// - 64 : stopping
1926+
//
1927+
// - 80 : stopped
19271928
func getInstanceState(instance *ec2.Instance) types.State {
19281929
if instance.State == nil {
19291930
return types.Unknown

azure/azure.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,15 @@ func getScaleSetInstanceState(view compute.VirtualMachineScaleSetVMInstanceView)
692692
}
693693

694694
// Possible values:
695-
// "PowerState/deallocated"
696-
// "PowerState/deallocating"
697-
// "PowerState/running"
698-
// "PowerState/starting"
699-
// "PowerState/stopped"
700-
// "PowerState/stopping"
701-
// "PowerState/unknown"
695+
//
696+
// "PowerState/deallocated"
697+
// "PowerState/deallocating"
698+
// "PowerState/running"
699+
// "PowerState/starting"
700+
// "PowerState/stopped"
701+
// "PowerState/stopping"
702+
// "PowerState/unknown"
703+
//
702704
// The assumption is that the status without time is the currently active status
703705
func convertViewStatusToState(actualStatus compute.InstanceViewStatus) types.State {
704706
switch *actualStatus.Code {

filter/longrunning.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (f longRunning) Execute(items []types.CloudItem) []types.CloudItem {
6161
case types.Alert:
6262
if item.GetItem().(types.Alert).State != types.Unused {
6363
log.Debugf("[LONGRUNNING] Filter alert, because it's in used state: %s", item.GetName())
64+
}
6465
case types.Cluster:
6566
if item.GetItem().(types.Cluster).State != types.Running {
6667
log.Debugf("[LONGRUNNING] Filter instance, because it's not in RUNNING state: %s", item.GetName())

gcp/gcp.go

+28-25
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030

3131
var provider = gcpProvider{}
3232

33+
const DATAPROC_ENDPOINT_SUFFIX = "-dataproc.googleapis.com:443"
34+
3335
type gcpProvider struct {
3436
projectID string
3537
computeClient *compute.Service
@@ -986,14 +988,15 @@ func getRegions(p gcpProvider) ([]string, error) {
986988
}
987989

988990
// Possible values:
989-
// "PROVISIONING"
990-
// "RUNNING"
991-
// "STAGING"
992-
// "STOPPED"
993-
// "STOPPING"
994-
// "SUSPENDED"
995-
// "SUSPENDING"
996-
// "TERMINATED"
991+
//
992+
// "PROVISIONING"
993+
// "RUNNING"
994+
// "STAGING"
995+
// "STOPPED"
996+
// "STOPPING"
997+
// "SUSPENDED"
998+
// "SUSPENDING"
999+
// "TERMINATED"
9971000
func getInstanceState(instance *compute.Instance) types.State {
9981001
switch instance.Status {
9991002
case "PROVISIONING", "RUNNING", "STAGING":
@@ -1083,7 +1086,7 @@ func (p gcpProvider) getDatabases(aggregator *sqladmin.InstancesListCall) ([]*ty
10831086
for _, databaseInstance := range gDatabaseList.Items {
10841087
instanceName := databaseInstance.Name
10851088

1086-
listOperationCall := p.sqlClient.Operations.List(p.projectID, instanceName)
1089+
listOperationCall := p.sqlClient.Operations.List(instanceName)
10871090
creationTimeStamp, err := getDatabaseInstanceCreationTimeStamp(listOperationCall, instanceName)
10881091
if err != nil {
10891092
log.Errorf("[GCP] Failed to get the creation timestamp of the DB: %s, err: %s", instanceName, err.Error())
@@ -1141,12 +1144,12 @@ func getDatabaseInstanceCreationTimeStamp(opService *sqladmin.OperationsListCall
11411144
return time.Time{}, errors.New(fmt.Sprintf("[GCP] Failed to get the CREATE operation of the DB instance: %s", dbName))
11421145
}
11431146

1144-
//Possible values:
1145-
//CREATING: Disk is provisioning.
1146-
//RESTORING: Source data is being copied into the disk.
1147-
//FAILED: Disk creation failed.
1148-
//READY: Disk is ready for use.
1149-
//DELETING: Disk is deleting.
1147+
// Possible values:
1148+
// CREATING: Disk is provisioning.
1149+
// RESTORING: Source data is being copied into the disk.
1150+
// FAILED: Disk creation failed.
1151+
// READY: Disk is ready for use.
1152+
// DELETING: Disk is deleting.
11501153
func getDiskStatus(gDisk *compute.Disk) types.State {
11511154
switch gDisk.Status {
11521155
case "CREATING", "RESTORING", "STAGING", "READY", "FAILED":
@@ -1162,13 +1165,13 @@ func getDiskStatus(gDisk *compute.Disk) types.State {
11621165
}
11631166
}
11641167

1165-
//SQL_INSTANCE_STATE_UNSPECIFIED The state of the instance is unknown.
1166-
//RUNNABLE The instance is running.
1167-
//SUSPENDED The instance is currently offline, but it may run again in the future.
1168-
//PENDING_DELETE The instance is being deleted.
1169-
//PENDING_CREATE The instance is being created.
1170-
//MAINTENANCE The instance is down for maintenance.
1171-
//FAILED The instance failed to be created.
1168+
// SQL_INSTANCE_STATE_UNSPECIFIED The state of the instance is unknown.
1169+
// RUNNABLE The instance is running.
1170+
// SUSPENDED The instance is currently offline, but it may run again in the future.
1171+
// PENDING_DELETE The instance is being deleted.
1172+
// PENDING_CREATE The instance is being created.
1173+
// MAINTENANCE The instance is down for maintenance.
1174+
// FAILED The instance failed to be created.
11721175
func getDatabaseInstanceStatus(instance *sqladmin.DatabaseInstance) types.State {
11731176
switch instance.State {
11741177
case "RUNNABLE":
@@ -1215,7 +1218,7 @@ func newCluster(cluster *dataprocpb.Cluster, region string) *types.Cluster {
12151218
Created: cluster.Status.StateStartTime.AsTime(),
12161219
CloudType: types.GCP,
12171220
Region: region,
1218-
Tags: convertTags(cluster.Labels),
1221+
Tags: cluster.Labels,
12191222
Config: cluster.GetConfig(),
12201223
State: getClusterState(cluster.Status.GetState()),
12211224
}
@@ -1235,7 +1238,7 @@ func getClusterState(s dataprocpb.ClusterStatus_State) types.State {
12351238
8: types.Starting,
12361239
}
12371240

1238-
status, ok := statuses[s]
1241+
status, ok := statuses[int32(s)]
12391242
if !ok {
12401243
return types.Unknown
12411244
}
@@ -1267,7 +1270,7 @@ func (p gcpProvider) GetClusters() ([]*types.Cluster, error) {
12671270
return nil, err
12681271
}
12691272
for _, r := range regionsList {
1270-
regionalClient, err := dataproc.NewClusterControllerClient(ctx, option.WithEndpoint(r+"-dataproc.googleapis.com:443"))
1273+
regionalClient, err := dataproc.NewClusterControllerClient(ctx, option.WithEndpoint(r+DATAPROC_ENDPOINT_SUFFIX))
12711274
if err != nil {
12721275
log.Errorf("[GET_CLUSTERS] Error creating dataproc client for region %s: %+v", r, err)
12731276
return nil, err

go.mod

+29-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
module github.com/hortonworks/cloud-haunter
22

3-
go 1.17
3+
go 1.19
44

55
require (
6+
cloud.google.com/go/dataproc v1.8.0
67
github.com/Azure/azure-sdk-for-go v60.1.0+incompatible
78
github.com/Azure/azure-storage-blob-go v0.14.0
89
github.com/Azure/go-autorest/autorest v0.11.23
910
github.com/Azure/go-autorest/autorest/azure/auth v0.5.9
1011
github.com/aws/aws-sdk-go v1.29.34
1112
github.com/sirupsen/logrus v1.0.5
12-
github.com/stretchr/testify v1.4.0
13+
github.com/stretchr/testify v1.8.1
1314
github.com/tbruyelle/hipchat-go v0.0.0-20160921153256-749fb9e14beb
14-
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd
15-
google.golang.org/api v0.0.0-20180717000714-0025a57598c0
15+
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
16+
google.golang.org/api v0.102.0
17+
google.golang.org/genproto v0.0.0-20221116193143-41c2ba794472
1618
gopkg.in/yaml.v2 v2.2.2
1719
)
1820

1921
require (
20-
cloud.google.com/go v0.25.0 // indirect
22+
cloud.google.com/go/compute v1.12.1 // indirect
23+
cloud.google.com/go/compute/metadata v0.2.1 // indirect
24+
cloud.google.com/go/longrunning v0.3.0 // indirect
25+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
26+
github.com/google/go-cmp v0.5.9 // indirect
27+
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
28+
github.com/googleapis/gax-go/v2 v2.6.0 // indirect
29+
go.opencensus.io v0.24.0 // indirect
30+
google.golang.org/grpc v1.50.1 // indirect
31+
google.golang.org/protobuf v1.28.1 // indirect
32+
gopkg.in/yaml.v3 v3.0.1 // indirect
33+
)
34+
35+
require (
36+
cloud.google.com/go v0.105.0 // indirect
2137
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
2238
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
2339
github.com/Azure/go-autorest/autorest/adal v0.9.14 // indirect
@@ -27,24 +43,23 @@ require (
2743
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
2844
github.com/Azure/go-autorest/logger v0.2.1 // indirect
2945
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
30-
github.com/davecgh/go-spew v1.1.0 // indirect
46+
github.com/davecgh/go-spew v1.1.1 // indirect
3147
github.com/dimchansky/utfbom v1.1.1 // indirect
3248
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
33-
github.com/golang/protobuf v1.2.0 // indirect
49+
github.com/golang/protobuf v1.5.2 // indirect
3450
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
35-
github.com/google/uuid v1.2.0 // indirect
51+
github.com/google/uuid v1.3.0 // indirect
3652
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
3753
github.com/mattn/go-ieproxy v0.0.1 // indirect
3854
github.com/mitchellh/go-homedir v1.1.0 // indirect
3955
github.com/pmezard/go-difflib v1.0.0 // indirect
4056
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
41-
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
42-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
43-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
44-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
45-
golang.org/x/text v0.3.3 // indirect
57+
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b // indirect
58+
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
59+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
60+
golang.org/x/text v0.4.0 // indirect
4661
golang.org/x/time v0.0.0-20220411224347-583f2d630306
47-
google.golang.org/appengine v1.1.0 // indirect
62+
google.golang.org/appengine v1.6.7 // indirect
4863
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
4964
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
5065
)

0 commit comments

Comments
 (0)